Bindings for widgets opacity and color property for Lua UI API
Widget opacity and color are currently not exposed for templates. These can just be another prop.
local element = ui.create {
type = ui.TYPE.Image,
props = {
opacity = 1.0,
color = util.color.rgb(1, 0, 0),
},
}
-- fade out widget by 50%
element.props.opacity = element.props.opacity * 0.5;
-- desaturate widget color by 50%
fac = 0.5
lum = util.props.color:asRgb():dot(0.299, 0.587, 0.144)
element.props.color.r = element.props.color.r + fac * (lum - element.props.color.r)
element.props.color.g = element.props.color.g + fac * (lum - element.props.color.g)
element.props.color.b = element.props.color.b + fac * (lum - element.props.color.b)
Some important use cases for this include fading in/out widgets over time and tinting UI elements. Changing color is currently used to change crosshair color for owned objects, it's also useful for needing to control a solid white texture like for various types of color picker.
Edited by Cody Glassman