The Battle for Wesnoth  1.19.5+dev
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
gui2::styled_widget Class Referenceabstract

#include <styled_widget.hpp>

Inheritance diagram for gui2::styled_widget:

Public Member Functions

 styled_widget (const implementation::builder_styled_widget &builder, const std::string &control_type)
 Constructor. More...
 
virtual void set_members (const widget_item &data)
 Sets the members of the styled_widget. More...
 
virtual void set_active (const bool active)=0
 Sets the styled_widget's state. More...
 
virtual bool get_active () const =0
 Gets the active state of the styled_widget. More...
 
bool disable_click_dismiss () const override
 See widget::disable_click_dismiss. More...
 
virtual iteration::walker_ptr create_walker () override
 See widget::create_walker. More...
 
point get_config_minimum_size () const
 Gets the minimum size as defined in the config. More...
 
point get_config_default_size () const
 Gets the default size as defined in the config. More...
 
point get_config_maximum_size () const
 Gets the best size as defined in the config. More...
 
virtual unsigned get_characters_per_line () const
 Returns the number of characters per line. More...
 
virtual bool get_link_aware () const
 Returns whether the label should be link_aware, in in rendering and in searching for links with get_link. More...
 
virtual color_t get_link_color () const
 Returns the color string to be used with links. More...
 
virtual void layout_initialize (const bool full_initialization) override
 See widget::layout_initialize. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See widget::request_reduce_width. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See widget::request_reduce_height. More...
 
virtual void place (const point &origin, const point &size) override
 See widget::place. More...
 
virtual widgetfind_at (const point &coordinate, const bool must_be_active) override
 See widget::find_at. More...
 
virtual const widgetfind_at (const point &coordinate, const bool must_be_active) const override
 See widget::find_at. More...
 
widgetfind (const std::string &id, const bool must_be_active) override
 See widget::find. More...
 
const widgetfind (const std::string &id, const bool must_be_active) const override
 See widget::find. More...
 
bool get_use_tooltip_on_label_overflow () const
 
void set_use_tooltip_on_label_overflow (const bool use_tooltip=true)
 
const t_stringget_label () const
 
virtual void set_label (const t_string &text)
 
virtual void set_use_markup (bool use_markup)
 
bool get_use_markup () const
 
const t_stringtooltip () const
 
void set_tooltip (const t_string &tooltip)
 
const t_stringhelp_message () const
 
void set_help_message (const t_string &help_message)
 
std::vector< canvas > & get_canvases ()
 
canvasget_canvas (const unsigned index)
 
virtual void set_text_alignment (const PangoAlignment text_alignment)
 
PangoAlignment get_text_alignment () const
 
void set_text_ellipse_mode (const PangoEllipsizeMode ellipse_mode)
 
PangoEllipsizeMode get_text_ellipse_mode () const
 Get the text's ellipsize mode. More...
 
void set_text_maximum_width (int max_width)
 Set how wide the text can become. More...
 
virtual const std::string & get_control_type () const =0
 Returns the type of this styled_widget. More...
 
- Public Member Functions inherited from gui2::widget
 widget (const widget &)=delete
 
widgetoperator= (const widget &)=delete
 
 widget ()
 
 widget (const builder_widget &builder)
 Constructor. More...
 
virtual ~widget () override
 
void set_id (const std::string &id)
 
const std::string & id () const
 
windowget_window ()
 Get the parent window. More...
 
const windowget_window () const
 The constant version of get_window. More...
 
gridget_parent_grid ()
 Get the parent grid. More...
 
const gridget_parent_grid () const
 
void set_parent (widget *parent)
 
widgetparent ()
 
virtual void demand_reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a widget. More...
 
virtual void demand_reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a widget. More...
 
point get_best_size () const
 Gets the best size for the widget. More...
 
virtual bool can_mouse_focus () const
 Whether the mouse move/click event go 'through' this widget. More...
 
virtual bool can_wrap () const
 Can the widget wrap. More...
 
virtual void set_origin (const point &origin)
 Sets the origin of the widget. More...
 
virtual void set_size (const point &size)
 Sets the size of the widget. More...
 
virtual void move (const int x_offset, const int y_offset)
 Moves a widget. More...
 
virtual void set_horizontal_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void set_vertical_alignment (const std::string &alignment)
 Sets the horizontal alignment of the widget within its parent grid. More...
 
virtual void layout_children ()
 Allows a widget to update its children. More...
 
point get_origin () const
 Returns the screen origin of the widget. More...
 
point get_size () const
 Returns the size of the widget. More...
 
rect get_rectangle () const
 Gets the bounding rectangle of the widget on the screen. More...
 
int get_x () const
 
int get_y () const
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_linked_group (const std::string &linked_group)
 
std::string get_linked_group () const
 
SDL_Rect calculate_blitting_rectangle () const
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle () const
 Calculates the clipping rectangle of the widget. More...
 
bool draw_background ()
 Draws the background of a widget. More...
 
void draw_children ()
 Draws the children of a widget. More...
 
bool draw_foreground ()
 Draws the foreground of the widget. More...
 
SDL_Rect get_dirty_rectangle () const
 Gets the dirty rectangle of the widget. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle)
 Sets the visible rectangle for a widget. More...
 
void queue_redraw ()
 Indicates that this widget should be redrawn. More...
 
void queue_redraw (const rect &region)
 Indicate that specific region of the screen should be redrawn. More...
 
void set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const debug_border debug_border_mode)
 
void set_debug_border_color (const color_t debug_border_color)
 
virtual bool has_widget (const widget &widget) const
 Does the widget contain the widget. More...
 
template<class T >
NOT_DANGLING T * find_widget (const std::string &id, const bool must_be_active, const bool must_exist)
 Gets a widget with the wanted id. More...
 
template<class T >
NOT_DANGLING const T * find_widget (const std::string &id, const bool must_be_active, const bool must_exist) const
 
template<class T >
NOT_DANGLING T & find_widget (const std::string &id, const bool must_be_active=false)
 Gets a widget with the wanted id. More...
 
template<class T >
NOT_DANGLING const T & find_widget (const std::string &id, const bool must_be_active=false) const
 
- 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

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

Private Member Functions

point get_best_text_size (point minimum_size, point maximum_size={0, 0}) const
 Gets the best size for a text. More...
 
virtual bool text_can_shrink ()
 Gets whether a widget can shrink past its optimal size even if it's text-based (such as labels);. More...
 
void signal_handler_show_tooltip (const event::ui_event event, bool &handled, const point &location)
 
void signal_handler_show_helptip (const event::ui_event event, bool &handled, const point &location)
 
void signal_handler_notify_remove_tooltip (const event::ui_event event, bool &handled)
 

Private Attributes

std::string definition_
 The definition is the id of that widget class. More...
 
t_string label_
 Contain the non-editable text associated with styled_widget. More...
 
bool use_markup_
 Use markup for the label? More...
 
bool use_tooltip_on_label_overflow_
 If the text doesn't fit on the label should the text be used as tooltip? More...
 
t_string tooltip_
 Tooltip text. More...
 
t_string help_message_
 Tooltip text. More...
 
resolution_definition_ptr config_
 Contains the pointer to the configuration. More...
 
unsigned int cached_text_font_size_ = 0
 Contains the evaluated text_font_size from the configuration. More...
 
std::vector< canvascanvases_
 Holds all canvas objects for a styled_widget. More...
 
font::pango_text renderer_
 Text renderer object used for size calculations. More...
 
int text_maximum_width_
 The maximum width for the text in a styled_widget. More...
 
PangoAlignment text_alignment_
 The alignment of the text in a styled_widget. More...
 
PangoEllipsizeMode text_ellipse_mode_
 The ellipsize mode of the text in a styled_widget. More...
 
bool shrunken_
 Is the widget smaller as it's best size? More...
 

Friends

class debug_layout_graph
 

Additional Inherited Members

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

Detailed Description

Definition at line 34 of file styled_widget.hpp.

Constructor & Destructor Documentation

◆ styled_widget()

gui2::styled_widget::styled_widget ( const implementation::builder_styled_widget builder,
const std::string &  control_type 
)

Constructor.

Parameters
builderThe builder object with the settings for the object.
control_typeThe type of control to be built.

Definition at line 46 of file styled_widget.cpp.

References canvases_, config_, t_string::empty(), i, gui2::event_executor::set_wants_mouse_hover(), signal_handler_notify_remove_tooltip(), signal_handler_show_helptip(), signal_handler_show_tooltip(), tooltip_, and update_canvas().

Member Function Documentation

◆ calculate_best_size()

point gui2::styled_widget::calculate_best_size ( ) const
overrideprotectedvirtual

◆ cast_config_to()

template<typename T >
std::shared_ptr<const typename T::resolution> gui2::styled_widget::cast_config_to ( ) const
inlineprotected

Casts the current resolution definition config to the respective type of a derived widget.

Template Parameters
TThe definition type to cast to. Should have a resolution subclass or struct derived from resolution_definition.
Returns
A shared_ptr with the newly cast config.

Definition at line 301 of file styled_widget.hpp.

References get_config().

Referenced by gui2::implementation::builder_scrollbar_panel::build().

◆ create_walker()

iteration::walker_ptr gui2::styled_widget::create_walker ( )
overridevirtual

See widget::create_walker.

Implements gui2::widget.

Reimplemented in gui2::scrollbar_container, gui2::matrix, and gui2::container_base.

Definition at line 134 of file styled_widget.cpp.

◆ disable_click_dismiss()

bool gui2::styled_widget::disable_click_dismiss ( ) const
overridevirtual

See widget::disable_click_dismiss.

The default behavior is that a widget blocks easy close, if not it should override this function.

Implements gui2::widget.

Definition at line 129 of file styled_widget.cpp.

References get_active(), gui2::widget::get_visible(), and gui2::widget::visible.

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

◆ find() [1/2]

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

See widget::find.

Reimplemented from gui2::widget.

Reimplemented in gui2::window.

Definition at line 312 of file styled_widget.cpp.

References gui2::widget::find(), and get_active().

◆ find() [2/2]

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

See widget::find.

Reimplemented from gui2::widget.

Reimplemented in gui2::window.

Definition at line 304 of file styled_widget.cpp.

References gui2::widget::find(), and get_active().

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

◆ find_at() [1/2]

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

◆ find_at() [2/2]

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

◆ get_active()

virtual bool gui2::styled_widget::get_active ( ) const
pure virtual

◆ get_best_text_size()

point gui2::styled_widget::get_best_text_size ( point  minimum_size,
point  maximum_size = {0, 0} 
) const
private

◆ get_canvas()

canvas& gui2::styled_widget::get_canvas ( const unsigned  index)
inline

◆ get_canvases()

std::vector<canvas>& gui2::styled_widget::get_canvases ( )
inline

◆ get_characters_per_line()

unsigned gui2::styled_widget::get_characters_per_line ( ) const
virtual

Returns the number of characters per line.

This value is used to call pango_text::set_characters_per_line (indirectly).

Returns
The characters per line. This implementation always returns 0.

Reimplemented in gui2::rich_label, and gui2::label.

Definition at line 169 of file styled_widget.cpp.

Referenced by get_best_text_size(), and update_canvas().

◆ get_config() [1/2]

resolution_definition_ptr gui2::styled_widget::get_config ( )
inlineprotected

◆ get_config() [2/2]

resolution_definition_const_ptr gui2::styled_widget::get_config ( ) const
inlineprotected

Definition at line 286 of file styled_widget.hpp.

References config_.

◆ get_config_default_size()

point gui2::styled_widget::get_config_default_size ( ) const

Gets the default size as defined in the config.

Precondition
config_ != nullptr
Returns
The size.

Definition at line 149 of file styled_widget.cpp.

References config_, DBG_GUI_L, and LOG_HEADER.

Referenced by gui2::container_base::calculate_best_size(), gui2::image::calculate_best_size(), and calculate_best_size().

◆ get_config_maximum_size()

point gui2::styled_widget::get_config_maximum_size ( ) const

Gets the best size as defined in the config.

Precondition
config_ != nullptr
Returns
The size.

Definition at line 159 of file styled_widget.cpp.

References config_, DBG_GUI_L, and LOG_HEADER.

Referenced by gui2::image::calculate_best_size(), calculate_best_size(), and gui2::grid::child::place().

◆ get_config_minimum_size()

point gui2::styled_widget::get_config_minimum_size ( ) const

Gets the minimum size as defined in the config.

Precondition
config_ != nullptr
Returns
The size.

Definition at line 139 of file styled_widget.cpp.

References config_, DBG_GUI_L, and LOG_HEADER.

Referenced by request_reduce_height(), and request_reduce_width().

◆ get_control_type()

virtual const std::string& gui2::styled_widget::get_control_type ( ) const
pure virtual

Returns the type of this styled_widget.

This is used as the control_type parameter for get_control.

Do note that each widget also must have a public static type() function; it's use to implement this function. The reason for this system is twofold:

1) Due to an oddity in C++, one technically may not call a virtual function in a derived class's initializer list, which we do liberally. Calling it in the constructor body is fine, but doing so in the initializer list is technically undefined behavior and will give "invalid vptr" errors under UBSanitizer.

2) Having a static type getter allows the type string to be fetched without constructing an instance of the widget. A good example of this usecase is in build_single_widget_instance.

Implemented in gui2::window, gui2::vertical_scrollbar, gui2::unit_preview_pane, gui2::tree_view, gui2::toggle_panel, gui2::toggle_button, gui2::text_box, gui2::tab_container, gui2::stacked_widget, gui2::spinner, gui2::spacer, gui2::slider, gui2::size_lock, gui2::scrollbar_panel, gui2::scrollbar_container, gui2::scroll_text, gui2::scroll_label, gui2::rich_label, gui2::repeating_button, gui2::progress_bar, gui2::password_box, gui2::panel, gui2::multimenu_button, gui2::multiline_text, gui2::multi_page, gui2::minimap, gui2::menu_button, gui2::matrix, gui2::listbox, gui2::label, gui2::image, gui2::horizontal_scrollbar, gui2::drawing, gui2::combobox, gui2::chatbox, gui2::button, and gui2::addon_list.

Referenced by gui2::widget::set_id().

◆ get_label()

const t_string& gui2::styled_widget::get_label ( ) const
inline

◆ get_label_link()

std::string gui2::styled_widget::get_label_link ( const point position) const
protected

◆ get_label_token()

std::string gui2::styled_widget::get_label_token ( const point position,
const char *  delimiters = " \n\r\t" 
) const
protected

Exposes font::pango_text::get_token, for the text label of this styled_widget.

Definition at line 576 of file styled_widget.cpp.

References font::pango_text::get_token(), and renderer_.

◆ get_link_aware()

bool gui2::styled_widget::get_link_aware ( ) const
virtual

Returns whether the label should be link_aware, in in rendering and in searching for links with get_link.

This value is used to call pango_text::set_link_aware (indirectly).

Returns
The link aware status. This impl always always returns false.

Reimplemented in gui2::scroll_text, gui2::scroll_label, gui2::rich_label, gui2::multiline_text, and gui2::label.

Definition at line 174 of file styled_widget.cpp.

Referenced by get_best_text_size(), and update_canvas().

◆ get_link_color()

color_t gui2::styled_widget::get_link_color ( ) const
virtual

Returns the color string to be used with links.

This value is used to call pango_text::set_link_color (indirectly).

Returns
The link color string. This impl returns "#ffff00".

Reimplemented in gui2::rich_label, and gui2::label.

Definition at line 179 of file styled_widget.cpp.

References color_t::from_hex_string().

Referenced by get_best_text_size(), and update_canvas().

◆ get_state()

virtual unsigned gui2::styled_widget::get_state ( ) const
protectedpure virtual

◆ get_text_alignment()

PangoAlignment gui2::styled_widget::get_text_alignment ( ) const
inline

Definition at line 263 of file styled_widget.hpp.

References text_alignment_.

Referenced by gui2::rich_label::default_text_config().

◆ get_text_ellipse_mode()

PangoEllipsizeMode gui2::styled_widget::get_text_ellipse_mode ( ) const
inline

Get the text's ellipsize mode.

Note that if can_wrap is true, it override the manual setting.

Definition at line 275 of file styled_widget.hpp.

References gui2::widget::can_wrap(), and text_ellipse_mode_.

Referenced by get_best_text_size(), and update_canvas().

◆ get_text_font_size()

unsigned int gui2::styled_widget::get_text_font_size ( ) const
protected

Resolves and returns the text_font_size.

To allow the text_font_size in the widget definition to be a formula, call this function which will evaluate the formula (caching the result) and return the value.

Definition at line 407 of file styled_widget.cpp.

References cached_text_font_size_, config_, and gui2::get_screen_size_variables().

Referenced by get_best_text_size(), gui2::text_box::text_box(), gui2::combobox::update_offsets(), gui2::multiline_text::update_offsets(), and gui2::text_box::update_offsets().

◆ get_text_maximum_height()

int gui2::styled_widget::get_text_maximum_height ( ) const
protected

Returns the maximum height available for the text.

This value makes sense after the widget has been given a size, since the maximum height is based on the height of the widget.

Definition at line 425 of file styled_widget.cpp.

References config_, and gui2::widget::get_height().

Referenced by gui2::combobox::place(), gui2::multiline_text::place(), gui2::text_box::place(), update_canvas(), gui2::combobox::update_canvas(), gui2::multiline_text::update_canvas(), and gui2::text_box::update_canvas().

◆ get_text_maximum_width()

int gui2::styled_widget::get_text_maximum_width ( ) const
protected

Returns the maximum width available for the text.

This value makes sense after the widget has been given a size, since the maximum width is based on the width of the widget.

Definition at line 417 of file styled_widget.cpp.

References config_, gui2::widget::get_width(), and text_maximum_width_.

Referenced by gui2::combobox::place(), gui2::multiline_text::place(), gui2::text_box::place(), update_canvas(), gui2::combobox::update_canvas(), gui2::multiline_text::update_canvas(), and gui2::text_box::update_canvas().

◆ get_use_markup()

bool gui2::styled_widget::get_use_markup ( ) const
inline

◆ get_use_tooltip_on_label_overflow()

bool gui2::styled_widget::get_use_tooltip_on_label_overflow ( ) const
inline

Definition at line 202 of file styled_widget.hpp.

References use_tooltip_on_label_overflow_.

◆ help_message()

const t_string& gui2::styled_widget::help_message ( ) const
inline

Definition at line 238 of file styled_widget.hpp.

References help_message_.

Referenced by set_help_message().

◆ impl_draw_background()

bool gui2::styled_widget::impl_draw_background ( )
overrideprotectedvirtual

◆ impl_draw_foreground()

bool gui2::styled_widget::impl_draw_foreground ( )
overrideprotectedvirtual

See widget::impl_draw_foreground.

Reimplemented from gui2::widget.

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

Definition at line 444 of file styled_widget.cpp.

Referenced by gui2::toggle_panel::impl_draw_foreground().

◆ layout_initialize()

void gui2::styled_widget::layout_initialize ( const bool  full_initialization)
overridevirtual

See widget::layout_initialize.

Todo:
Also handle the tooltip state. Handle if shrunken_ && use_tooltip_on_label_overflow_.

Reimplemented from gui2::widget.

Reimplemented in gui2::scrollbar_container, gui2::matrix, and gui2::container_base.

Definition at line 184 of file styled_widget.cpp.

References gui2::widget::layout_initialize(), and shrunken_.

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

◆ place()

void gui2::styled_widget::place ( const point origin,
const point size 
)
overridevirtual

◆ request_reduce_height()

void gui2::styled_widget::request_reduce_height ( const unsigned  maximum_height)
overridevirtual

◆ request_reduce_width()

void gui2::styled_widget::request_reduce_width ( const unsigned  maximum_width)
overridevirtual

◆ set_active()

virtual void gui2::styled_widget::set_active ( const bool  active)
pure virtual

◆ set_config()

void gui2::styled_widget::set_config ( resolution_definition_ptr  config)
inlineprotected

Definition at line 310 of file styled_widget.hpp.

References config_.

◆ set_help_message()

void gui2::styled_widget::set_help_message ( const t_string help_message)
inline

Definition at line 244 of file styled_widget.hpp.

References help_message(), and help_message_.

Referenced by set_members().

◆ set_label()

void gui2::styled_widget::set_label ( const t_string text)
virtual

Reimplemented in gui2::rich_label, gui2::scroll_text, and gui2::scroll_label.

Definition at line 321 of file styled_widget.cpp.

References label, label_, draw::point(), gui2::widget::queue_redraw(), renderer_, gui2::widget::set_layout_size(), font::pango_text::set_text(), update_canvas(), and use_markup_.

Referenced by gui2::dialogs::statistics_dialog::add_damage_row(), gui2::dialogs::statistics_dialog::add_hits_row(), gui2::dialogs::preferences_dialog::add_hotkey_callback(), gui2::dialogs::mp_lobby::adjust_game_row_contents(), gui2::bind_status_label(), gui2::dialogs::campaign_selection::campaign_selected(), gui2::dialogs::file_dialog::check_filename(), gui2::dialogs::chat_log::model::clear_chat_msg_list(), gui2::dialogs::gamestate_inspector::view::clear_stuff_list(), gui2::dialogs::story_viewer::display_part(), gui2::dialogs::game_load::display_savegame(), gui2::dialogs::editor_edit_pbl::editor_edit_pbl(), gui2::dialogs::file_progress::file_progress(), gui2::scroll_label::finalize_subclass(), gui2::scroll_text::finalize_subclass(), gui2::dialogs::synched_choice_wait::handle_generic_event(), gui2::dialogs::mp_change_control::highlight_side_nick(), gui2::dialogs::message_implementation::init_button(), gui2::dialogs::preferences_dialog::initialize_callbacks(), gui2::dialogs::loading_screen::layout(), gui2::dialogs::mp_match_history::new_search(), gui2::dialogs::addon_manager::on_addon_select(), gui2::dialogs::mp_create_game::on_game_select(), gui2::dialogs::chat_log::model::populate_chat_message_list(), gui2::dialogs::install_dependencies::pre_show(), gui2::dialogs::campaign_selection::pre_show(), gui2::dialogs::file_dialog::pre_show(), gui2::dialogs::lua_interpreter::pre_show(), gui2::dialogs::message::pre_show(), gui2::dialogs::mp_lobby::pre_show(), gui2::dialogs::mp_join_game::pre_show(), gui2::dialogs::mp_staging::pre_show(), gui2::dialogs::synched_choice_wait::pre_show(), gui2::dialogs::network_transmission::pre_show(), gui2::dialogs::simple_item_selector::pre_show(), gui2::dialogs::statistics_dialog::pre_show(), gui2::dialogs::unit_recall::pre_show(), gui2::dialogs::wml_message_base::pre_show(), gui2::dialogs::preferences_dialog::remove_hotkey_callback(), gui2::dialogs::unit_recall::rename_unit(), gui2::dialogs::achievements_dialog::set_achievements_row(), gui2::dialogs::attack_predictions::set_data(), gui2::unit_preview_pane::set_displayed_type(), gui2::unit_preview_pane::set_displayed_unit(), gui2::image::set_image(), gui2::scroll_label::set_label(), gui2::rich_label::set_label(), set_members(), gui2::menu_button::set_selected(), gui2::rich_label::set_topic(), gui2::multimenu_button::set_values(), gui2::menu_button::set_values(), gui2::dialogs::mp_create_game::show_description(), gui2::dialogs::addon_manager::toggle_details(), gui2::dialogs::tooltip::tooltip(), gui2::dialogs::gamestate_inspector::view::update(), gui2::dialogs::game_cache_options::update_cache_size_display(), gui2::dialogs::mp_create_game::update_details(), gui2::dialogs::mp_match_history::update_display(), gui2::multimenu_button::update_label(), gui2::multiline_text::update_layout(), gui2::dialogs::mp_staging::update_leader_display(), gui2::dialogs::lobby_player_info::update_relation(), gui2::dialogs::chat_log::controller::update_view_from_model(), and gui2::dialogs::mp_lobby::update_visible_games().

◆ set_members()

void gui2::styled_widget::set_members ( const widget_item data)
virtual

Sets the members of the styled_widget.

The map contains named members it can set, controls inheriting from us can add additional members to set by this function. The following members can by the following key:

  • label_ label
  • tooltip_ tooltip
  • help_message_ help
Parameters
dataMap with the key value pairs to set the members.
Todo:
document this feature on the wiki.
Todo:
do we need to add the debug colors here as well?

Reimplemented in gui2::toggle_button.

Definition at line 89 of file styled_widget.cpp.

References data, gui2::decode_text_alignment(), set_help_message(), gui2::widget::set_id(), set_label(), gui2::widget::set_linked_group(), set_text_alignment(), set_tooltip(), set_use_markup(), and utils::string_bool().

Referenced by gui2::pane::create_item(), gui2::policy::select_action::show::init(), gui2::toggle_panel::set_child_members(), and gui2::toggle_button::set_members().

◆ set_text_alignment()

void gui2::styled_widget::set_text_alignment ( const PangoAlignment  text_alignment)
virtual

◆ set_text_ellipse_mode()

void gui2::styled_widget::set_text_ellipse_mode ( const PangoEllipsizeMode  ellipse_mode)

◆ set_text_maximum_width()

void gui2::styled_widget::set_text_maximum_width ( int  max_width)
inline

Set how wide the text can become.

If the text is bigger than this limit, it gets wrapped

Definition at line 355 of file styled_widget.hpp.

References text_maximum_width_.

Referenced by gui2::scroll_label::set_text_max_width().

◆ set_tooltip()

void gui2::styled_widget::set_tooltip ( const t_string tooltip)
inline

◆ set_use_markup()

void gui2::styled_widget::set_use_markup ( bool  use_markup)
virtual

◆ set_use_tooltip_on_label_overflow()

void gui2::styled_widget::set_use_tooltip_on_label_overflow ( const bool  use_tooltip = true)
inline

Definition at line 207 of file styled_widget.hpp.

References use_tooltip_on_label_overflow_.

◆ signal_handler_notify_remove_tooltip()

void gui2::styled_widget::signal_handler_notify_remove_tooltip ( const event::ui_event  event,
bool &  handled 
)
private

Definition at line 561 of file styled_widget.cpp.

References DBG_GUI_E, LOG_HEADER, and gui2::dialogs::tip::remove().

Referenced by styled_widget().

◆ signal_handler_show_helptip()

void gui2::styled_widget::signal_handler_show_helptip ( const event::ui_event  event,
bool &  handled,
const point location 
)
private

◆ signal_handler_show_tooltip()

void gui2::styled_widget::signal_handler_show_tooltip ( const event::ui_event  event,
bool &  handled,
const point location 
)
private

◆ text_can_shrink()

virtual bool gui2::styled_widget::text_can_shrink ( )
inlineprivatevirtual

Gets whether a widget can shrink past its optimal size even if it's text-based (such as labels);.

Reimplemented in gui2::rich_label, and gui2::label.

Definition at line 481 of file styled_widget.hpp.

Referenced by request_reduce_width().

◆ tooltip()

const t_string& gui2::styled_widget::tooltip ( ) const
inline

◆ update_canvas()

void gui2::styled_widget::update_canvas ( )
protectedvirtual

Friends And Related Function Documentation

◆ debug_layout_graph

friend class debug_layout_graph
friend

Definition at line 36 of file styled_widget.hpp.

Member Data Documentation

◆ cached_text_font_size_

unsigned int gui2::styled_widget::cached_text_font_size_ = 0
mutableprivate

Contains the evaluated text_font_size from the configuration.

We want to allow formulas in the value of text_font_size, since the desired font size can depend on parameters of the screen and window. But we don't want to have to recompute the value of the formula all the time. This member variable is the cache for the evaluated font size.

Definition at line 419 of file styled_widget.hpp.

Referenced by get_text_font_size().

◆ canvases_

std::vector<canvas> gui2::styled_widget::canvases_
private

Holds all canvas objects for a styled_widget.

A styled_widget can have multiple states, which are defined in the classes inheriting from us. For every state there is a separate canvas, which is stored here. When drawing the state is determined and that canvas is drawn.

Definition at line 429 of file styled_widget.hpp.

Referenced by get_canvas(), get_canvases(), place(), styled_widget(), and update_canvas().

◆ config_

resolution_definition_ptr gui2::styled_widget::config_
private

Contains the pointer to the configuration.

Every styled_widget has a definition of how it should look, this contains a pointer to the definition. The definition is resolution dependent, where the resolution is the size of the Wesnoth application window. Depending on the resolution widgets can look different, use different fonts. Windows can use extra scrollbars use abbreviations as text etc.

Definition at line 409 of file styled_widget.hpp.

Referenced by calculate_best_size(), get_best_text_size(), get_config(), get_config_default_size(), get_config_maximum_size(), get_config_minimum_size(), get_text_font_size(), get_text_maximum_height(), get_text_maximum_width(), request_reduce_width(), set_config(), and styled_widget().

◆ definition_

std::string gui2::styled_widget::definition_
private

The definition is the id of that widget class.

Eg for a button it [button_definition]id. A button can have multiple definitions which all look different but for the engine still is a button.

Definition at line 369 of file styled_widget.hpp.

◆ help_message_

t_string gui2::styled_widget::help_message_
private

Tooltip text.

The help event can cause a tooltip to be shown, this is the text to be shown. At the moment the tooltip is a single line of text.

Definition at line 398 of file styled_widget.hpp.

Referenced by help_message(), set_help_message(), signal_handler_show_helptip(), and signal_handler_show_tooltip().

◆ label_

t_string gui2::styled_widget::label_
private

◆ renderer_

font::pango_text gui2::styled_widget::renderer_
mutableprivate

Text renderer object used for size calculations.

Note this is not used to actually render any text, only to get the dimensions of the text for layout purposes. The actual text rendering happens in the canvas. This is kept as a class member since creating a pango_text object is quite expensive.

Todo:
Maybe if still too slow we might also copy this cache to the canvas so it can reuse our results, but for now it seems fast enough. Unfortunately that would make the dependency between the classes bigger as wanted.

Definition at line 498 of file styled_widget.hpp.

Referenced by get_best_text_size(), get_label_link(), get_label_token(), place(), and set_label().

◆ shrunken_

bool gui2::styled_widget::shrunken_
private

Is the widget smaller as it's best size?

Definition at line 510 of file styled_widget.hpp.

Referenced by layout_initialize().

◆ text_alignment_

PangoAlignment gui2::styled_widget::text_alignment_
private

The alignment of the text in a styled_widget.

Definition at line 504 of file styled_widget.hpp.

Referenced by get_best_text_size(), get_text_alignment(), set_text_alignment(), and update_canvas().

◆ text_ellipse_mode_

PangoEllipsizeMode gui2::styled_widget::text_ellipse_mode_
private

The ellipsize mode of the text in a styled_widget.

Definition at line 507 of file styled_widget.hpp.

Referenced by get_text_ellipse_mode(), and set_text_ellipse_mode().

◆ text_maximum_width_

int gui2::styled_widget::text_maximum_width_
private

The maximum width for the text in a styled_widget.

Definition at line 501 of file styled_widget.hpp.

Referenced by get_best_text_size(), get_text_maximum_width(), and set_text_maximum_width().

◆ tooltip_

t_string gui2::styled_widget::tooltip_
private

Tooltip text.

The hovering event can cause a small tooltip to be shown, this is the text to be shown. At the moment the tooltip is a single line of text.

Definition at line 390 of file styled_widget.hpp.

Referenced by place(), set_tooltip(), signal_handler_show_tooltip(), styled_widget(), and tooltip().

◆ use_markup_

bool gui2::styled_widget::use_markup_
private

Use markup for the label?

Definition at line 375 of file styled_widget.hpp.

Referenced by get_best_text_size(), get_use_markup(), set_label(), set_use_markup(), and update_canvas().

◆ use_tooltip_on_label_overflow_

bool gui2::styled_widget::use_tooltip_on_label_overflow_
private

If the text doesn't fit on the label should the text be used as tooltip?

This only happens if the tooltip is empty.

Definition at line 382 of file styled_widget.hpp.

Referenced by get_use_tooltip_on_label_overflow(), place(), and set_use_tooltip_on_label_overflow().


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