Sidebar

Home



Expressions V4


Tutorials

How-To

Reference

  Lexical basics
  Type system
  Variables and assignment
  Operators
  Expression rules
  Control flow
  Functions
  Built-in functions
   None and NaN
   Arithmetic
   Algebra
   Logarithmic and Exponential
   Trigonometric
   Rounding and Centering
   Strings
   Output, Formatting, Clipboard, and Errors
   Dialog Functions
   Platform and Paths
  Methods and properties
  Built-in methods
   Common Value Methods
   Number Methods
   String Basic Methods
   String Slice Methods
   String Parsing Methods
   String Formatting Methods
   String Regex Methods
   String Trim and Case Methods
  Objects
  Built-in objects
   Global objects
    settings
    controller
    session
    python
   Collections
    array
    map
    bytes
   File Format I/O
    image_data
    image_stream
   Utils
    crypto
    timer
   Comm
    serial
   Dialogs
    file_open
    file_save
    msg_ok
    msg_ok_cancel
    msg_yes_no
    msg_password
   GUI objects
    window
    panel
    group
    splitpanel
    label
    textbutton
    drawablebutton
    togglebutton
    togglegroup
    textinput
    textedit
    numinput
    slider
    combobox
    listbox
    progressbar
    led
    separator
    menu
    image
    snake
  Classes and user-defined objects
  Include system
  Error model
  Execution model and sessions
  Host integration
  Limits and performance
  Formal reference
  Glossary

Cookbook

exprv4:reference:objects:gui_togglegroup

togglegroup

`togglegroup()` creates a group of selectable toggle choices. Selection values are numeric indexes starting at `1`; `0` means no selection.

Constructor

togglegroup()

Creates a togglegroup object.

Item Description
Syntax `togglegroup()`
Arguments none
Returns togglegroup object

Example:

g = togglegroup().add('A').add('B').value(1);

Properties

Properties are read-only. Use methods to change GUI object state.

Property Type Description
`position_x` number Current x position.
`position_y` number Current y position.
`size_width` number Current width.
`size_height` number Current height.
`visible` boolean Current visible state.
`enabled` boolean Current enabled state.
`value` number Current selected item index. `0` means no selection.
`count` number Number of choices.

Common Object Methods

to_string()

Returns a display string for the object.

Item Description
Syntax `value.to_string()`
Arguments none
Returns string

Example:

text = value.to_string();

`clone()` is not supported for `togglegroup`.


Most visible GUI controls support these methods.

position(x, y)

Sets the component position in pixels.

Item Description
Syntax `component.position(x, y)`
Arguments `x`: x position; `y`: y position
Returns component object

Example:

label().position(20, 10);

size(width, height)

Sets the component size in pixels. Width and height are clamped to at least `1`.

Some container objects, such as `panel()` and `group()`, use `size(-1, -1)` as a special fit-parent mode.

Item Description
Syntax `component.size(width, height)`
Arguments `width`: width in pixels; `height`: height in pixels
Returns component object

Example:

textinput().size(220, 26);

visible(enabled)

Shows or hides the component.

Item Description
Syntax `component.visible(enabled)`
Arguments `enabled`: boolean
Returns component object

Example:

status.visible(false);

enabled(enabled)

Enables or disables user interaction with the component.

Item Description
Syntax `component.enabled(enabled)`
Arguments `enabled`: boolean
Returns component object

Example:

run_button.enabled(false);

Methods

add(text)

Adds a choice. The new choice gets the next numeric index.

Item Description
Syntax `togglegroup.add(text)`
Arguments `text`: button text
Returns togglegroup object

Example:

g = togglegroup().add('A').add('B');

add(text, width)

Adds a choice with explicit button width.

Item Description
Syntax `togglegroup.add(text, width)`
Arguments `text`: button text; `width`: button width in pixels
Returns togglegroup object

Example:

g = togglegroup().add('Millimeters', 110).add('Inches', 90);

add(text, width, newLine)

Adds a choice with explicit button width and optional row break.

Item Description
Syntax `togglegroup.add(text, width, newLine)`
Arguments `text`: button text; `width`: button width in pixels; `newLine`: boolean row break flag
Returns togglegroup object

Example:

g = togglegroup()
    .add('Fast', 80)
    .add('Slow', 80, true);

add(text, width, newLine, offset)

Adds a choice with explicit button width, row break flag, and x offset.

Item Description
Syntax `togglegroup.add(text, width, newLine, offset)`
Arguments `text`: button text; `width`: button width in pixels; `newLine`: boolean row break flag; `offset`: x offset in pixels
Returns togglegroup object

Example:

g = togglegroup()
    .add('X', 60)
    .add('Y', 60, true, 20);

value(index)

Sets selected item index. Index is clamped to `0..count`; `0` means no selection.

Item Description
Syntax `togglegroup.value(index)`
Arguments `index`: selected item index
Returns togglegroup object

Example:

g = togglegroup().add('A').add('B').value(2);

on_change(callback)

Sets a callback called when selection changes.

Item Description
Syntax `togglegroup.on_change(callback)`
Arguments `callback`: callable with one argument, the selected item index
Returns togglegroup object

Example:

function unit_changed(index)
{
    print('unit index: ', index);
}
 
g = togglegroup().on_change(unit_changed);

click(index)

Simulates selecting an item by 1-based index.

Item Description
Syntax `togglegroup.click(index)`
Arguments `index`: item index from `1` to `count`
Returns togglegroup object

Example:

g.click(1);

Example

units = togglegroup()
    .position(20, 20)
    .size(220, 80)
    .add('Millimeters', 110)
    .add('Inches', 90)
    .value(1);
 
window().title('Units').size(280, 140).add(units).show();

Previous: togglebutton

Next: textinput

exprv4/reference/objects/gui_togglegroup.txt · Last modified: by andrej

Page Tools