HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions
v1::toggle_widget Class Referencefinal

#include <hikogui/widgets/toggle_widget.hpp>

Inheritance diagram for v1::toggle_widget:
v1::abstract_button_widget v1::widget

Public Types

using super = abstract_button_widget
 
using delegate_type = typename super::delegate_type
 
- Public Types inherited from v1::abstract_button_widget
using super = widget
 
using delegate_type = button_delegate
 

Public Member Functions

 toggle_widget (gui_window &window, widget *parent, std::unique_ptr< delegate_type > delegate) noexcept
 Construct a toggle widget.
 
template<typename Value , typename... Args>
requires (not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>)
 toggle_widget (gui_window &window, widget *parent, Value &&value, Args &&...args) noexcept
 Construct a toggle widget with a default button delegate.
 
- Public Member Functions inherited from v1::abstract_button_widget
template<typename Label >
void set_label (Label const &rhs) noexcept
 Set on/off/other labels of the button to the same value.
 
button_state state () const noexcept
 Get the current state of the button.
 
- Public Member Functions inherited from v1::widget
 widget (gui_window &window, widget *parent) noexcept
 
 widget (const widget &)=delete
 
widgetoperator= (const widget &)=delete
 
 widget (widget &&)=delete
 
widgetoperator= (widget &&)=delete
 
bool is_gui_thread () const noexcept
 
hi::theme const & theme () const noexcept
 Get the theme.
 
hi::font_book & font_book () const noexcept
 Get the font book.
 
virtual hitbox hitbox_test_from_parent (point3 position) const noexcept
 Call hitbox_test from a parent widget.
 
virtual hitbox hitbox_test_from_parent (point3 position, hitbox sibling_hitbox) const noexcept
 Call hitbox_test from a parent widget.
 
widget_constraints const & constraints () const noexcept
 
widget_layout const & layout () const noexcept
 Get the current layout for this widget.
 
virtual void request_redraw () const noexcept
 Request the widget to be redrawn on the next frame.
 
void request_relayout () const noexcept
 Request the window to be relayout on the next frame.
 
void request_reconstrain () const noexcept
 Request the window to be reconstrain on the next frame.
 
void request_resize () const noexcept
 Request the window to be resize based on the preferred size of the widgets.
 
virtual bool handle_event_recursive (gui_event const &event, std::vector< widget const * > const &reject_list=std::vector< widget const * >{}) noexcept
 Handle command recursive.
 
virtual widget const * find_next_widget (widget const *current_keyboard_widget, keyboard_focus_group group, keyboard_focus_direction direction) const noexcept
 Find the next widget that handles keyboard focus.
 
widget const * find_first_widget (keyboard_focus_group group) const noexcept
 
widget const * find_last_widget (keyboard_focus_group group) const noexcept
 
bool is_first (keyboard_focus_group group) const noexcept
 Is this widget the first widget in the parent container.
 
bool is_last (keyboard_focus_group group) const noexcept
 Is this widget the last widget in the parent container.
 
virtual void scroll_to_show (hi::aarectangle rectangle) noexcept
 Scroll to show the given rectangle on the window.
 
void scroll_to_show () noexcept
 Scroll to show the important part of the widget.
 
std::vector< widget const * > parent_chain () const noexcept
 Get a list of parents of a given widget.
 
virtual color foreground_color () const noexcept
 
virtual color focus_color () const noexcept
 
virtual color accent_color () const noexcept
 
virtual color label_color () const noexcept
 

Additional Inherited Members

- Data Fields inherited from v1::abstract_button_widget
observable< labelon_label = tr("on")
 The label to show when the button is in the 'on' state.
 
observable< labeloff_label = tr("off")
 The label to show when the button is in the 'off' state.
 
observable< labelother_label = tr("other")
 The label to show when the button is in the 'other' state.
 
observable< alignmentalignment
 The alignment of the button and on/off/other label.
 
notifier< void()> pressed
 
- Data Fields inherited from v1::widget
gui_windowwindow
 Convenient reference to the Window.
 
widget *const parent
 Pointer to the parent widget.
 
std::string id
 A name of widget, should be unique between siblings.
 
observable< widget_mode > mode = widget_mode::enabled
 The widget mode.
 
observable< bool > hover = false
 Mouse cursor is hovering over the widget.
 
observable< bool > focus = false
 The widget has keyboard focus.
 
int semantic_layer
 The draw layer of the widget.
 
int logical_layer
 The logical layer of the widget.
 

Detailed Description

A GUI widget that permits the user to make a binary choice.

A toggle is very similar to a checkbox_widget. The semantic difference between a checkbox and a toggle is:

A toggle is a button with three different states with different visual representation:

Each time a user activates the toggle-button it toggles between the 'on' and 'off' states. If the toggle is in the 'other' state an activation will switch it to the 'off' state.

A toggle cannot itself switch state to 'other', this state may be caused by external factors.

In the following example we create a toggle widget on the window which observes value. When the value is 1 the toggle is 'on', when the value is 2 the toggle is 'off'.

observable<int> value = 0;
auto &tb = window->content().make_widget<toggle_widget>("B1", value, 1, 2);
tb.on_label = tr("on");
tb.off_label = tr("off");
tb.other_label = tr("other");

Constructor & Destructor Documentation

◆ toggle_widget() [1/2]

v1::toggle_widget::toggle_widget ( gui_window & window,
widget * parent,
std::unique_ptr< delegate_type > delegate )
noexcept

Construct a toggle widget.

Parameters
windowThe window that this widget belongs to.
parentThe parent widget that owns this toggle widget.
delegateThe delegate to use to manage the state of the toggle button.

◆ toggle_widget() [2/2]

template<typename Value , typename... Args>
requires (not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>)
v1::toggle_widget::toggle_widget ( gui_window & window,
widget * parent,
Value && value,
Args &&... args )
inlinenoexcept

Construct a toggle widget with a default button delegate.

See also
default_button_delegate
Parameters
windowThe window that this widget belongs to.
parentThe parent widget that owns this toggle widget.
valueThe value or observable value which represents the state of the toggle.
argsAn optional on-value, followed by an optional off-value. These two values are used to determine which value yields an on/off state.

The documentation for this class was generated from the following file: