IUP/Controls/IupToggle: Difference between revisions

From Vendetta Lua
Jump to navigationJump to search
Created page with "__NOTOC__ __NOEDITSECTION__ Creates the toggle interface element. It is a two-state (on/off) button that, when selected, generates an action that activates a function in the a..."
 
No edit summary
 
Line 1: Line 1:
__NOTOC__
__NOTOC__
__NOEDITSECTION__
__NOEDITSECTION__
{{IUP Controls}}
Creates the toggle interface element. It is a two-state (on/off) button that, when selected, generates an action that activates a function in the associated application. Its visual representation can contain a text or an image.
Creates the toggle interface element. It is a two-state (on/off) button that, when selected, generates an action that activates a function in the associated application. Its visual representation can contain a text or an image.


===Creation===
===Creation===


:iup.toggle{title = '''title''': string} -> (elem: ihandle)
    iup.toggle{} -> (elem: ihandle)


:'''title''': Text to be shown on the toggle.
:This function returns the identifier of the created toggle, or nil if an error occurs.
 
:This function returns the identifier of the created toggle, or NULL if an error occurs.


===Attributes===
===Attributes===
Line 24: Line 23:


:'''[[IUP/Attributes/IMINACTIVE|IMINACTIVE]]''': Image of the inactive toggle. If it is not defined but IMAGE is defined then for inactive toggles the non transparent colors will be replaced by a darker version of the background color creating the disabled effect.
:'''[[IUP/Attributes/IMINACTIVE|IMINACTIVE]]''': Image of the inactive toggle. If it is not defined but IMAGE is defined then for inactive toggles the non transparent colors will be replaced by a darker version of the background color creating the disabled effect.
:'''IMCHECK''': Image
:'''IMCHECKINACTIVE''': Image


:'''VALUE''': Toggle's state. Values can be "ON" or "OFF". Default: "OFF".
:'''VALUE''': Toggle's state. Values can be "ON" or "OFF". Default: "OFF".


:'''[[IUP/Attributes/TITLE|TITLE]]''': Toggle's text.
:'''[[IUP/Attributes/TITLE|TITLE]]''': Toggle's text.
:'''[[IUP/Attributes/SEGMENTED|SEGMENTED]]'''


===Callbacks===
===Callbacks===
Line 33: Line 38:
:[[IUP/Callbacks/ACTION|ACTION]]: Action generated when the toggle's state (on/off) changes. The callback also receives the toggle's state.
:[[IUP/Callbacks/ACTION|ACTION]]: Action generated when the toggle's state (on/off) changes. The callback also receives the toggle's state.


::elem:action('''v''': number) -> (ret: number) [in Iu
    elem:action('''v''': number) -> (ret: number)


::'''v''': 1 if the toggle's state was shifted to on; 0 if it was shifted to off.
::'''v''': 1 if the toggle's state was shifted to on; 0 if it was shifted to off.
:[[IUP/Callbacks/GETFOCUS_CB|GETFOCUS_CB]]
:[[IUP/Callbacks/KILLFOCUS_CB|KILLFOCUS_CB]]
:[[IUP/Callbacks/ENTERWINDOW_CB|ENTERWINDOW_CB]]
:[[IUP/Callbacks/LEAVEWINDOW_CB|LEAVEWINDOW_CB]]


===Notes===
===Notes===
Line 52: Line 65:


:[[IUP/Controls/IupImage|IupImage]], [[IUP/Controls/IupButton|IupButton]], [[IUP/Controls/IupLabel|IupLabel]], [[IUP/Layout/IupRadio|IupRadio]].
:[[IUP/Controls/IupImage|IupImage]], [[IUP/Controls/IupButton|IupButton]], [[IUP/Controls/IupLabel|IupLabel]], [[IUP/Layout/IupRadio|IupRadio]].
[[Category:IUP Controls]]

Latest revision as of 22:22, 11 May 2023


Controls

Dialog
Fill
Hbox
Vbox
Zbox
Cbox
Radio
Button
Canvas
Frame
Label
List
Multiline
Text
Toggle
Progress Bar
Matrix
Tree
Navmap

Creates the toggle interface element. It is a two-state (on/off) button that, when selected, generates an action that activates a function in the associated application. Its visual representation can contain a text or an image.

Creation

   iup.toggle{} -> (elem: ihandle)
This function returns the identifier of the created toggle, or nil if an error occurs.

Attributes

BGCOLOR: Color of the toggle.
FGCOLOR: Color of the text shown on the toggle.
FONT: Font size the text shown on the toggle.
IMAGE: Toggle image. When the IMAGE attribute is defined, the TITLE is not shown. This makes the toggle look just like a button with an image, but its behavior remains the same.
IMPRESS: Image of the pressed toggle.
IMINACTIVE: Image of the inactive toggle. If it is not defined but IMAGE is defined then for inactive toggles the non transparent colors will be replaced by a darker version of the background color creating the disabled effect.
IMCHECK: Image
IMCHECKINACTIVE: Image
VALUE: Toggle's state. Values can be "ON" or "OFF". Default: "OFF".
TITLE: Toggle's text.
SEGMENTED

Callbacks

ACTION: Action generated when the toggle's state (on/off) changes. The callback also receives the toggle's state.
   elem:action(v: number) -> (ret: number)
v: 1 if the toggle's state was shifted to on; 0 if it was shifted to off.
GETFOCUS_CB
KILLFOCUS_CB
ENTERWINDOW_CB
LEAVEWINDOW_CB

Notes

Toggle with image or text can not change its behavior after mapped. This is a creation attribute. But after creation the image can be changed for another image, and the text for another text.
Text is left aligned and image is centered.
Toggles are activated using the Space key.
To build a set of mutual exclusive toggles, insert them in a IupRadio container. They must be inserted before creation, and their behavior can not be changed.
Unlike buttons, toggles always display the button border when IMAGE and IMPRESS are both defined.

See Also

IupImage, IupButton, IupLabel, IupRadio.