Light with 3 status?

Hi community!!! Hope all is ok… happy new year!

Is there an “out of the box” Light widget with 3 status? Such as disabled (gray), off (red) and active (green)? Or I need to create two RedLight/GreenLight widgets one above the other and I show/hide them?

Thanks

There is an out-of-the-box GreenRedLight

You construct it like a RedLight (for example). But when you pass it the number of the light, it will use that light for the green, and the next numbered light for the red part. In your module code you need to set both values:

// This example code was written freehand, so it might have bugs
enum LightIds {
		LIGHT_GREEN_1,
		LIGHT_RED_1,
		LIGHT_GREEN_2,
		LIGHT_RED_2,
		NUM_LIGHTS
	};

...
		// set light 1 to yellow
		lights[LIGHT_GREEN_1].setBrightness(1.0f);
		lights[LIGHT_RED_1].setBrightness(1.0f);
		// set light 2 to red
		lights[LIGHT_GREEN_2].setBrightness(0.0f);
		lights[LIGHT_RED_2].setBrightness(1.0f);

...
	addChild(createLightCentered<TinyLight<GreenRedLight>>(Vec(142.5, 68.5), module, MOD::LIGHT_GREEN_1));
	addChild(createLightCentered<TinyLight<GreenRedLight>>(Vec(142.5, 78.5), module, MOD::LIGHT_GREEN_2));

Here’s one I made earlier (last year) L69 turns off the other condition…

It works nice, thanks!

Maybe they just add additional “border” placing one on top of others, compared with a single widget rendered on screen. Right?

Well you don’t need to include a border in the other lights you could have them opaque. The border is a stroke and fill, the stroke will always be bigger than the fill. The alpha of the off can be turned all the way down so it is transparent. You then just need 1 border/off position. The draw order is bottom to top, e.g. last draw gets placed on top.

1 Like