Discussion:
How to make a 3 position toggel switch
Frank G Haymes
2013-04-21 01:47:43 UTC
Permalink
I need to make a 3 position (on-off-on) toggle switch widget.

Can someone to point me to a toggle switch widget?

If one does not exist, can someone point me to an example/tutorial on how to make a custom toggle switch widget?

Thank You,

Frank G. Haymes
chris
2013-04-21 08:52:41 UTC
Permalink
Fl_Radio_Button may be what you need (if I understand your description
correctly).

Cheers,
chris
Post by Frank G Haymes
I need to make a 3 position (on-off-on) toggle switch widget.
Can someone to point me to a toggle switch widget?
If one does not exist, can someone point me to an example/tutorial on how to make a custom toggle switch widget?
Thank You,
Frank G. Haymes
Ian MacArthur
2013-04-21 09:08:59 UTC
Permalink
Post by Frank G Haymes
I need to make a 3 position (on-off-on) toggle switch widget.
Can someone to point me to a toggle switch widget?
If one does not exist, can someone point me to an example/tutorial on how to make a custom toggle switch widget?
There's no 3-position switch that I'm aware of.

When I needed this, I just put 3 radio-buttons in a group and that was fine - and trivial to do.

If you really have a desire for the skeumorphism of it *looking* like a 3-way toggle switch, I guess you could derive your won widget from Fl_Group, hide the 3 radio buttons inside it then override the draw method to give the desired appearance.

There are some examples on Greg's cheat pages about creating your own button appearances (with GIF's and such to get the desired appearance on screen...) that would be a good starting point, I think.
Greg Ercolano
2013-04-22 00:44:32 UTC
Permalink
Post by Ian MacArthur
Post by Frank G Haymes
Can someone to point me to a toggle switch widget?
There's no 3-position switch that I'm aware of.
When I needed this, I just put 3 radio-buttons in a group and that was fine - and trivial to do.
Ya, or an Fl_Menu_Button with three items in it -- less screen real estate.
Use that if the user only needs to see which state the switch is in.

Otherwise, use the radio button approach if it's more useful that the user
see all three things, and which one of the three is "on".

A "toggle switch" or "3 position dial" would simulate the real world better,
but is perhaps not a good paradigm visually.

But if you really want to go that route, paint three images of the switch
in the various positions, and derive a class from Fl_Button that has one
of the switch images assigned as the image() for the button, and each hit
of the button switches the image() to show the other painting of the switch.
Set it up so that each hit toggles to the next of the three states. Use a char
or int to keep track of the current state, and just cycle through it each click;
0-1-2-1-0-1-2.. or 0-1-2-0-1-2.. whichever is best.

Continue reading on narkive:
Loading...