The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
Inheritance graph

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 (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, 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 void child_populate_dirty_list (window &caller, const std::vector< widget * > &call_stack) override
 See widget::child_populate_dirty_list. 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_basecreate_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...
 
dialogs::modal_dialogdialog ()
 Returns the top-level dialog. More...
 
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...
 
SDL_Rect get_rectangle () const
 Gets the bounding rectangle of the widget on the screen. More...
 
int get_x () const
 
int get_y () const
 
unsigned get_width () const
 
unsigned get_height () const
 
void set_linked_group (const std::string &linked_group)
 
SDL_Rect calculate_blitting_rectangle (const int x_offset, const int y_offset)
 Calculates the blitting rectangle of the widget. More...
 
SDL_Rect calculate_clipping_rectangle (const int x_offset, const int y_offset)
 Calculates the clipping rectangle of the widget. More...
 
void draw_background (surface &frame_buffer, int x_offset, int y_offset)
 Draws the background of a widget. More...
 
void draw_children (surface &frame_buffer, int x_offset, int y_offset)
 Draws the children of a widget. More...
 
void draw_foreground (surface &frame_buffer, int x_offset, int y_offset)
 Draws the foreground of the widget. More...
 
void populate_dirty_list (window &caller, std::vector< widget * > &call_stack)
 Adds a widget to the dirty list if it is dirty. More...
 
SDL_Rect get_dirty_rectangle () const
 Gets the dirty rectangle of the widget. More...
 
void set_is_dirty (const bool is_dirty)
 
bool get_is_dirty () const
 
void set_visible (const visibility visible)
 
visibility get_visible () const
 
redraw_action get_drawing_action () const
 
void set_debug_border_mode (const unsigned debug_border_mode)
 
void set_debug_border_color (const color_t debug_border_color)
 
- Public Member Functions inherited from gui2::event_executor
 event_executor ()
 
virtual ~event_executor ()
 
void set_wants_mouse_hover (const bool hover=true)
 
bool wants_mouse_hover () const
 
void set_wants_mouse_left_double_click (const bool click=true)
 
bool wants_mouse_left_double_click () const
 
void set_wants_mouse_middle_double_click (const bool click=true)
 
bool wants_mouse_middle_double_click () const
 
event_executorset_wants_mouse_right_double_click (const bool click=true)
 
bool wants_mouse_right_double_click () const
 
- Public Member Functions inherited from gui2::event::dispatcher
 dispatcher ()
 
virtual ~dispatcher ()
 
void connect ()
 Connects the dispatcher to the event handler. More...
 
bool has_event (const ui_event event, const event_queue_type event_type)
 
bool fire (const ui_event event, widget &target)
 Fires an event which has no extra parameters. More...
 
bool fire (const ui_event event, widget &target, const point &coordinate)
 Fires an event which takes a coordinate parameter. More...
 
bool fire (const ui_event event, widget &target, const SDL_Keycode key, const SDL_Keymod modifier, const utf8::string &unicode)
 Fires an event which takes keyboard parameters. More...
 
bool fire (const ui_event event, widget &target, const point &pos, const point &distance)
 Fires an event which takes touch parameters. More...
 
bool fire (const ui_event event, widget &target, void *)
 Fires an event which takes notification parameters. More...
 
bool fire (const ui_event event, widget &target, 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>
utils::enable_if_t< has_key
< set_event, E >::value > 
connect_signal (const signal_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event, E >::value > 
disconnect_signal (const signal_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_mouse, E >::value > 
connect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_mouse, E >::value > 
disconnect_signal (const signal_mouse_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_mouse. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_keyboard, E >
::value > 
connect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_keyboard, E >
::value > 
disconnect_signal (const signal_keyboard_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_keyboard. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_touch, E >::value > 
connect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_touch. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_touch, E >::value > 
disconnect_signal (const signal_touch_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_touch. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_notification, E >
::value > 
connect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_notification. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_notification, E >
::value > 
disconnect_signal (const signal_notification_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_notification. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_message, E >
::value > 
connect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_event_message. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_message, E >
::value > 
disconnect_signal (const signal_message_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_event_message. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_raw_event, E >
::value > 
connect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_raw_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_raw_event, E >
::value > 
disconnect_signal (const signal_raw_event_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_raw_event. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_text_input, E >
::value > 
connect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Connect a signal for callback in set_text_input. More...
 
template<ui_event E>
utils::enable_if_t< has_key
< set_event_text_input, E >
::value > 
disconnect_signal (const signal_text_input_function &signal, const queue_position position=back_child)
 Disconnect a signal for callback in set_text_input. More...
 
void capture_mouse ()
 Captures the mouse. More...
 
void release_mouse ()
 Releases the mouse capture. More...
 
void set_mouse_behavior (const mouse_behavior mouse_behavior)
 
mouse_behavior get_mouse_behavior () const
 
void set_want_keyboard_input (const bool want_keyboard_input)
 
bool get_want_keyboard_input () const
 
void register_hotkey (const hotkey::HOTKEY_COMMAND id, const hotkey_function &function)
 Registers a hotkey. More...
 
bool execute_hotkey (const hotkey::HOTKEY_COMMAND id)
 Executes a hotkey. More...
 

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 (surface &frame_buffer, int x_offset, int y_offset) 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  visibility { visibility::visible, visibility::hidden, visibility::invisible }
 Visibility settings done by the user. More...
 
enum  redraw_action { redraw_action::full, redraw_action::partly, redraw_action::none }
 Visibility set by the engine. More...
 
- Public Types inherited from gui2::event::dispatcher
enum  event_queue_type { pre = 1, child = 2, post = 4 }
 
enum  queue_position {
  front_pre_child, back_pre_child, front_child, back_child,
  front_post_child, back_post_child
}
 The position where to add a new callback in the signal handler. More...
 
enum  mouse_behavior { all, hit, none }
 The behavior of the mouse events. More...
 
- 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 30 of file grid.hpp.

Constructor & Destructor Documentation

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

Definition at line 39 of file grid.cpp.

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

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

Delete the copy constructor.

gui2::grid::~grid ( )
virtual

Definition at line 54 of file grid.cpp.

Member Function Documentation

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 58 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

iterator gui2::grid::begin ( )
inline
point gui2::grid::calculate_best_size ( ) const
overrideprivatevirtual
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 191 of file grid.hpp.

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

See widget::can_wrap.

Reimplemented from gui2::widget.

Definition at line 466 of file grid.cpp.

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

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

void gui2::grid::child_populate_dirty_list ( window caller,
const std::vector< widget * > &  call_stack 
)
overridevirtual
iteration::walker_base * gui2::grid::create_walker ( )
overridevirtual

See widget::create_walker.

Implements gui2::widget.

Definition at line 699 of file grid.cpp.

References preferences::grid().

Referenced by gui2::dialogs::select_orb_colors::setup_orb_group(), and test_grid().

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 369 of file grid.cpp.

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

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 271 of file grid.cpp.

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

bool gui2::grid::disable_click_dismiss ( ) const
overridevirtual
iterator gui2::grid::end ( )
inline
widget * gui2::grid::find ( const std::string &  id,
const bool  must_be_active 
)
overridevirtual
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 660 of file grid.cpp.

References gui2::widget::id().

widget * gui2::grid::find_at ( const point coordinate,
const bool  must_be_active 
)
overridevirtual
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 648 of file grid.cpp.

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 537 of file grid.hpp.

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().

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 550 of file grid.hpp.

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 928 of file grid.cpp.

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

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

Returns the widget in the selected cell.

Definition at line 186 of file grid.hpp.

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

bool gui2::grid::has_widget ( const widget widget) const
overridevirtual
void gui2::grid::impl_draw_children ( surface frame_buffer,
int  x_offset,
int  y_offset 
)
overrideprivatevirtual
void gui2::grid::layout ( const point origin)
private

Layouts the children in the grid.

Definition at line 971 of file grid.cpp.

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

Referenced by place().

void gui2::grid::layout_children ( )
overridevirtual
void gui2::grid::layout_initialize ( const bool  full_initialization)
overridevirtual
grid& gui2::grid::operator= ( const grid )
delete

Delete the move assignment operator.

void gui2::grid::place ( const point origin,
const point size 
)
overridevirtual
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 415 of file grid.cpp.

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

Referenced by request_placement().

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 276 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(), utf8::size(), and point::y.

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

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 198 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(), utf8::size(), and point::x.

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

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 140 of file grid.cpp.

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

Referenced by gui2::window::~window().

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 148 of file grid.cpp.

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

void gui2::grid::request_placement ( dispatcher dispatcher,
const event::ui_event  event,
bool &  handled,
bool &  halt 
)
private
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 309 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(), utf8::size(), and point::y.

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

void gui2::grid::request_reduce_width ( const unsigned  maximum_width)
overridevirtual
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 162 of file grid.cpp.

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

Referenced by gui2::container_base::set_active(), set_active(), and gui2::listbox::set_row_active().

void gui2::grid::set_child ( 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 69 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::widget::set_parent(), gui2::grid::child::set_widget(), VERTICAL_MASK, 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().

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 943 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().

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

Definition at line 713 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

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 101 of file grid.hpp.

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

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

void gui2::grid::set_origin ( const point origin)
overridevirtual
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 86 of file grid.hpp.

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

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

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

Definition at line 704 of file grid.cpp.

References cols_, rows_, and set_rows_cols().

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

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 722 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().

void gui2::grid::set_visible_rectangle ( const SDL_Rect &  rectangle)
overridevirtual
std::unique_ptr< widget > gui2::grid::swap_child ( const std::string &  id,
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). If no widget found and thus not replace nullptr will returned.

Definition at line 98 of file grid.cpp.

References children_, gui2::grid::child::free_widget(), g, gui2::grid::child::get_widget(), gui2::widget::id(), gui2::grid::child::id(), gui2::widget::set_parent(), gui2::widget::set_visible(), gui2::grid::child::set_widget(), and swap_child().

Referenced by gui2::dialogs::preferences_dialog::post_build(), gui2::dialogs::drop_down_menu::pre_show(), swap_child(), and gui2::swap_grid().

Friends And Related Function Documentation

friend class debug_layout_graph
friend

Definition at line 32 of file grid.hpp.

friend struct grid_implementation
friend

Definition at line 33 of file grid.hpp.

Member Data Documentation

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

Definition at line 65 of file grid.hpp.

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

const unsigned gui2::grid::BORDER_BOTTOM = 1 << 7
static
const unsigned gui2::grid::BORDER_LEFT = 1 << 8
static
const unsigned gui2::grid::BORDER_RIGHT = 1 << 9
static
const unsigned gui2::grid::BORDER_TOP = 1 << 6
static
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 527 of file grid.hpp.

Referenced by begin(), can_wrap(), child_populate_dirty_list(), disable_click_dismiss(), end(), 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().

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

The grow factor for all columns.

Definition at line 519 of file grid.hpp.

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

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

The column widths in the grid.

Definition at line 513 of file grid.hpp.

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

unsigned gui2::grid::cols_
private
const unsigned gui2::grid::HORIZONTAL_ALIGN_CENTER = 3 << HORIZONTAL_SHIFT
static
const unsigned gui2::grid::HORIZONTAL_ALIGN_LEFT = 2 << HORIZONTAL_SHIFT
static
const unsigned gui2::grid::HORIZONTAL_ALIGN_RIGHT = 4 << HORIZONTAL_SHIFT
static
const unsigned gui2::grid::HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << HORIZONTAL_SHIFT
static
const unsigned gui2::grid::HORIZONTAL_MASK = 7 << HORIZONTAL_SHIFT
static
const unsigned gui2::grid::HORIZONTAL_SHIFT = 3
static

Definition at line 54 of file grid.hpp.

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

The grow factor for all rows.

Definition at line 516 of file grid.hpp.

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

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

The row heights in the grid.

Definition at line 510 of file grid.hpp.

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

unsigned gui2::grid::rows_
private
const unsigned gui2::grid::VERTICAL_ALIGN_BOTTOM = 4 << VERTICAL_SHIFT
static
const unsigned gui2::grid::VERTICAL_ALIGN_CENTER = 3 << VERTICAL_SHIFT
static
const unsigned gui2::grid::VERTICAL_ALIGN_TOP = 2 << VERTICAL_SHIFT
static
const unsigned gui2::grid::VERTICAL_GROW_SEND_TO_CLIENT = 1 << VERTICAL_SHIFT
static
const unsigned gui2::grid::VERTICAL_MASK = 7 << VERTICAL_SHIFT
static
const unsigned gui2::grid::VERTICAL_SHIFT = 0
static

Definition at line 47 of file grid.hpp.


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