The Battle for Wesnoth  1.15.0-dev
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
gui2::widget Class Referenceabstract

Base class for all widgets. More...

#include <widget.hpp>

Inheritance diagram for gui2::widget:
Inheritance graph

Public Types

enum  visibility { visibility::visible, visibility::hidden, visibility::invisible }
 Visibility settings done by the user. More...
 
enum  redraw_action { redraw_action::full, redraw_action::partly, redraw_action::none }
 Visibility set by the engine. More...
 
- 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  mouse_behavior { all, hit, none }
 The behavior of the mouse events. More...
 

Public Member Functions

 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 layout_initialize (const bool full_initialization)
 How the layout engine works. More...
 
virtual void request_reduce_width (const unsigned maximum_width)=0
 Tries to reduce the width of a widget. More...
 
virtual void demand_reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a widget. More...
 
virtual void request_reduce_height (const unsigned maximum_height)
 Tries to reduce the height 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 place (const point &origin, const point &size)
 Places 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...
 
SDL_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...
 
void draw_background ()
 Draws the background of a widget. More...
 
void draw_children ()
 Draws the children of a widget. More...
 
void 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 set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const unsigned debug_border_mode)
 
void set_debug_border_color (const color_t debug_border_color)
 
virtual widgetfind_at (const point &coordinate, const bool must_be_active)
 Returns the widget at the wanted coordinates. More...
 
virtual const widgetfind_at (const point &coordinate, const bool must_be_active) const
 The constant version of find_at. More...
 
virtual widgetfind (const std::string &id, const bool must_be_active)
 Returns a widget with the wanted id. More...
 
virtual const widgetfind (const std::string &id, const bool must_be_active) const
 The constant version of find. More...
 
virtual bool has_widget (const widget &widget) const
 Does the widget contain the widget. More...
 
virtual bool disable_click_dismiss () const =0
 Does the widget disable easy close? More...
 
virtual iteration::walker_ptr create_walker ()=0
 Creates a new walker object managed by a smart pointer. 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...
 
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 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>
std::enable_if_t< is_general_event(E)> connect_signal (const signal_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event. More...
 
template<ui_event E>
std::enable_if_t< is_general_event(E)> disconnect_signal (const signal_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event. More...
 
template<ui_event E>
std::enable_if_t< is_mouse_event(E)> connect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
std::enable_if_t< is_mouse_event(E)> disconnect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
std::enable_if_t< is_keyboard_event(E)> connect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
std::enable_if_t< is_keyboard_event(E)> disconnect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
std::enable_if_t< is_touch_event(E)> connect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_touch. More...
 
template<ui_event E>
std::enable_if_t< is_touch_event(E)> disconnect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_touch. More...
 
template<ui_event E>
std::enable_if_t< is_notification_event(E)> connect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_notification. More...
 
template<ui_event E>
std::enable_if_t< is_notification_event(E)> disconnect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_notification. More...
 
template<ui_event E>
std::enable_if_t< is_message_event(E)> connect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_message. More...
 
template<ui_event E>
std::enable_if_t< is_message_event(E)> disconnect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_message. More...
 
template<ui_event E>
std::enable_if_t< is_raw_event_event(E)> connect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_raw_event. More...
 
template<ui_event E>
std::enable_if_t< is_raw_event_event(E)> disconnect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_raw_event. More...
 
template<ui_event E>
std::enable_if_t< is_text_input_event(E)> connect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_text_input. More...
 
template<ui_event E>
std::enable_if_t< is_text_input_event(E)> disconnect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_text_input. 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...
 

Protected Member Functions

void set_layout_size (const point &size)
 
const pointlayout_size () const
 
void clear_layout_size ()
 Throws away layout_size_. More...
 

Private Member Functions

virtual point calculate_best_size () const =0
 Calculates the best size. More...
 
virtual void impl_draw_background ()
 See draw_background. More...
 
virtual void impl_draw_children ()
 See draw_children. More...
 
virtual void impl_draw_foreground ()
 See draw_foreground. More...
 
void draw_debug_border ()
 
virtual bool is_at (const point &coordinate) const override
 See event::dispatcher::is_at. More...
 
bool is_at (const point &coordinate, const bool must_be_active) const
 Is the coordinate inside our area. More...
 
bool recursive_is_visible (const widget *widget, const bool must_be_active) const
 Is the widget and every single one of its parents visible? More...
 

Private Attributes

std::string id_
 The id is the unique name of the widget in a certain context. More...
 
widgetparent_
 The parent widget. More...
 
int x_
 The x-coordinate of the widget on the screen. More...
 
int y_
 The y-coordinate of the widget on the screen. More...
 
unsigned width_
 The width of the widget. More...
 
unsigned height_
 The height of the widget. More...
 
point layout_size_
 The best size for the widget. More...
 
std::string linked_group_
 The linked group the widget belongs to. More...
 
visibility visible_
 Field for the status of the visibility. More...
 
redraw_action redraw_action_
 Field for the action to do on a drawing request. More...
 
SDL_Rect clipping_rectangle_
 The clipping rectangle if a widget is partly visible. More...
 
unsigned debug_border_mode_
 Mode for drawing the debug border. More...
 
color_t debug_border_color_
 The color for the debug border. More...
 

Friends

class debug_layout_graph
 
class window
 

Detailed Description

Base class for all widgets.

From this abstract all other widgets should derive. It contains the minimal info needed for a real widget and some pure abstract functions which need to be implemented by classes deriving from this class.

Definition at line 48 of file widget.hpp.

Member Enumeration Documentation

◆ redraw_action

Visibility set by the engine.

This state only will be used if visible_ is visibility::visible depending on this state the widget might not be visible after all.

Enumerator
full 

The widget is fully visible.

The widget should be drawn if dirty_ is true. The entire widget's rectangle should be redrawn.

partly 

The widget is partly visible.

The should be drawn if dirty_ is true. The rectangle to redraw in determined by clipping_rectangle_

none 

The widget is not visible.

The widget should not be drawn if dirty_ is true.

Definition at line 96 of file widget.hpp.

◆ visibility

Visibility settings done by the user.

Enumerator
visible 

The user sets the widget visible, that means:

  • The widget is visible.
  • find_at always 'sees' the widget (the active flag is tested later).
  • The widget (if active) handles events (and sends events to its children).
  • The widget is drawn.
hidden 

The user sets the widget hidden, that means:

  • The widget is invisible but keeps its size.
  • find_at 'sees' the widget if active is false.
  • The widget doesn't handle events (and doesn't send events to its children).
invisible 

The user set the widget invisible, that means:

  • The widget is invisible and its grid cell has size 0,0.
  • find_at never 'sees' the widget.
  • The widget doesn't handle events (and doesn't send events to its children).

Definition at line 58 of file widget.hpp.

Constructor & Destructor Documentation

◆ widget() [1/3]

gui2::widget::widget ( const widget )
delete

◆ widget() [2/3]

gui2::widget::widget ( )

◆ widget() [3/3]

gui2::widget::widget ( const builder_widget builder)
explicit

Constructor.

Parameters
builderThe builder object with the settings for the object.

Definition at line 52 of file widget.cpp.

References DBG_GUI_LF.

◆ ~widget()

gui2::widget::~widget ( )
overridevirtual

Member Function Documentation

◆ calculate_best_size()

virtual point gui2::widget::calculate_best_size ( ) const
privatepure virtual

Calculates the best size.

This function calculates the best size and ignores the current values in the layout phase. Note containers can call the get_best_size() of their children since it is meant to update itself.

Returns
The best size for the widget.
Return values
0,0The best size is 0,0.

Implemented in gui2::policy::placement::independent, gui2::policy::placement::table, gui2::listbox, gui2::policy::placement::vertical_list, gui2::generator_base, gui2::tree_view_node, gui2::grid, gui2::policy::placement::horizontal_list, gui2::styled_widget, gui2::matrix, gui2::scrollbar_container, gui2::pane, gui2::container_base, gui2::viewport, gui2::image, gui2::drawing, gui2::size_lock, gui2::spacer, and gui2::slider.

Referenced by get_best_size().

◆ calculate_blitting_rectangle()

SDL_Rect gui2::widget::calculate_blitting_rectangle ( ) const

Calculates the blitting rectangle of the widget.

The blitting rectangle is the entire widget rectangle, but offsetted for drawing position.

Returns
The drawing rectangle.

Definition at line 344 of file widget.cpp.

References get_rectangle().

Referenced by calculate_clipping_rectangle(), and draw_debug_border().

◆ calculate_clipping_rectangle()

SDL_Rect gui2::widget::calculate_clipping_rectangle ( ) const

Calculates the clipping rectangle of the widget.

The clipping rectangle is used then the redraw_action_ is redraw_action::partly. Since the drawing can be offsetted it also needs offset parameters.

Returns
The clipping rectangle.

Definition at line 349 of file widget.cpp.

References calculate_blitting_rectangle(), calculate_clipping_rectangle(), clipping_rectangle_, get_drawing_action(), CVideo::get_singleton(), partly, and renderer_.

Referenced by calculate_clipping_rectangle(), and draw_debug_border().

◆ can_mouse_focus()

virtual bool gui2::widget::can_mouse_focus ( ) const
inlinevirtual

Whether the mouse move/click event go 'through' this widget.

Reimplemented in gui2::grid, gui2::label, and gui2::image.

Definition at line 320 of file widget.hpp.

References utf8::size().

Referenced by gui2::event::mouse_motion::signal_handler_sdl_mouse_motion().

◆ can_wrap()

bool gui2::widget::can_wrap ( ) const
virtual

Can the widget wrap.

When a widget can wrap it can reduce its width by increasing its height. When a layout is too wide it should first try to wrap and if that fails it should check the vertical scrollbar status. After wrapping the height might (probably will) change so the layout engine needs to recalculate the height after wrapping.

Reimplemented in gui2::grid, gui2::scrollbar_container, gui2::container_base, gui2::scroll_label, and gui2::label.

Definition at line 212 of file widget.cpp.

Referenced by gui2::container_base::can_wrap(), gui2::grid::can_wrap(), gui2::styled_widget::get_best_text_size(), gui2::styled_widget::request_reduce_width(), and gui2::text_box::update_canvas().

◆ clear_layout_size()

void gui2::widget::clear_layout_size ( )
inlineprotected

Throws away layout_size_.

Use with care: this function does not recurse to child widgets.

See Layout algorithm for more information.

Definition at line 446 of file widget.hpp.

Referenced by gui2::container_base::container_base().

◆ create_walker()

virtual iteration::walker_ptr gui2::widget::create_walker ( )
pure virtual

Creates a new walker object managed by a smart pointer.

Implemented in gui2::grid, gui2::matrix, gui2::tree_view_node, gui2::container_base, gui2::pane, gui2::styled_widget, and gui2::viewport.

◆ demand_reduce_height()

void gui2::widget::demand_reduce_height ( const unsigned  maximum_height)
virtual

Tries to reduce the height of a widget.

This function does it more aggressively and should only be used when using scrollbars failed.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_heightThe wanted maximum height.

Reimplemented in gui2::grid, and gui2::container_base.

Definition at line 184 of file widget.cpp.

◆ demand_reduce_width()

void gui2::widget::demand_reduce_width ( const unsigned  maximum_width)
virtual

Tries to reduce the width of a widget.

This function does it more aggressively and should only be used when using scrollbars and wrapping failed.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_widthThe wanted maximum width.

Reimplemented in gui2::grid, and gui2::container_base.

Definition at line 174 of file widget.cpp.

◆ disable_click_dismiss()

virtual bool gui2::widget::disable_click_dismiss ( ) const
pure virtual

◆ draw_background()

void gui2::widget::draw_background ( )

Draws the background of a widget.

Derived should override impl_draw_background instead of changing this function.

Definition at line 398 of file widget.cpp.

References draw_debug_border(), impl_draw_background(), visible, and visible_.

Referenced by gui2::window::draw(), and gui2::grid::impl_draw_children().

◆ draw_children()

void gui2::widget::draw_children ( )

Draws the children of a widget.

Containers should draw their children when they get this request.

Derived should override impl_draw_children instead of changing this function.

Definition at line 408 of file widget.cpp.

References impl_draw_children(), visible, and visible_.

Referenced by gui2::window::draw(), gui2::container_base::impl_draw_children(), gui2::matrix::impl_draw_children(), gui2::tree_view_node::impl_draw_children(), gui2::grid::impl_draw_children(), and gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::impl_draw_children().

◆ draw_debug_border()

void gui2::widget::draw_debug_border ( )
private

◆ draw_foreground()

void gui2::widget::draw_foreground ( )

Draws the foreground of the widget.

Some widgets e.g. panel and window have a back and foreground layer this function requests the drawing of the foreground.

Derived should override impl_draw_foreground instead of changing this function.

Definition at line 417 of file widget.cpp.

References impl_draw_foreground(), visible, and visible_.

Referenced by gui2::window::draw(), and gui2::grid::impl_draw_children().

◆ find() [1/2]

widget * gui2::widget::find ( const std::string &  id,
const bool  must_be_active 
)
virtual

Returns a widget with the wanted id.

Note
Since the id might not be unique inside a container there is no guarantee which widget is returned.
Parameters
idThe id of the widget to find.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
The widget with the id.
Return values
nullptrNo widget with the id found (or not active if must_be_active was set).

Reimplemented in gui2::policy::placement::independent, gui2::grid, gui2::window, gui2::styled_widget, gui2::stacked_widget, gui2::tree_view_node, gui2::matrix, gui2::scrollbar_container, gui2::container_base, and gui2::viewport.

Definition at line 528 of file widget.cpp.

References id_.

Referenced by gui2::policy::placement::independent::create_item(), gui2::grid_implementation::find(), gui2::matrix::find(), gui2::tree_view_node::find(), gui2::styled_widget::find(), find_widget(), and gui2::dialogs::lobby_player_info::pre_show().

◆ find() [2/2]

const widget * gui2::widget::find ( const std::string &  id,
const bool  must_be_active 
) const
virtual

◆ find_at() [1/2]

widget * gui2::widget::find_at ( const point coordinate,
const bool  must_be_active 
)
virtual

◆ find_at() [2/2]

const widget * gui2::widget::find_at ( const point coordinate,
const bool  must_be_active 
) const
virtual

◆ get_best_size()

point gui2::widget::get_best_size ( ) const

Gets the best size for the widget.

During the layout phase a best size will be determined, several stages might change the best size. This function will return the currently best size as determined during the layout phase.

Returns
The best size for the widget.
Return values
0,0The best size is 0,0.

Definition at line 189 of file widget.cpp.

References calculate_best_size(), gui2::window::get_linked_size(), get_window(), invisible, layout_size_, linked_group_, visible_, point::x, and point::y.

Referenced by gui2::tree_view_node::add_child_impl(), gui2::container_base::calculate_best_size(), gui2::scrollbar_container::calculate_best_size(), gui2::matrix::calculate_best_size(), gui2::policy::placement::horizontal_list::calculate_best_size(), gui2::tree_view_node::calculate_best_size(), gui2::policy::placement::vertical_list::calculate_best_size(), gui2::policy::placement::table::calculate_best_size(), gui2::policy::placement::independent::calculate_best_size(), gui2::tree_view_node::get_folded_size(), gui2::tree_view_node::get_unfolded_size(), gui2::window_implementation::layout(), gui2::window::layout(), gui2::window::layout_linked_widgets(), gui2::policy::placement::horizontal_list::place(), gui2::policy::placement::vertical_list::place(), gui2::tree_view_node::place(), gui2::grid::child::place(), gui2::policy::placement::table::place(), gui2::container_base::reduce_height(), gui2::grid::reduce_height(), gui2::container_base::reduce_width(), gui2::grid::reduce_width(), gui2::grid::request_placement(), gui2::container_base::request_reduce_height(), gui2::scrollbar_container::request_reduce_height(), gui2::styled_widget::request_reduce_height(), gui2::grid::request_reduce_height(), gui2::container_base::request_reduce_width(), gui2::scrollbar_container::request_reduce_width(), gui2::styled_widget::request_reduce_width(), gui2::grid::request_reduce_width(), gui2::listbox::resize_content(), and gui2::listbox::set_content_size().

◆ get_dirty_rectangle()

SDL_Rect gui2::widget::get_dirty_rectangle ( ) const

Gets the dirty rectangle of the widget.

Depending on the redraw_action_ it returns the rectangle this widget dirties while redrawing.

Returns
The dirty rectangle.

Definition at line 426 of file widget.cpp.

References clipping_rectangle_, full, get_rectangle(), and redraw_action_.

◆ get_drawing_action()

widget::redraw_action gui2::widget::get_drawing_action ( ) const

Definition at line 475 of file widget.cpp.

References height_, none, redraw_action_, and width_.

Referenced by calculate_clipping_rectangle(), and gui2::grid::impl_draw_children().

◆ get_height()

unsigned gui2::widget::get_height ( ) const

◆ get_origin()

point gui2::widget::get_origin ( ) const

◆ get_parent_grid()

grid * gui2::widget::get_parent_grid ( )

Get the parent grid.

Returns
Pointer to parent grid.
Return values
nullptrNo parent grid found.

Definition at line 141 of file widget.cpp.

References parent_.

Referenced by set_horizontal_alignment(), and set_vertical_alignment().

◆ get_rectangle()

SDL_Rect gui2::widget::get_rectangle ( ) const

◆ get_size()

point gui2::widget::get_size ( ) const

◆ get_visible()

widget::visibility gui2::widget::get_visible ( ) const

◆ get_width()

unsigned gui2::widget::get_width ( ) const

◆ get_window() [1/2]

window * gui2::widget::get_window ( )

Get the parent window.

Returns
Pointer to parent window.
Return values
nullptrNo parent window found.

Definition at line 113 of file widget.cpp.

References parent_.

Referenced by gui2::addon_list::add_list_to_keyboard_chain(), gui2::scrollbar_container::content_resize_height(), gui2::scrollbar_container::content_resize_request(), gui2::scrollbar_container::content_resize_width(), gui2::text_box_base::cursor_timer_callback(), gui2::dialogs::game_load::filter_text_changed(), gui2::dialogs::unit_recall::filter_text_changed(), gui2::dialogs::unit_create::filter_text_changed(), gui2::policy::placement::horizontal_list::find_at(), gui2::policy::placement::vertical_list::find_at(), gui2::policy::placement::table::find_at(), gui2::policy::placement::independent::find_at(), get_best_size(), gui2::container_base::inject_linked_groups(), layout_initialize(), gui2::listbox::list_item_clicked(), gui2::dialogs::addon_manager::on_filtertext_changed(), gui2::unit_preview_pane::profile_button_callback(), gui2::scrollbar_base::recalculate(), gui2::grid::request_placement(), gui2::listbox::set_row_shown(), gui2::toggle_button::set_value(), gui2::toggle_panel::set_value(), set_visible(), gui2::button::signal_handler_left_button_click(), gui2::menu_button::signal_handler_left_button_click(), gui2::multimenu_button::signal_handler_left_button_click(), gui2::toggle_button::signal_handler_left_button_double_click(), gui2::toggle_panel::signal_handler_left_button_double_click(), gui2::button::signal_handler_left_button_down(), gui2::scroll_label::signal_handler_left_button_down(), gui2::repeating_button::signal_handler_left_button_down(), gui2::menu_button::signal_handler_left_button_down(), gui2::tree_view::signal_handler_left_button_down(), gui2::multimenu_button::signal_handler_left_button_down(), gui2::text_box::signal_handler_left_button_down(), gui2::slider_base::signal_handler_left_button_down(), gui2::scrollbar_base::signal_handler_left_button_down(), gui2::slider::signal_handler_left_button_up(), gui2::slider_base::signal_handler_left_button_up(), gui2::scrollbar_base::signal_handler_left_button_up(), gui2::chatbox::signal_handler_receive_keyboard_focus(), gui2::pane::signal_handler_request_placement(), gui2::chatbox::switch_to_window(), gui2::window::window_instance(), and ~widget().

◆ get_window() [2/2]

const window * gui2::widget::get_window ( ) const

The constant version of get_window.

Definition at line 127 of file widget.cpp.

References parent_.

◆ get_x()

int gui2::widget::get_x ( ) const

◆ get_y()

int gui2::widget::get_y ( ) const

◆ has_widget()

bool gui2::widget::has_widget ( const widget widget) const
virtual

Does the widget contain the widget.

Widgets can be containers which have more widgets inside them, this function will traverse in those child widgets and tries to find the wanted widget.

Parameters
widgetPointer to the widget to find.
Returns
Whether or not the widget was found.

Reimplemented in gui2::grid, and gui2::container_base.

Definition at line 539 of file widget.cpp.

Referenced by gui2::container_base::has_widget(), and gui2::grid::has_widget().

◆ id()

const std::string & gui2::widget::id ( ) const

Definition at line 106 of file widget.cpp.

References id_.

Referenced by gui2::window::add_linked_widget(), gui2::chatbox::append_to_chatbox(), gui2::iteration::policy::order::bottom_up< VW, VG, VC >::bottom_up(), gui2::dialogs::campaign_selection::campaign_selected(), gui2::window::click_dismiss(), connect_queue(), gui2::scrollbar_container::find(), gui2::stacked_widget::find(), gui2::grid::find(), gui2::policy::select_action::selection::init(), gui2::window::init_linked_size_group(), gui2::iteration::policy::order::bottom_up< VW, VG, VC >::next(), gui2::iteration::policy::order::top_down< VW, VG, VC >::next(), gui2::dialogs::help_browser::on_topic_select(), gui2::grid::place(), place(), gui2::dialogs::campaign_selection::post_show(), gui2::grid::remove_child(), gui2::window::remove_linked_widget(), gui2::styled_widget::request_reduce_height(), gui2::styled_widget::request_reduce_width(), gui2::addon_list::select_addon(), set_id(), gui2::dialogs::select_orb_colors::setup_orb_group(), gui2::text_box::signal_handler_mouse_motion(), gui2::toggle_panel::signal_handler_pre_left_button_click(), gui2::dialogs::campaign_selection::sort_campaigns(), gui2::event::mouse_motion::start_hover_timer(), gui2::event::mouse_motion::stop_hover_timer(), gui2::grid::swap_child(), gui2::chatbox::switch_to_window(), gui2::iteration::policy::order::top_down< VW, VG, VC >::up(), gui2::dialogs::mp_options_helper::update_options_data_map(), and gui2::dialogs::mp_options_helper::update_options_data_map_menu_button().

◆ impl_draw_background()

virtual void gui2::widget::impl_draw_background ( )
inlineprivatevirtual

◆ impl_draw_children()

virtual void gui2::widget::impl_draw_children ( )
inlineprivatevirtual

◆ impl_draw_foreground()

virtual void gui2::widget::impl_draw_foreground ( )
inlineprivatevirtual

See draw_foreground.

Reimplemented in gui2::styled_widget, gui2::toggle_panel, and gui2::panel.

Definition at line 568 of file widget.hpp.

Referenced by draw_foreground().

◆ is_at() [1/2]

bool gui2::widget::is_at ( const point coordinate) const
overrideprivatevirtual

See event::dispatcher::is_at.

Implements gui2::event::dispatcher.

Definition at line 544 of file widget.cpp.

Referenced by find_at().

◆ is_at() [2/2]

bool gui2::widget::is_at ( const point coordinate,
const bool  must_be_active 
) const
private

Is the coordinate inside our area.

Helper for find_at so also looks at our visibility.

Parameters
coordinateThe coordinate which should be inside the widget.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
Status.

Definition at line 563 of file widget.cpp.

References get_rectangle(), sdl::point_in_rect(), and recursive_is_visible().

◆ layout_children()

void gui2::widget::layout_children ( )
virtual

Allows a widget to update its children.

Before the window is populating the dirty list the widgets can update their content, which allows delayed initialization. This delayed initialization is only allowed if the widget resizes itself, not when being placed.

Reimplemented in gui2::scrollbar_container, gui2::grid, gui2::listbox, gui2::matrix, gui2::container_base, gui2::tree_view, gui2::size_lock, and gui2::stacked_widget.

Definition at line 287 of file widget.cpp.

Referenced by gui2::grid::layout_children().

◆ layout_initialize()

void gui2::widget::layout_initialize ( const bool  full_initialization)
virtual

How the layout engine works.

Every widget has a member layout_size_ which holds the best size in the current layout phase. When the windows starts the layout phase it calls layout_initialize which resets this value.

Every widget has two function to get the best size. get_best_size tests whether layout_size_ is set and if so returns that value otherwise it calls calculate_best_size so the size can be updated.

During the layout phase some functions can modify layout_size_ so the next call to get_best_size returns the currently best size. This means that after the layout phase get_best_size still returns this value. Initialises the layout phase.

Clears the initial best size for the widgets.

See Layout algorithm for more information.

Parameters
full_initializationFor widgets with scrollbars it hides them unless the mode is scrollbar_mode::ALWAYS_VISIBLE. For other widgets this flag is a NOP.

Reimplemented in gui2::generator_base, gui2::tree_view_node, gui2::grid, gui2::styled_widget, gui2::matrix, gui2::scrollbar_container, gui2::pane, gui2::container_base, and gui2::viewport.

Definition at line 163 of file widget.cpp.

References gui2::window::add_linked_widget(), get_window(), invisible, layout_size_, linked_group_, and visible_.

Referenced by gui2::viewport::layout_initialize(), gui2::pane::layout_initialize(), gui2::styled_widget::layout_initialize(), gui2::grid::layout_initialize(), and gui2::tree_view_node::layout_initialize().

◆ layout_size()

const point & gui2::widget::layout_size ( ) const
protected

Definition at line 332 of file widget.cpp.

References layout_size_.

Referenced by gui2::tree_view_node::add_child_impl().

◆ move()

void gui2::widget::move ( const int  x_offset,
const int  y_offset 
)
virtual

Moves a widget.

This function can be used to move the widget without dirtying it.

Todo:
Implement the function to all derived classes.
Parameters
x_offsetThe amount of pixels to move the widget in the x-direction.
y_offsetThe amount of pixels to move the widget in the y-direction.

Definition at line 255 of file widget.cpp.

References x_, and y_.

◆ operator=()

widget& gui2::widget::operator= ( const widget )
delete

◆ parent()

widget * gui2::widget::parent ( )

◆ place()

void gui2::widget::place ( const point origin,
const point size 
)
virtual

◆ recursive_is_visible()

bool gui2::widget::recursive_is_visible ( const widget widget,
const bool  must_be_active 
) const
private

Is the widget and every single one of its parents visible?

Parameters
widgetWidget where to start the check.
must_be_activeThe widget should be active, not all widgets have an active flag, those who don't ignore flag.
Returns
Status.

Definition at line 549 of file widget.cpp.

References hidden, invisible, parent_, and visible_.

Referenced by is_at().

◆ request_reduce_height()

void gui2::widget::request_reduce_height ( const unsigned  maximum_height)
virtual

Tries to reduce the height of a widget.

This function tries to do it 'friendly' and only use scrollbars.

Todo:
Make pure virtual.

See Layout algorithm for more information.

Parameters
maximum_heightThe wanted maximum height.

Reimplemented in gui2::policy::placement::independent, gui2::policy::placement::table, gui2::policy::placement::vertical_list, gui2::generator_base, gui2::grid, gui2::policy::placement::horizontal_list, gui2::styled_widget, gui2::scrollbar_container, gui2::container_base, gui2::drawing, and gui2::spacer.

Definition at line 179 of file widget.cpp.

◆ request_reduce_width()

virtual void gui2::widget::request_reduce_width ( const unsigned  maximum_width)
pure virtual

Tries to reduce the width of a widget.

This function tries to do it 'friendly' and only use scrollbars or tries to wrap the widget.

See Layout algorithm for more information.

Parameters
maximum_widthThe wanted maximum width.

Implemented in gui2::policy::placement::independent, gui2::policy::placement::table, gui2::policy::placement::vertical_list, gui2::generator_base, gui2::tree_view_node, gui2::grid, gui2::policy::placement::horizontal_list, gui2::styled_widget, gui2::matrix, gui2::scrollbar_container, gui2::pane, gui2::container_base, gui2::drawing, gui2::viewport, and gui2::spacer.

◆ set_debug_border_color()

void gui2::widget::set_debug_border_color ( const color_t  debug_border_color)

Definition at line 486 of file widget.cpp.

References debug_border_color_.

◆ set_debug_border_mode()

void gui2::widget::set_debug_border_mode ( const unsigned  debug_border_mode)

Definition at line 481 of file widget.cpp.

References debug_border_mode_.

◆ set_horizontal_alignment()

void gui2::widget::set_horizontal_alignment ( const std::string &  alignment)
virtual

Sets the horizontal alignment of the widget within its parent grid.

Parameters
alignmentThe new alignment.

Definition at line 261 of file widget.cpp.

References gui2::implementation::get_h_align(), get_parent_grid(), gui2::grid::HORIZONTAL_MASK, and gui2::grid::set_child_alignment().

◆ set_id()

void gui2::widget::set_id ( const std::string &  id)

◆ set_layout_size()

void gui2::widget::set_layout_size ( const point size)
protected

◆ set_linked_group()

void gui2::widget::set_linked_group ( const std::string &  linked_group)

Definition at line 337 of file widget.cpp.

References linked_group_.

Referenced by gui2::builder_grid::build(), and gui2::styled_widget::set_members().

◆ set_origin()

void gui2::widget::set_origin ( const point origin)
virtual

Sets the origin of the widget.

This function can be used to move the widget without dirtying it. The location is an absolute position, if a relative more is required use move.

Parameters
originThe new origin.

Reimplemented in gui2::policy::placement::independent, gui2::policy::placement::table, gui2::policy::placement::vertical_list, gui2::tree_view_node, gui2::generator_base, gui2::grid, gui2::policy::placement::horizontal_list, gui2::scrollbar_container, and gui2::container_base.

Definition at line 217 of file widget.cpp.

References point::x, x_, point::y, and y_.

Referenced by gui2::container_base::set_origin(), gui2::grid::set_origin(), gui2::tree_view_node::set_origin(), and gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_origin().

◆ set_parent()

void gui2::widget::set_parent ( widget parent)

◆ set_size()

void gui2::widget::set_size ( const point size)
virtual

Sets the size of the widget.

This version is meant to resize a widget, since the origin isn't modified. This can be used if a widget needs to change its size and the layout will be fixed later.

Parameters
sizeThe size of the widget.

Definition at line 223 of file widget.cpp.

References height_, width_, point::x, and point::y.

Referenced by gui2::tree_view_node::place(), gui2::tree_view::resize_content(), and gui2::listbox::resize_content().

◆ set_vertical_alignment()

void gui2::widget::set_vertical_alignment ( const std::string &  alignment)
virtual

Sets the horizontal alignment of the widget within its parent grid.

Parameters
alignmentThe new alignment.

Definition at line 274 of file widget.cpp.

References get_parent_grid(), gui2::implementation::get_v_align(), gui2::grid::set_child_alignment(), and gui2::grid::VERTICAL_MASK.

Referenced by gui2::dialogs::story_viewer::display_part().

◆ set_visible()

void gui2::widget::set_visible ( const visibility  visible)

Definition at line 445 of file widget.cpp.

References gui2::event::dispatcher::fire(), get_size(), get_window(), gui2::window::invalidate_layout(), invisible, gui2::new_widgets, gui2::event::REQUEST_PLACEMENT, visible, and visible_.

Referenced by gui2::chatbox::active_window_changed(), gui2::dialogs::mp_staging::add_side_node(), gui2::dialogs::mp_lobby::adjust_game_row_contents(), gui2::adjust_scrollbar_mode(), gui2::dialogs::story_viewer::display_part(), gui2::chatbox::find_or_create_window(), gui2::chatbox::increment_waiting_messages(), gui2::chatbox::increment_waiting_whispers(), gui2::dialogs::message_implementation::init_button(), lua_gui2::intf_set_dialog_visible(), gui2::window::layout(), gui2::scrollbar_container::layout_initialize(), gui2::dialogs::mp_staging::on_controller_select(), gui2::dialogs::preferences_dialog::post_build(), gui2::dialogs::mp_alerts_options::pre_show(), gui2::dialogs::transient_message::pre_show(), gui2::dialogs::lobby_player_info::pre_show(), gui2::dialogs::help_browser::pre_show(), gui2::dialogs::campaign_difficulty::pre_show(), gui2::dialogs::wml_error::pre_show(), gui2::dialogs::game_version::pre_show(), gui2::dialogs::addon_manager::pre_show(), gui2::dialogs::message::pre_show(), gui2::dialogs::wml_message_base::pre_show(), gui2::dialogs::file_dialog::pre_show(), gui2::scrollbar_container::request_reduce_height(), gui2::scrollbar_container::request_reduce_width(), gui2::policy::select_action::show::select(), gui2::addon_list::set_addons(), gui2::set_scrollbar_mode(), gui2::tree_view_node::tree_view_node(), and gui2::dialogs::mp_options_helper::update_status_label().

◆ set_visible_rectangle()

void gui2::widget::set_visible_rectangle ( const SDL_Rect &  rectangle)
virtual

Friends And Related Function Documentation

◆ debug_layout_graph

friend class debug_layout_graph
friend

Definition at line 50 of file widget.hpp.

◆ window

friend class window
friend

Definition at line 51 of file widget.hpp.

Member Data Documentation

◆ clipping_rectangle_

SDL_Rect gui2::widget::clipping_rectangle_
private

The clipping rectangle if a widget is partly visible.

Definition at line 614 of file widget.hpp.

Referenced by calculate_clipping_rectangle(), get_dirty_rectangle(), and set_visible_rectangle().

◆ debug_border_color_

color_t gui2::widget::debug_border_color_
private

The color for the debug border.

Definition at line 630 of file widget.hpp.

Referenced by draw_debug_border(), and set_debug_border_color().

◆ debug_border_mode_

unsigned gui2::widget::debug_border_mode_
private

Mode for drawing the debug border.

The debug border is a helper border to determine where a widget is placed. It is only intended for debugging purposes.

Possible values:

  • 0 no border
  • 1 single pixel border
  • 2 flood-filled rectangle

Definition at line 627 of file widget.hpp.

Referenced by draw_debug_border(), and set_debug_border_mode().

◆ height_

unsigned gui2::widget::height_
private

The height of the widget.

Definition at line 464 of file widget.hpp.

Referenced by get_drawing_action(), get_height(), get_size(), place(), and set_size().

◆ id_

std::string gui2::widget::id_
private

The id is the unique name of the widget in a certain context.

This is needed for certain widgets so the engine knows which widget is which. E.g. it knows which button is pressed and thus which engine action is connected to the button. This doesn't mean that the id is unique in a window, e.g. a listbox can have the same id for every row.

Definition at line 162 of file widget.hpp.

Referenced by find(), id(), set_id(), and ~widget().

◆ layout_size_

point gui2::widget::layout_size_
private

The best size for the widget.

When 0,0 the real best size is returned, but in the layout phase a wrapping or a scrollbar might change the best size for that widget. This variable holds that best value.

If the widget size hasn't been changed from the default that calculate_best_size() returns, layout_size_ is (0,0).

Definition at line 476 of file widget.hpp.

Referenced by get_best_size(), layout_initialize(), layout_size(), and set_layout_size().

◆ linked_group_

std::string gui2::widget::linked_group_
private

The linked group the widget belongs to.

Todo:
For now the linked group is initialized when the layout of the widget is initialized. The best time to set it would be upon adding the widget in the window. Need to look whether it is possible in a clean way. Maybe a signal just prior to showing a window where the widget can do some of it's on things, would also be nice for widgets that need a finalizer function.

Definition at line 500 of file widget.hpp.

Referenced by get_best_size(), layout_initialize(), set_linked_group(), and ~widget().

◆ parent_

widget* gui2::widget::parent_
private

The parent widget.

If the widget has a parent it contains a pointer to the parent, else it is set to nullptr.

Definition at line 201 of file widget.hpp.

Referenced by get_parent_grid(), get_window(), parent(), recursive_is_visible(), and set_parent().

◆ redraw_action_

redraw_action gui2::widget::redraw_action_
private

Field for the action to do on a drawing request.

Definition at line 611 of file widget.hpp.

Referenced by draw_debug_border(), get_dirty_rectangle(), get_drawing_action(), and set_visible_rectangle().

◆ visible_

visibility gui2::widget::visible_
private

Field for the status of the visibility.

Definition at line 608 of file widget.hpp.

Referenced by draw_background(), draw_children(), draw_foreground(), get_best_size(), get_visible(), layout_initialize(), recursive_is_visible(), and set_visible().

◆ width_

unsigned gui2::widget::width_
private

The width of the widget.

Definition at line 461 of file widget.hpp.

Referenced by get_drawing_action(), get_size(), get_width(), place(), and set_size().

◆ x_

int gui2::widget::x_
private

The x-coordinate of the widget on the screen.

Definition at line 455 of file widget.hpp.

Referenced by get_origin(), get_x(), move(), place(), and set_origin().

◆ y_

int gui2::widget::y_
private

The y-coordinate of the widget on the screen.

Definition at line 458 of file widget.hpp.

Referenced by get_origin(), get_y(), move(), place(), and set_origin().


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