The Battle for Wesnoth  1.19.5+dev
Classes | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
gui2::grid Class Reference

Base container class. More...

#include <grid.hpp>

Inheritance diagram for gui2::grid:

Classes

class  child
 Child item of the grid. More...
 
class  iterator
 Iterator for the child items. More...
 

Public Member Functions

 grid (const unsigned rows=0, const unsigned cols=0)
 
 grid (const grid &)=delete
 Delete the copy constructor. More...
 
gridoperator= (const grid &)=delete
 Delete the move assignment operator. More...
 
virtual ~grid ()
 
unsigned add_row (const unsigned count=1)
 Adds a row to end of the grid. More...
 
void set_row_grow_factor (const unsigned row, const unsigned factor)
 Sets the grow factor for a row. More...
 
void set_column_grow_factor (const unsigned column, const unsigned factor)
 Sets the grow factor for a column. More...
 
void set_child (std::unique_ptr< widget > widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
 Sets a child in the grid. More...
 
std::unique_ptr< widgetswap_child (const std::string &id, std::unique_ptr< widget > w, const bool recurse, widget *new_parent=nullptr)
 Exchanges a child in the grid. More...
 
void remove_child (const unsigned row, const unsigned col)
 Removes and frees a widget in a cell. More...
 
void remove_child (const std::string &id, const bool find_all=false)
 Removes and frees a widget in a cell by it's id. More...
 
void set_active (const bool active)
 Activates all children. More...
 
const widgetget_widget (const unsigned row, const unsigned col) const
 Returns the widget in the selected cell. More...
 
widgetget_widget (const unsigned row, const unsigned col)
 Returns the widget in the selected cell. More...
 
virtual bool can_mouse_focus () const override
 Whether the mouse move/click event go 'through' this widget. More...
 
virtual void layout_initialize (const bool full_initialization) override
 See widget::layout_initialize. More...
 
void reduce_width (const unsigned maximum_width)
 Tries to reduce the width of a container. More...
 
virtual void request_reduce_width (const unsigned maximum_width) override
 See widget::request_reduce_width. More...
 
virtual void demand_reduce_width (const unsigned maximum_width) override
 See widget::demand_reduce_width. More...
 
void reduce_height (const unsigned maximum_height)
 Tries to reduce the height of a container. More...
 
virtual void request_reduce_height (const unsigned maximum_height) override
 See widget::request_reduce_height. More...
 
virtual void demand_reduce_height (const unsigned maximum_height) override
 See widget::demand_reduce_height. More...
 
point recalculate_best_size ()
 Recalculates the best size. More...
 
void set_child_alignment (widget *widget, unsigned set_flag, unsigned mode_mask)
 Modifies the widget alignment data of a child cell containing a specific widget. More...
 
virtual bool can_wrap () const override
 See widget::can_wrap. More...
 
virtual void place (const point &origin, const point &size) override
 See widget::place. More...
 
virtual void set_origin (const point &origin) override
 See widget::set_origin. More...
 
virtual void set_visible_rectangle (const SDL_Rect &rectangle) override
 See widget::set_visible_rectangle. More...
 
virtual void layout_children () override
 See widget::layout_children. 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...
 
virtual bool has_widget (const widget &widget) const override
 See widget::has_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...
 
void set_rows (const unsigned rows)
 
unsigned int get_rows () const
 
void set_cols (const unsigned cols)
 
unsigned int get_cols () const
 
void set_rows_cols (const unsigned rows, const unsigned cols)
 Wrapper to set_rows and set_cols. More...
 
iterator begin ()
 
iterator end ()
 
- 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 ()
 
point get_best_size () const
 Gets the best size for 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...
 
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...
 
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)
 
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)
 

Static Public Attributes

static const unsigned VERTICAL_SHIFT = 0
 
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT
 
static const unsigned VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT
 
static const unsigned VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT
 
static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT
 
static const unsigned VERTICAL_MASK = 7 << VERTICAL_SHIFT
 
static const unsigned HORIZONTAL_SHIFT = 3
 
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT
 
static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT
 
static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT
 
static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT
 
static const unsigned HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT
 
static const unsigned BORDER_TOP = 1 << 6
 
static const unsigned BORDER_BOTTOM = 1 << 7
 
static const unsigned BORDER_LEFT = 1 << 8
 
static const unsigned BORDER_RIGHT = 1 << 9
 
static const unsigned BORDER_ALL = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT
 

Private Member Functions

virtual point calculate_best_size () const override
 See widget::calculate_best_size. More...
 
void request_placement (dispatcher &dispatcher, const event::ui_event event, bool &handled, bool &halt)
 Attempts to lay out the grid without laying out the entire window. More...
 
const grid::childget_child (const unsigned row, const unsigned col) const
 Gets the grid child in the specified cell. More...
 
grid::childget_child (const unsigned row, const unsigned col)
 Gets the grid child in the specified cell. More...
 
grid::childget_child (widget *w)
 Gets the grid child containing the specified widget. More...
 
void layout (const point &origin)
 Layouts the children in the grid. More...
 
virtual void impl_draw_children () override
 See widget::impl_draw_children. More...
 

Private Attributes

unsigned rows_
 The number of grid rows. More...
 
unsigned cols_
 The number of grid columns. More...
 
std::vector< unsigned > row_height_
 The row heights in the grid. More...
 
std::vector< unsigned > col_width_
 The column widths in the grid. More...
 
std::vector< unsigned > row_grow_factor_
 The grow factor for all rows. More...
 
std::vector< unsigned > col_grow_factor_
 The grow factor for all columns. More...
 
std::vector< childchildren_
 The child items. More...
 

Friends

class debug_layout_graph
 
struct grid_implementation
 

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...
 
- Protected Member Functions inherited from gui2::widget
void set_layout_size (const point &size)
 
const pointlayout_size () const
 
void clear_layout_size ()
 Throws away layout_size_. More...
 

Detailed Description

Base container class.

This class holds a number of widgets and their wanted layout parameters. It also layouts the items in the grid and handles their drawing.

Definition at line 31 of file grid.hpp.

Constructor & Destructor Documentation

◆ grid() [1/2]

gui2::grid::grid ( const unsigned  rows = 0,
const unsigned  cols = 0 
)
explicit

Definition at line 40 of file grid.cpp.

References gui2::event::dispatcher::back_pre_child, and request_placement().

◆ grid() [2/2]

gui2::grid::grid ( const grid )
delete

Delete the copy constructor.

◆ ~grid()

gui2::grid::~grid ( )
virtual

Definition at line 56 of file grid.cpp.

Member Function Documentation

◆ add_row()

unsigned gui2::grid::add_row ( const unsigned  count = 1)

Adds a row to end of the grid.

Parameters
countNumber of rows to add, should be > 0.
Returns
The row number of the first row added.

Definition at line 60 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

◆ begin()

iterator gui2::grid::begin ( )
inline

Definition at line 479 of file grid.hpp.

References children_.

Referenced by gui2::container_base::begin(), and gui2::iteration::scrollbar_container::next().

◆ calculate_best_size()

point gui2::grid::calculate_best_size ( ) const
overrideprivatevirtual

◆ can_mouse_focus()

virtual bool gui2::grid::can_mouse_focus ( ) const
inlineoverridevirtual

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

Reimplemented from gui2::widget.

Definition at line 192 of file grid.hpp.

◆ can_wrap()

bool gui2::grid::can_wrap ( ) const
overridevirtual

See widget::can_wrap.

Reimplemented from gui2::widget.

Definition at line 471 of file grid.cpp.

References gui2::grid::child::can_wrap(), gui2::widget::can_wrap(), and children_.

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

◆ create_walker()

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

See widget::create_walker.

Implements gui2::widget.

Definition at line 689 of file grid.cpp.

Referenced by test_grid().

◆ demand_reduce_height()

void gui2::grid::demand_reduce_height ( const unsigned  maximum_height)
overridevirtual

See widget::demand_reduce_height.

Todo:
Implement.

Reimplemented from gui2::widget.

Definition at line 374 of file grid.cpp.

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

◆ demand_reduce_width()

void gui2::grid::demand_reduce_width ( const unsigned  maximum_width)
overridevirtual

See widget::demand_reduce_width.

Todo:
Implement.

Reimplemented from gui2::widget.

Definition at line 276 of file grid.cpp.

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

◆ disable_click_dismiss()

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

◆ end()

iterator gui2::grid::end ( )
inline

◆ find() [1/2]

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

See widget::find.

Reimplemented from gui2::widget.

Definition at line 650 of file grid.cpp.

◆ find() [2/2]

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

◆ find_at() [1/2]

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

See widget::find_at.

Reimplemented from gui2::widget.

Definition at line 638 of file grid.cpp.

◆ find_at() [2/2]

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

◆ get_child() [1/3]

grid::child& gui2::grid::get_child ( const unsigned  row,
const unsigned  col 
)
inlineprivate

Gets the grid child in the specified cell.

Parameters
rowThe row of the cell.
colThe column of the cell.
Returns
A const reference to the specified grid child.

Definition at line 538 of file grid.hpp.

References children_, and rows_.

◆ get_child() [2/3]

const grid::child& gui2::grid::get_child ( const unsigned  row,
const unsigned  col 
) const
inlineprivate

Gets the grid child in the specified cell.

Parameters
rowThe row of the cell.
colThe column of the cell.
Returns
A const reference to the specified grid child.

Definition at line 525 of file grid.hpp.

References children_, and rows_.

Referenced by calculate_best_size(), gui2::grid_implementation::column_request_reduce_width(), get_widget(), layout(), remove_child(), gui2::grid_implementation::row_request_reduce_height(), set_child(), and set_child_alignment().

◆ get_child() [3/3]

grid::child * gui2::grid::get_child ( widget w)
private

Gets the grid child containing the specified widget.

Parameters
wThe widget to search for.
Returns
A pointer to the relevant grid child, or nullptr if no grid cell 'owns' the given widget.

Definition at line 917 of file grid.cpp.

References gui2::event::dispatcher::child, children_, gui2::grid::child::get_widget(), and w.

◆ get_cols()

unsigned int gui2::grid::get_cols ( ) const
inline

◆ get_rows()

unsigned int gui2::grid::get_rows ( ) const
inline

◆ get_widget() [1/2]

widget* gui2::grid::get_widget ( const unsigned  row,
const unsigned  col 
)
inline

Returns the widget in the selected cell.

Definition at line 187 of file grid.hpp.

References get_child(), and gui2::grid::child::get_widget().

◆ get_widget() [2/2]

const widget* gui2::grid::get_widget ( const unsigned  row,
const unsigned  col 
) const
inline

◆ has_widget()

bool gui2::grid::has_widget ( const widget widget) const
overridevirtual

◆ impl_draw_children()

void gui2::grid::impl_draw_children ( )
overrideprivatevirtual

◆ layout()

void gui2::grid::layout ( const point origin)
private

Layouts the children in the grid.

Definition at line 960 of file grid.cpp.

References col_width_, cols_, DBG_GUI_L, get_child(), get_widget(), LOG_HEADER, gui2::grid::child::place(), row_height_, rows_, and utf8::size().

Referenced by place().

◆ layout_children()

void gui2::grid::layout_children ( )
overridevirtual

◆ layout_initialize()

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

◆ operator=()

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

Delete the move assignment operator.

◆ place()

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

◆ recalculate_best_size()

point gui2::grid::recalculate_best_size ( )

Recalculates the best size.

This is used for scrollbar containers when they try to update their contents size before falling back to the 'global' invalidate_layout.

Returns
The newly calculated size.

Definition at line 420 of file grid.cpp.

References calculate_best_size(), and gui2::widget::set_layout_size().

Referenced by request_placement().

◆ reduce_height()

void gui2::grid::reduce_height ( const unsigned  maximum_height)

Tries to reduce the height of a container.

See Layout algorithm for more information.

Parameters
maximum_heightThe wanted maximum height.
Todo:
Implement.

Definition at line 281 of file grid.cpp.

References DBG_GUI_L, gui2::widget::get_best_size(), gui2::log_gui_layout, LOG_HEADER, log_scope2, LOG_SCOPE_HEADER, request_reduce_height(), and utf8::size().

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

◆ reduce_width()

void gui2::grid::reduce_width ( const unsigned  maximum_width)

Tries to reduce the width of a container.

See Layout algorithm for more information.

Parameters
maximum_widthThe wanted maximum width.
Todo:
Implement.

Definition at line 203 of file grid.cpp.

References DBG_GUI_L, gui2::widget::get_best_size(), gui2::log_gui_layout, LOG_HEADER, log_scope2, LOG_SCOPE_HEADER, request_reduce_width(), and utf8::size().

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

◆ remove_child() [1/2]

void gui2::grid::remove_child ( const std::string &  id,
const bool  find_all = false 
)

Removes and frees a widget in a cell by it's id.

Parameters
idThe id of the widget to free.
find_allIf true if removes all items with the id, otherwise it stops after removing the first item (or once all children have been tested).

Definition at line 153 of file grid.cpp.

References children_, gui2::grid::child::id(), and gui2::grid::child::set_widget().

◆ remove_child() [2/2]

void gui2::grid::remove_child ( const unsigned  row,
const unsigned  col 
)

Removes and frees a widget in a cell.

Parameters
rowThe row of the cell.
colThe column of the cell.

Definition at line 145 of file grid.cpp.

References cols_, get_child(), rows_, and gui2::grid::child::set_widget().

◆ request_placement()

void gui2::grid::request_placement ( dispatcher dispatcher,
const event::ui_event  event,
bool &  handled,
bool &  halt 
)
private

◆ request_reduce_height()

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

See widget::request_reduce_height.

Todo:
this point shouldn't be reached, find out why it does.
Todo:
Improve this code.

Now we try every item to be reduced, maybe items need a flag whether or not to try to reduce and also evaluate whether the force reduction is still needed.

Reimplemented from gui2::widget.

Definition at line 314 of file grid.cpp.

References calculate_best_size(), DBG_GUI_L, gui2::widget::get_best_size(), LOG_HEADER, row_height_, gui2::grid_implementation::row_request_reduce_height(), rows_, gui2::widget::set_layout_size(), and utf8::size().

Referenced by reduce_height(), gui2::container_base::request_reduce_height(), and gui2::policy::placement::independent::request_reduce_height().

◆ request_reduce_width()

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

◆ set_active()

void gui2::grid::set_active ( const bool  active)

Activates all children.

If a child inherits from styled_widget or is a grid it will call set_active() for the child otherwise it ignores the widget.

Parameters
activeParameter for set_active.

Definition at line 167 of file grid.cpp.

References children_, g, gui2::grid::child::get_widget(), gui2::styled_widget::set_active(), and gui2::widget::widget().

Referenced by gui2::dialogs::editor_edit_pbl::add_translation(), gui2::dialogs::game_load::populate_game_list(), gui2::container_base::set_active(), and gui2::listbox::set_row_active().

◆ set_child()

void gui2::grid::set_child ( std::unique_ptr< widget widget,
const unsigned  row,
const unsigned  col,
const unsigned  flags,
const unsigned  border_size 
)

Sets a child in the grid.

When the child is added to the grid the grid 'owns' the widget. The widget is put in a cell, and every cell can only contain 1 widget if the wanted cell already contains a widget, that widget is freed and removed.

Parameters
widgetThe widget to put in the grid.
rowThe row of the cell.
colThe column of the cell.
flagsThe flags for the widget in the cell.
border_sizeThe size of the border for the cell, how the border is applied depends on the flags.

Definition at line 71 of file grid.cpp.

References cols_, get_child(), gui2::grid::child::get_widget(), HORIZONTAL_MASK, gui2::grid::child::id(), LOG_HEADER, rows_, gui2::grid::child::set_border_size(), gui2::grid::child::set_flags(), gui2::grid::child::set_widget(), VERTICAL_MASK, w, and WRN_GUI_G.

Referenced by add_widget(), gui2::implementation::builder_scrollbar_panel::build(), gui2::builder_grid::build(), gui2::tree_view::finalize_setup(), gui2::container_base::set_child(), and gui2::set_single_child().

◆ set_child_alignment()

void gui2::grid::set_child_alignment ( widget widget,
unsigned  set_flag,
unsigned  mode_mask 
)

Modifies the widget alignment data of a child cell containing a specific widget.

Parameters
widgetThe widget whose cell to modify.
set_flagThe alignment flag to set.
mode_maskWhether to affect horizontal or vertical alignment. Use either HORIZONTAL_MASK or VERTICAL_MASK

Definition at line 932 of file grid.cpp.

References ERR_GUI_G, gui2::event::dispatcher::fire(), get_child(), gui2::grid::child::get_flags(), HORIZONTAL_GROW_SEND_TO_CLIENT, gui2::event::REQUEST_PLACEMENT, gui2::grid::child::set_flags(), and VERTICAL_GROW_SEND_TO_CLIENT.

Referenced by gui2::widget::set_horizontal_alignment(), and gui2::widget::set_vertical_alignment().

◆ set_cols()

void gui2::grid::set_cols ( const unsigned  cols)

Definition at line 703 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

◆ set_column_grow_factor()

void gui2::grid::set_column_grow_factor ( const unsigned  column,
const unsigned  factor 
)
inline

Sets the grow factor for a column.

Todo:
refer to a page with the layout manipulation info.
Parameters
columnThe column to modify.
factorThe grow factor.

Definition at line 102 of file grid.hpp.

References col_grow_factor_, and gui2::widget::queue_redraw().

Referenced by gui2::implementation::builder_scrollbar_panel::build(), gui2::builder_grid::build(), and gui2::container_base::set_column_grow_factor().

◆ set_origin()

void gui2::grid::set_origin ( const point origin)
overridevirtual

◆ set_row_grow_factor()

void gui2::grid::set_row_grow_factor ( const unsigned  row,
const unsigned  factor 
)
inline

Sets the grow factor for a row.

Todo:
refer to a page with the layout manipulation info.
Parameters
rowThe row to modify.
factorThe grow factor.

Definition at line 87 of file grid.hpp.

References gui2::widget::queue_redraw(), and row_grow_factor_.

Referenced by gui2::implementation::builder_scrollbar_panel::build(), gui2::builder_grid::build(), and gui2::container_base::set_row_grow_factor().

◆ set_rows()

void gui2::grid::set_rows ( const unsigned  rows)

Definition at line 694 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

◆ set_rows_cols()

void gui2::grid::set_rows_cols ( const unsigned  rows,
const unsigned  cols 
)

Wrapper to set_rows and set_cols.

Parameters
rowsParameter to call set_rows with.
colsParameter to call set_cols with.

Definition at line 712 of file grid.cpp.

References children_, col_grow_factor_, cols_, LOG_HEADER, row_grow_factor_, rows_, and WRN_GUI_G.

Referenced by add_row(), gui2::implementation::builder_scrollbar_panel::build(), gui2::builder_grid::build(), gui2::tree_view::finalize_setup(), set_cols(), set_rows(), gui2::container_base::set_rows_cols(), and gui2::set_single_child().

◆ set_visible_rectangle()

void gui2::grid::set_visible_rectangle ( const SDL_Rect &  rectangle)
overridevirtual

◆ swap_child()

std::unique_ptr< widget > gui2::grid::swap_child ( const std::string &  id,
std::unique_ptr< widget w,
const bool  recurse,
widget new_parent = nullptr 
)

Exchanges a child in the grid.

It replaced the child with a certain id with the new widget but doesn't touch the other settings of the child.

Parameters
idThe id of the widget to free.
wThe widget to put in the grid.
recurseDo we want to decent into the child grids.
new_parentThe new parent for the swapped out widget.
Returns
The widget which got removed (the parent of the widget is cleared), or w if no matching widget was found.

Definition at line 101 of file grid.cpp.

References children_, gui2::grid::child::free_widget(), g, gui2::grid::child::get_widget(), gui2::grid::child::id(), gui2::grid::child::set_widget(), and w.

Referenced by gui2::tab_container::finalize(), gui2::dialogs::preferences_dialog::initialize_callbacks(), gui2::dialogs::drop_down_menu::pre_show(), and gui2::swap_grid().

Friends And Related Function Documentation

◆ debug_layout_graph

friend class debug_layout_graph
friend

Definition at line 33 of file grid.hpp.

◆ grid_implementation

friend struct grid_implementation
friend

Definition at line 34 of file grid.hpp.

Member Data Documentation

◆ BORDER_ALL

const unsigned gui2::grid::BORDER_ALL = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT
static

Definition at line 66 of file grid.hpp.

Referenced by gui2::implementation::get_border().

◆ BORDER_BOTTOM

const unsigned gui2::grid::BORDER_BOTTOM = 1 << 7
static

◆ BORDER_LEFT

const unsigned gui2::grid::BORDER_LEFT = 1 << 8
static

◆ BORDER_RIGHT

const unsigned gui2::grid::BORDER_RIGHT = 1 << 9
static

◆ BORDER_TOP

const unsigned gui2::grid::BORDER_TOP = 1 << 6
static

◆ children_

std::vector<child> gui2::grid::children_
private

The child items.

All children are stored in a 1D vector and the formula to access a cell is: rows_ * col + row. All other vectors use the same access formula.

Definition at line 515 of file grid.hpp.

Referenced by begin(), can_wrap(), disable_click_dismiss(), end(), gui2::grid_implementation::find(), gui2::grid_implementation::find_at(), get_child(), has_widget(), impl_draw_children(), layout_children(), layout_initialize(), remove_child(), set_active(), set_origin(), set_rows_cols(), set_visible_rectangle(), and swap_child().

◆ col_grow_factor_

std::vector<unsigned> gui2::grid::col_grow_factor_
private

The grow factor for all columns.

Definition at line 507 of file grid.hpp.

Referenced by place(), set_column_grow_factor(), and set_rows_cols().

◆ col_width_

std::vector<unsigned> gui2::grid::col_width_
mutableprivate

The column widths in the grid.

Definition at line 501 of file grid.hpp.

Referenced by calculate_best_size(), layout(), place(), and request_reduce_width().

◆ cols_

unsigned gui2::grid::cols_
private

◆ HORIZONTAL_ALIGN_CENTER

const unsigned gui2::grid::HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT
static

◆ HORIZONTAL_ALIGN_LEFT

const unsigned gui2::grid::HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT
static

◆ HORIZONTAL_ALIGN_RIGHT

const unsigned gui2::grid::HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT
static

◆ HORIZONTAL_GROW_SEND_TO_CLIENT

const unsigned gui2::grid::HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT
static

◆ HORIZONTAL_MASK

const unsigned gui2::grid::HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT
static

◆ HORIZONTAL_SHIFT

const unsigned gui2::grid::HORIZONTAL_SHIFT = 3
static

Definition at line 55 of file grid.hpp.

◆ row_grow_factor_

std::vector<unsigned> gui2::grid::row_grow_factor_
private

The grow factor for all rows.

Definition at line 504 of file grid.hpp.

Referenced by place(), set_row_grow_factor(), and set_rows_cols().

◆ row_height_

std::vector<unsigned> gui2::grid::row_height_
mutableprivate

The row heights in the grid.

Definition at line 498 of file grid.hpp.

Referenced by calculate_best_size(), layout(), place(), and request_reduce_height().

◆ rows_

unsigned gui2::grid::rows_
private

◆ VERTICAL_ALIGN_BOTTOM

const unsigned gui2::grid::VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT
static

◆ VERTICAL_ALIGN_CENTER

const unsigned gui2::grid::VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT
static

◆ VERTICAL_ALIGN_TOP

const unsigned gui2::grid::VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT
static

◆ VERTICAL_GROW_SEND_TO_CLIENT

const unsigned gui2::grid::VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT
static

◆ VERTICAL_MASK

const unsigned gui2::grid::VERTICAL_MASK = 7 << VERTICAL_SHIFT
static

◆ VERTICAL_SHIFT

const unsigned gui2::grid::VERTICAL_SHIFT = 0
static

Definition at line 48 of file grid.hpp.


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