The Battle for Wesnoth  1.19.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:

Public Types

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

 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...
 
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 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 on the heap. 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)
 

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 bool impl_draw_background ()
 See draw_background. More...
 
virtual void impl_draw_children ()
 See draw_children. More...
 
virtual bool 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...
 
rect clipping_rectangle_
 The clipping rectangle if a widget is partly visible. More...
 
debug_border 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 52 of file widget.hpp.

Member Enumeration Documentation

◆ debug_border

Enumerator
none 

No border.

outline 

Single-pixel outline.

fill 

Flood-filled rectangle.

Definition at line 127 of file widget.hpp.

◆ 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. The entire widget's rectangle should be redrawn.

partly 

The widget is partly visible.

The should be drawn. The rectangle to redraw in determined by clipping_rectangle_

none 

The widget is not visible.

The widget should not be drawn.

Definition at line 100 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 62 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 55 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.

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

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.

Returns
The drawing rectangle.

Definition at line 354 of file widget.cpp.

References get_rectangle().

Referenced by draw_background(), draw_children(), draw_debug_border(), and draw_foreground().

◆ 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.

Returns
The clipping rectangle.

Definition at line 359 of file widget.cpp.

References clipping_rectangle_, sdl::empty_rect, full, get_drawing_action(), get_rectangle(), none, and partly.

Referenced by draw_background(), draw_children(), draw_debug_border(), and draw_foreground().

◆ 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::label, gui2::image, and gui2::grid.

Definition at line 331 of file widget.hpp.

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::spinner, gui2::scrollbar_container, gui2::scroll_text, gui2::scroll_label, gui2::multiline_text, gui2::label, gui2::grid, and gui2::container_base.

Definition at line 216 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::get_text_ellipse_mode(), 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 456 of file widget.hpp.

References draw::point(), and set_layout_size().

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

◆ create_walker()

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

◆ 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 188 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 178 of file widget.cpp.

◆ disable_click_dismiss()

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

◆ draw_background()

bool gui2::widget::draw_background ( )

Draws the background of a widget.

Derived should override impl_draw_background instead of changing this function.

Returns
False if drawing should be deferred.

Definition at line 372 of file widget.cpp.

References calculate_blitting_rectangle(), calculate_clipping_rectangle(), draw_debug_border(), get_drawing_action(), get_origin(), get_window(), impl_draw_background(), none, draw::reduce_clip(), draw::set_viewport(), rect::shift(), visible, and visible_.

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

◆ draw_children()

void gui2::widget::draw_children ( )

◆ draw_debug_border()

void gui2::widget::draw_debug_border ( )
private

◆ draw_foreground()

bool 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.

Returns
False if drawing should be deferred.

Definition at line 415 of file widget.cpp.

References calculate_blitting_rectangle(), calculate_clipping_rectangle(), get_drawing_action(), get_origin(), get_window(), impl_draw_foreground(), none, draw::reduce_clip(), draw::set_viewport(), rect::shift(), visible, and visible_.

Referenced by 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::window, gui2::viewport, gui2::tree_view_node, gui2::styled_widget, gui2::stacked_widget, gui2::scrollbar_container, gui2::matrix, gui2::grid, gui2::policy::placement::independent, and gui2::container_base.

Definition at line 555 of file widget.cpp.

References id_.

Referenced by gui2::matrix::find(), gui2::styled_widget::find(), gui2::tree_view_node::find(), gui2::grid_implementation::find(), and gui2::find_widget().

◆ 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.

Definition at line 193 of file widget.cpp.

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

Referenced by gui2::tree_view_node::add_child_impl(), gui2::container_base::calculate_best_size(), gui2::policy::placement::horizontal_list::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::matrix::calculate_best_size(), gui2::scrollbar_container::calculate_best_size(), gui2::tree_view_node::calculate_best_size(), gui2::tree_view_node::get_folded_size(), gui2::tree_view_node::get_unfolded_size(), gui2::window::layout(), gui2::window_implementation::layout(), gui2::window::layout_linked_widgets(), gui2::policy::placement::table::place(), gui2::policy::placement::horizontal_list::place(), gui2::policy::placement::vertical_list::place(), gui2::size_lock::place(), gui2::tree_view_node::place(), gui2::grid::child::place(), gui2::container_base::reduce_height(), gui2::grid::reduce_height(), gui2::container_base::reduce_width(), gui2::grid::reduce_width(), gui2::tree_view_node::replace_children(), gui2::grid::request_placement(), gui2::container_base::request_reduce_height(), gui2::grid::request_reduce_height(), gui2::scrollbar_container::request_reduce_height(), gui2::styled_widget::request_reduce_height(), gui2::container_base::request_reduce_width(), gui2::grid::request_reduce_width(), gui2::scrollbar_container::request_reduce_width(), gui2::styled_widget::request_reduce_width(), gui2::listbox::resize_content(), gui2::listbox::set_content_size(), and gui2::scroll_text::set_max_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 436 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

◆ 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 145 of file widget.cpp.

References parent_.

Referenced by set_horizontal_alignment(), and set_vertical_alignment().

◆ get_rectangle()

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 117 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(), draw_background(), draw_children(), draw_foreground(), gui2::policy::placement::table::find_at(), gui2::policy::placement::horizontal_list::find_at(), gui2::policy::placement::vertical_list::find_at(), gui2::policy::placement::independent::find_at(), get_best_size(), gui2::grid::impl_draw_children(), gui2::container_base::inject_linked_groups(), layout_initialize(), gui2::listbox::list_item_clicked(), gui2::unit_preview_pane::profile_button_callback(), queue_redraw(), 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::scroll_label::signal_handler_left_button_down(), gui2::scroll_text::signal_handler_left_button_down(), gui2::spinner::signal_handler_left_button_down(), gui2::tree_view::signal_handler_left_button_down(), gui2::button::signal_handler_left_button_down(), gui2::menu_button::signal_handler_left_button_down(), gui2::multiline_text::signal_handler_left_button_down(), gui2::multimenu_button::signal_handler_left_button_down(), gui2::repeating_button::signal_handler_left_button_down(), gui2::scrollbar_base::signal_handler_left_button_down(), gui2::slider_base::signal_handler_left_button_down(), gui2::text_box::signal_handler_left_button_down(), gui2::scrollbar_base::signal_handler_left_button_up(), gui2::slider::signal_handler_left_button_up(), gui2::slider_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::multiline_text::update_layout(), gui2::dialogs::file_progress::update_progress(), 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 131 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 566 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 110 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(), connect_queue(), lua_widget::impl_widget_dir(), gui2::policy::select_action::selection::init(), gui2::window::init_linked_size_group(), gui2::dialogs::addon_manager::load_addon_list(), 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(), place(), gui2::grid::place(), gui2::dialogs::campaign_selection::post_show(), gui2::dialogs::help_browser::pre_show(), gui2::dialogs::modal_dialog::register_text(), gui2::window::remove_linked_widget(), gui2::styled_widget::request_reduce_height(), gui2::styled_widget::request_reduce_width(), gui2::dialogs::attack_predictions::set_data(), set_id(), gui2::dialogs::select_orb_colors::setup_orb_group(), gui2::multiline_text::signal_handler_mouse_motion(), gui2::text_box::signal_handler_mouse_motion(), gui2::toggle_panel::signal_handler_pre_left_button_click(), gui2::event::mouse_motion::start_hover_timer(), gui2::event::mouse_motion::stop_hover_timer(), gui2::chatbox::switch_to_window(), gui2::iteration::policy::order::top_down< VW, VG, VC >::up(), gui2::dialogs::mp_options_helper::update_options_data_map(), gui2::dialogs::mp_options_helper::update_options_data_map_menu_button(), and gui2::dialogs::modeless_dialog::window_id().

◆ impl_draw_background()

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

◆ impl_draw_children()

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

◆ impl_draw_foreground()

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

See draw_foreground.

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

Definition at line 581 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 571 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 590 of file widget.cpp.

References rect::contains(), get_rectangle(), 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::tree_view, gui2::stacked_widget, gui2::size_lock, gui2::scrollbar_container, gui2::matrix, gui2::grid, and gui2::container_base.

Definition at line 297 of file widget.cpp.

Referenced by gui2::grid::layout_children(), and gui2::size_lock::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::viewport, gui2::tree_view_node, gui2::styled_widget, gui2::scrollbar_container, gui2::pane, gui2::matrix, gui2::grid, and gui2::container_base.

Definition at line 167 of file widget.cpp.

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

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

◆ layout_size()

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

◆ 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 queueing a redraw.

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 265 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

◆ queue_redraw() [1/2]

void gui2::widget::queue_redraw ( )

Indicates that this widget should be redrawn.

This function should be called by widgets whenever their visible state changes.

Definition at line 455 of file widget.cpp.

References get_rectangle(), height_, and width_.

Referenced by gui2::dialogs::tod_new_schedule::button_state_change(), gui2::text_box_base::cursor_timer_callback(), gui2::dialogs::story_viewer::display_part(), gui2::dialogs::story_viewer::draw_floating_image(), gui2::text_box_base::handle_editing(), gui2::multiline_text::handle_key_down_arrow(), gui2::multiline_text::handle_key_up_arrow(), gui2::multiline_text::handle_mouse_selection(), gui2::text_box::handle_mouse_selection(), gui2::dialogs::title_screen::init_callbacks(), gui2::dialogs::lua_interpreter::controller::input_keypress_callback(), gui2::text_box_base::insert_char(), gui2::dialogs::loading_screen::layout(), gui2::scrollbar_container::move_viewport(), gui2::text_box_base::paste_selection(), place(), gui2::dialogs::loading_screen::process(), gui2::listbox::resize_content(), gui2::tree_view::resize_content(), gui2::container_base::set_active(), gui2::slider::set_best_slider_length(), gui2::grid::set_column_grow_factor(), gui2::text_box_base::set_cursor(), gui2::styled_widget::set_label(), gui2::label::set_link_aware(), gui2::label::set_link_color(), gui2::minimap::set_map_data(), gui2::text_box_base::set_maximum_length(), gui2::progress_bar::set_percentage(), gui2::grid::set_row_grow_factor(), gui2::listbox::set_row_shown(), gui2::menu_button::set_selected(), gui2::text_box_base::set_selection_length(), gui2::text_box_base::set_selection_start(), set_size(), gui2::button::set_state(), gui2::label::set_state(), gui2::menu_button::set_state(), gui2::multimenu_button::set_state(), gui2::repeating_button::set_state(), gui2::scrollbar_base::set_state(), gui2::slider_base::set_state(), gui2::text_box_base::set_state(), gui2::toggle_button::set_state(), gui2::toggle_panel::set_state(), gui2::styled_widget::set_text_alignment(), gui2::label::set_text_alpha(), gui2::styled_widget::set_text_ellipse_mode(), gui2::styled_widget::set_use_markup(), gui2::text_box_base::set_value(), gui2::toggle_button::set_value(), gui2::toggle_panel::set_value(), gui2::multimenu_button::set_values(), gui2::menu_button::set_values(), gui2::window::set_variable(), set_visible(), gui2::dialogs::outro::update(), gui2::scrollbar_base::update_canvas(), gui2::slider_base::update_canvas(), gui2::toggle_button::update_canvas(), gui2::listbox::update_content_size(), gui2::listbox::update_layout(), gui2::dialogs::file_progress::update_progress(), gui2::dialogs::debug_clock::update_time(), and gui2::dialogs::custom_tod::update_tod_display().

◆ queue_redraw() [2/2]

void gui2::widget::queue_redraw ( const rect region)

Indicate that specific region of the screen should be redrawn.

This is in absolute drawing-space coordinates, and not constrained to the current widget.

Definition at line 464 of file widget.cpp.

References get_window(), draw_manager::invalidate_region(), and gui2::window::queue_rerender().

◆ 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 576 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::table, gui2::policy::placement::vertical_list, gui2::policy::placement::horizontal_list, gui2::generator_base, gui2::styled_widget, gui2::spacer, gui2::scrollbar_container, gui2::grid, gui2::policy::placement::independent, gui2::drawing, and gui2::container_base.

Definition at line 183 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::table, gui2::policy::placement::vertical_list, gui2::policy::placement::horizontal_list, gui2::generator_base, gui2::viewport, gui2::tree_view_node, gui2::styled_widget, gui2::spacer, gui2::scrollbar_container, gui2::pane, gui2::matrix, gui2::grid, gui2::policy::placement::independent, gui2::drawing, and gui2::container_base.

◆ set_debug_border_color()

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

Definition at line 513 of file widget.cpp.

References debug_border_color_.

◆ set_debug_border_mode()

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

Definition at line 508 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 271 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 347 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 triggering a redraw. The location is an absolute position, if a relative move is required use move.

Parameters
originThe new origin.

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

Definition at line 221 of file widget.cpp.

References x_, and y_.

Referenced by gui2::container_base::set_origin(), gui2::generator< minimum_selection, maximum_selection, my_placement, select_action >::set_origin(), gui2::grid::set_origin(), and gui2::tree_view_node::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 227 of file widget.cpp.

References height_, queue_redraw(), utf8::size(), and width_.

Referenced by gui2::tree_view_node::place(), gui2::listbox::resize_content(), and gui2::tree_view::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 284 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 470 of file widget.cpp.

References gui2::event::dispatcher::fire(), get_size(), get_window(), gui2::window::invalidate_layout(), invisible, gui2::new_widgets, draw::point(), queue_redraw(), 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::gamestate_inspector::view::clear_stuff_list(), 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(), gui2::dialogs::preferences_dialog::initialize_callbacks(), gui2::window::layout(), gui2::scrollbar_container::layout_initialize(), gui2::dialogs::mp_staging::on_controller_select(), gui2::dialogs::campaign_difficulty::pre_show(), gui2::dialogs::file_dialog::pre_show(), gui2::dialogs::game_version::pre_show(), gui2::dialogs::message::pre_show(), gui2::dialogs::mp_alerts_options::pre_show(), gui2::dialogs::lobby_player_info::pre_show(), gui2::dialogs::simple_item_selector::pre_show(), gui2::dialogs::transient_message::pre_show(), gui2::dialogs::unit_list::pre_show(), gui2::dialogs::wml_error::pre_show(), gui2::dialogs::wml_message_base::pre_show(), gui2::scrollbar_container::request_reduce_height(), gui2::scrollbar_container::request_reduce_width(), gui2::policy::select_action::show::select(), gui2::dialogs::achievements_dialog::set_achievements_row(), gui2::addon_list::set_addons(), gui2::dialogs::game_load::set_save_dir_list(), gui2::set_scrollbar_mode(), gui2::dialogs::achievements_dialog::set_sub_achievements(), gui2::dialogs::mp_match_history::tab_switch_callback(), gui2::tree_view_node::tree_view_node(), gui2::dialogs::gamestate_inspector::view::update(), gui2::dialogs::mp_match_history::update_display(), 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 54 of file widget.hpp.

◆ window

friend class window
friend

Member Data Documentation

◆ clipping_rectangle_

rect gui2::widget::clipping_rectangle_
private

The clipping rectangle if a widget is partly visible.

Definition at line 644 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 655 of file widget.hpp.

Referenced by draw_debug_border(), and set_debug_border_color().

◆ debug_border_mode_

debug_border 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.

Definition at line 652 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 474 of file widget.hpp.

Referenced by get_drawing_action(), get_height(), get_size(), place(), queue_redraw(), 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 175 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 486 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 510 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 214 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 641 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 638 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 471 of file widget.hpp.

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

◆ x_

int gui2::widget::x_
private

The x-coordinate of the widget on the screen.

Definition at line 465 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 468 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: