The Battle for Wesnoth  1.19.0-dev
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
gui2::toggle_button Class Reference

Class for a toggle button. More...

#include <toggle_button.hpp>

Inheritance diagram for gui2::toggle_button:

Public Types

enum  state_t { ENABLED , DISABLED , FOCUSED , COUNT }
 Possible states of the widget. More...
 
- Public Types inherited from gui2::widget
enum class  visibility { visible , hidden , invisible }
 Visibility settings done by the user. More...
 
enum class  redraw_action { full , partly , none }
 Visibility set by the engine. More...
 
enum class  debug_border { none , outline , fill }
 
- Public Types inherited from gui2::event::dispatcher
enum  event_queue_type { pre = 1 , child = 2 , post = 4 }
 
enum  queue_position {
  front_pre_child , back_pre_child , front_child , back_child ,
  front_post_child , back_post_child
}
 The position where to add a new callback in the signal handler. More...
 
enum class  mouse_behavior { all , hit , none }
 The behavior of the mouse events. More...
 

Public Member Functions

 toggle_button (const implementation::builder_toggle_button &builder)
 
void set_members (const widget_item &data) override
 See styled_widget::set_members. More...
 
virtual void set_active (const bool active) override
 See styled_widget::set_active. More...
 
virtual bool get_active () const override
 See styled_widget::get_active. More...
 
virtual unsigned get_state () const override
 See styled_widget::get_state. More...
 
virtual void update_canvas () override
 Inherited from styled_widget. More...
 
virtual unsigned get_value () const override
 Inherited from selectable_item. More...
 
virtual unsigned num_states () const override
 Inherited from selectable_item. More...
 
virtual void set_value (unsigned selected, bool fire_event=false) override
 Inherited from selectable_item. More...
 
void set_retval (const int retval)
 
void set_icon_name (const std::string &icon_name)
 
const std::string & icon_name () const
 
- Public Member Functions inherited from gui2::styled_widget
 styled_widget (const implementation::builder_styled_widget &builder, const std::string &control_type)
 Constructor. More...
 
bool disable_click_dismiss () const override
 See widget::disable_click_dismiss. More...
 
virtual iteration::walker_ptr create_walker () override
 See widget::create_walker. More...
 
point get_config_minimum_size () const
 Gets the minimum size as defined in the config. More...
 
point get_config_default_size () const
 Gets the default size as defined in the config. More...
 
point get_config_maximum_size () const
 Gets the best size as defined in the config. More...
 
virtual unsigned get_characters_per_line () const
 Returns the number of characters per line. More...
 
virtual bool get_link_aware () const
 Returns whether the label should be link_aware, in in rendering and in searching for links with get_link. More...
 
virtual color_t get_link_color () const
 Returns the color string to be used with links. More...
 
virtual void layout_initialize (const bool full_initialization) override
 See widget::layout_initialize. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See widget::request_reduce_width. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See widget::request_reduce_height. More...
 
virtual void place (const point &origin, const point &size) override
 See widget::place. More...
 
virtual widgetfind_at (const point &coordinate, const bool must_be_active) override
 See widget::find_at. More...
 
virtual const widgetfind_at (const point &coordinate, const bool must_be_active) const override
 See widget::find_at. More...
 
widgetfind (const std::string &id, const bool must_be_active) override
 See widget::find. More...
 
const widgetfind (const std::string &id, const bool must_be_active) const override
 See widget::find. More...
 
bool get_use_tooltip_on_label_overflow () const
 
void set_use_tooltip_on_label_overflow (const bool use_tooltip=true)
 
const t_stringget_label () const
 
virtual void set_label (const t_string &text)
 
virtual void set_use_markup (bool use_markup)
 
bool get_use_markup () const
 
const t_stringtooltip () const
 
void set_tooltip (const t_string &tooltip)
 
const t_stringhelp_message () const
 
void set_help_message (const t_string &help_message)
 
std::vector< canvas > & get_canvases ()
 
canvasget_canvas (const unsigned index)
 
virtual void set_text_alignment (const PangoAlignment text_alignment)
 
PangoAlignment get_text_alignment () const
 
void set_text_ellipse_mode (const PangoEllipsizeMode ellipse_mode)
 
PangoEllipsizeMode get_text_ellipse_mode () const
 Get the text's ellipsize mode. More...
 
- Public Member Functions inherited from gui2::widget
 widget (const widget &)=delete
 
widgetoperator= (const widget &)=delete
 
 widget ()
 
 widget (const builder_widget &builder)
 Constructor. More...
 
virtual ~widget () override
 
void set_id (const std::string &id)
 
const std::string & id () const
 
windowget_window ()
 Get the parent window. More...
 
const windowget_window () const
 The constant version of get_window. More...
 
gridget_parent_grid ()
 Get the parent grid. More...
 
void set_parent (widget *parent)
 
widgetparent ()
 
virtual void demand_reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a widget. More...
 
virtual void demand_reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a widget. More...
 
point get_best_size () const
 Gets the best size for the widget. More...
 
virtual bool can_mouse_focus () const
 Whether the mouse move/click event go 'through' this widget. More...
 
virtual bool can_wrap () const
 Can the widget wrap. More...
 
virtual void set_origin (const point &origin)
 Sets the origin of the widget. More...
 
virtual void set_size (const point &size)
 Sets the size of the widget. More...
 
virtual void move (const int x_offset, const int y_offset)
 Moves a widget. More...
 
virtual void set_horizontal_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void set_vertical_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void layout_children ()
 Allows a widget to update its children. More...
 
point get_origin () const
 Returns the screen origin of the widget. More...
 
point get_size () const
 Returns the size of the widget. More...
 
rect get_rectangle () const
 Gets the bounding rectangle of the widget on the screen. More...
 
int get_x () const
 
int get_y () const
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_linked_group (const std::string &linked_group)
 
SDL_Rect calculate_blitting_rectangle () const
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle () const
 Calculates the clipping rectangle of the widget. More...
 
bool draw_background ()
 Draws the background of a widget. More...
 
void draw_children ()
 Draws the children of a widget. More...
 
bool draw_foreground ()
 Draws the foreground of the widget. More...
 
SDL_Rect get_dirty_rectangle () const
 Gets the dirty rectangle of the widget. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle)
 Sets the visible rectangle for a widget. More...
 
void queue_redraw ()
 Indicates that this widget should be redrawn. More...
 
void queue_redraw (const rect &region)
 Indicate that specific region of the screen should be redrawn. More...
 
void set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const debug_border debug_border_mode)
 
void set_debug_border_color (const color_t debug_border_color)
 
virtual bool has_widget (const widget &widget) const
 Does the widget contain the widget. More...
 
- Public Member Functions inherited from gui2::event_executor
 event_executor ()
 
virtual ~event_executor ()
 
void set_wants_mouse_hover (const bool hover=true)
 
bool wants_mouse_hover () const
 
void set_wants_mouse_left_double_click (const bool click=true)
 
bool wants_mouse_left_double_click () const
 
void set_wants_mouse_middle_double_click (const bool click=true)
 
bool wants_mouse_middle_double_click () const
 
event_executorset_wants_mouse_right_double_click (const bool click=true)
 
bool wants_mouse_right_double_click () const
 
- Public Member Functions inherited from gui2::event::dispatcher
 dispatcher ()
 
virtual ~dispatcher ()
 
void connect ()
 Connects the dispatcher to the event handler. More...
 
void disconnect ()
 Disconnects the dispatcher from the event handler. More...
 
bool is_connected () const
 Return whether the dispatcher is currently connected. More...
 
bool has_event (const ui_event event, const event_queue_type event_type)
 
bool fire (const ui_event event, widget &target)
 Fires an event which has no extra parameters. More...
 
bool fire (const ui_event event, widget &target, const point &coordinate)
 Fires an event which takes a coordinate parameter. More...
 
bool fire (const ui_event event, widget &target, const SDL_Keycode key, const SDL_Keymod modifier, const std::string &unicode)
 Fires an event which takes keyboard parameters. More...
 
bool fire (const ui_event event, widget &target, const point &pos, const point &distance)
 Fires an event which takes touch-motion parameters. More...
 
bool fire (const ui_event event, widget &target, const point &center, float dTheta, float dDist, uint8_t numFingers)
 Fires an event which takes touch-gesture parameters. More...
 
bool fire (const ui_event event, widget &target, void *)
 Fires an event which takes notification parameters. More...
 
bool fire (const ui_event event, widget &target, const message &msg)
 Fires an event which takes message parameters. More...
 
bool fire (const ui_event event, widget &target, const SDL_Event &sdlevent)
 Fires an event that's a raw SDL event. More...
 
bool fire (const ui_event event, widget &target, const std::string &text, int32_t start, int32_t len)
 Fires an event which takes text input parameters. More...
 
template<ui_event E, typename F >
void connect_signal (const F &func, const queue_position position=back_child)
 Adds a callback to the appropriate queue based on event type. More...
 
template<ui_event E, typename F >
void disconnect_signal (const F &func, const queue_position position=back_child)
 Removes a callback from the appropriate queue based on event type. More...
 
void capture_mouse ()
 Captures the mouse. More...
 
void release_mouse ()
 Releases the mouse capture. More...
 
void set_mouse_behavior (const mouse_behavior mouse_behavior)
 
mouse_behavior get_mouse_behavior () const
 
void set_want_keyboard_input (const bool want_keyboard_input)
 
bool get_want_keyboard_input () const
 
void register_hotkey (const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
 Registers a hotkey. More...
 
bool execute_hotkey (const hotkey::HOTKEY_COMMAND id)
 Executes a hotkey. More...
 
- Public Member Functions inherited from enable_lua_ptr< widget >
 enable_lua_ptr (widget *tp)
 
- Public Member Functions inherited from gui2::selectable_item
virtual ~selectable_item ()
 
bool get_value_bool () const
 
void set_value_bool (bool value, bool fire_event=false)
 

Static Public Member Functions

static const std::string & type ()
 Static type getter that does not rely on the widget being constructed. More...
 

Private Member Functions

void set_state (const state_t state)
 
virtual const std::string & get_control_type () const override
 Inherited from styled_widget, implemented by REGISTER_WIDGET. More...
 
void signal_handler_mouse_enter (const event::ui_event event, bool &handled)
 
void signal_handler_mouse_leave (const event::ui_event event, bool &handled)
 
void signal_handler_left_button_click (const event::ui_event event, bool &handled)
 
void signal_handler_left_button_double_click (const event::ui_event event, bool &handled)
 

Private Attributes

state_t state_
 Current state of the widget. More...
 
unsigned state_num_
 Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons. More...
 
int retval_
 The return value of the button. More...
 
std::string icon_name_
 The toggle button can contain an icon next to the text. More...
 

Additional Inherited Members

- Protected Member Functions inherited from gui2::styled_widget
virtual point calculate_best_size () const override
 See widget::calculate_best_size. More...
 
resolution_definition_ptr get_config ()
 
resolution_definition_const_ptr get_config () const
 
template<typename T >
std::shared_ptr< const typename T::resolution > cast_config_to () const
 Casts the current resolution definition config to the respective type of a derived widget. More...
 
void set_config (resolution_definition_ptr config)
 
unsigned int get_text_font_size () const
 Resolves and returns the text_font_size. More...
 
int get_text_maximum_width () const
 Returns the maximum width available for the text. More...
 
int get_text_maximum_height () const
 Returns the maximum height available for the text. More...
 
virtual bool impl_draw_background () override
 See widget::impl_draw_background. More...
 
virtual bool impl_draw_foreground () override
 See widget::impl_draw_foreground. More...
 
std::string get_label_token (const point &position, const char *delimiters=" \n\r\t") const
 Exposes font::pango_text::get_token, for the text label of this styled_widget. More...
 
std::string get_label_link (const point &position) const
 
- Protected Member Functions inherited from gui2::widget
void set_layout_size (const point &size)
 
const pointlayout_size () const
 
void clear_layout_size ()
 Throws away layout_size_. More...
 

Detailed Description

Class for a toggle button.

A toggle button is a button with two states 'up' and 'down' or 'selected' and 'deselected'. When the mouse is pressed on it the state changes.

The following states exist:

Variables:

Key Type Default Description
icon string "" The name of the icon file to show.
return_value_id string "" The return value id.
return_value int 0 The return value.

Definition at line 53 of file toggle_button.hpp.

Member Enumeration Documentation

◆ state_t

Possible states of the widget.

Note the order of the states must be the same as defined in settings.hpp. Also note the internals do assume the order for 'up' and 'down' to be the same and also that 'up' is before 'down'. 'up' has no suffix, 'down' has the SELECTED suffix.

Enumerator
ENABLED 
DISABLED 
FOCUSED 
COUNT 

Definition at line 110 of file toggle_button.hpp.

Constructor & Destructor Documentation

◆ toggle_button()

gui2::toggle_button::toggle_button ( const implementation::builder_toggle_button builder)
explicit

Member Function Documentation

◆ get_active()

bool gui2::toggle_button::get_active ( ) const
overridevirtual

See styled_widget::get_active.

Implements gui2::styled_widget.

Definition at line 89 of file toggle_button.cpp.

References DISABLED, and state_.

◆ get_control_type()

virtual const std::string& gui2::toggle_button::get_control_type ( ) const
overrideprivatevirtual

Inherited from styled_widget, implemented by REGISTER_WIDGET.

Implements gui2::styled_widget.

◆ get_state()

unsigned gui2::toggle_button::get_state ( ) const
overridevirtual

See styled_widget::get_state.

Implements gui2::styled_widget.

Definition at line 94 of file toggle_button.cpp.

References COUNT, state_, and state_num_.

◆ get_value()

virtual unsigned gui2::toggle_button::get_value ( ) const
inlineoverridevirtual

Inherited from selectable_item.

Implements gui2::selectable_item.

Definition at line 76 of file toggle_button.hpp.

References state_num_.

Referenced by set_value(), and signal_handler_left_button_click().

◆ icon_name()

const std::string& gui2::toggle_button::icon_name ( ) const
inline

Definition at line 97 of file toggle_button.hpp.

References icon_name_.

Referenced by set_icon_name().

◆ num_states()

unsigned gui2::toggle_button::num_states ( ) const
overridevirtual

Inherited from selectable_item.

Implements gui2::selectable_item.

Definition at line 61 of file toggle_button.cpp.

References COUNT, and gui2::styled_widget::get_config().

Referenced by set_value().

◆ set_active()

void gui2::toggle_button::set_active ( const bool  active)
overridevirtual

◆ set_icon_name()

void gui2::toggle_button::set_icon_name ( const std::string &  icon_name)
inline

◆ set_members()

void gui2::toggle_button::set_members ( const widget_item data)
overridevirtual

◆ set_retval()

void gui2::toggle_button::set_retval ( const int  retval)

◆ set_state()

void gui2::toggle_button::set_state ( const state_t  state)
private

◆ set_value()

void gui2::toggle_button::set_value ( unsigned  selected,
bool  fire_event = false 
)
overridevirtual

◆ signal_handler_left_button_click()

void gui2::toggle_button::signal_handler_left_button_click ( const event::ui_event  event,
bool &  handled 
)
private

◆ signal_handler_left_button_double_click()

void gui2::toggle_button::signal_handler_left_button_double_click ( const event::ui_event  event,
bool &  handled 
)
private

◆ signal_handler_mouse_enter()

void gui2::toggle_button::signal_handler_mouse_enter ( const event::ui_event  event,
bool &  handled 
)
private

Definition at line 151 of file toggle_button.cpp.

References DBG_GUI_E, FOCUSED, LOG_HEADER, and set_state().

Referenced by toggle_button().

◆ signal_handler_mouse_leave()

void gui2::toggle_button::signal_handler_mouse_leave ( const event::ui_event  event,
bool &  handled 
)
private

Definition at line 159 of file toggle_button.cpp.

References DBG_GUI_E, ENABLED, LOG_HEADER, and set_state().

Referenced by toggle_button().

◆ type()

static const std::string& gui2::toggle_button::type ( )
static

Static type getter that does not rely on the widget being constructed.

◆ update_canvas()

void gui2::toggle_button::update_canvas ( )
overridevirtual

Member Data Documentation

◆ icon_name_

std::string gui2::toggle_button::icon_name_
private

The toggle button can contain an icon next to the text.

Maybe this will move the the styled_widget class if deemed needed.

Definition at line 144 of file toggle_button.hpp.

Referenced by icon_name(), set_icon_name(), and update_canvas().

◆ retval_

int gui2::toggle_button::retval_
private

The return value of the button.

If this value is not 0 and the button is double clicked it sets the retval of the window and the window closes itself.

Definition at line 138 of file toggle_button.hpp.

Referenced by set_retval(), and signal_handler_left_button_double_click().

◆ state_

state_t gui2::toggle_button::state_
private

Current state of the widget.

The state of the widget determines what to render and how the widget reacts to certain 'events'.

Definition at line 127 of file toggle_button.hpp.

Referenced by get_active(), get_state(), and set_state().

◆ state_num_

unsigned gui2::toggle_button::state_num_
private

Usually 1 for selected and 0 for not selected, can also have higher values in tristate buttons.

Definition at line 131 of file toggle_button.hpp.

Referenced by get_state(), get_value(), and set_value().


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