15 #define GETTEXT_DOMAIN "wesnoth-lib"
26 #define LOG_SCOPE_HEADER "tgrid [" + id() + "] " + __func__
27 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
28 #define LOG_IMPL_HEADER "tgrid [" + grid.id() + "] " + __func__ + ':'
30 #define LOG_CHILD_SCOPE_HEADER \
31 "tgrid::tchild [" + (widget_ ? widget_->id() : "-") + "] " + __func__
32 #define LOG_CHILD_HEADER LOG_CHILD_SCOPE_HEADER + ':'
42 , row_grow_factor_(rows)
43 , col_grow_factor_(cols)
44 , children_(rows * cols)
73 const unsigned border_size)
85 << row <<
',' << col <<
"' will be replaced.\n";
211 if(size.
x <= static_cast<int>(maximum_width)) {
221 if(size.
x <= static_cast<int>(maximum_width)) {
240 if(size.
x <= static_cast<int>(maximum_width)) {
245 const unsigned too_wide = size.
x - maximum_width;
246 unsigned reduced = 0;
247 for(
size_t col = 0; col <
cols_; ++col) {
250 <<
" is too small to be reduced.\n";
254 const unsigned wanted_width =
col_width_[col] - (too_wide - reduced);
257 *
this, col, wanted_width);
261 <<
" pixels for column " << col <<
".\n";
267 if(size.
x <= static_cast<int>(maximum_width)) {
287 if(size.
y <= static_cast<int>(maximum_height)) {
297 if(size.
y <= static_cast<int>(maximum_height)) {
316 if(size.
y <= static_cast<int>(maximum_height)) {
321 const unsigned too_high = size.
y - maximum_height;
322 unsigned reduced = 0;
335 <<
" is too small to be reduced fully try 1 pixel.\n";
341 *
this, row, wanted_height);
353 if(size.
y <= static_cast<int>(maximum_height)) {
361 <<
" resulting height " << size.
y <<
".\n";
390 for(
unsigned col = 0; col <
cols_; ++col) {
409 for(
unsigned col = 0; col <
cols_; ++col) {
460 if(best_size == size) {
465 if(best_size.
x > size.x || best_size.
y > size.y) {
467 std::stringstream out;
468 out <<
" Failed to place a grid, we have " << size <<
" space but we need " << best_size <<
" space.";
469 out <<
" This happened at a grid with the id '" <<
id() <<
"'";
471 while(pw !=
nullptr) {
472 out <<
" in a '" <<
typeid(*pw).name() <<
"' with the id '" << pw->
id() <<
"'";
483 if(size.x > best_size.
x) {
484 const unsigned w = size.x - best_size.
x;
485 unsigned w_size = std::accumulate(
489 <<
" will be divided amount " << w_size <<
" units in "
490 <<
cols_ <<
" columns.\n";
502 const unsigned w_normal = w / w_size;
503 for(
unsigned i = 0;
i <
cols_; ++
i) {
506 <<
" with grow factor " << col_grow_factor_[
i]
511 if(size.y > best_size.
y) {
512 const unsigned h = size.y - best_size.
y;
513 unsigned h_size = std::accumulate(
516 <<
" will be divided amount " << h_size <<
" units in "
517 <<
rows_ <<
" rows.\n";
529 const unsigned h_normal = h / h_size;
530 for(
unsigned i = 0;
i <
rows_; ++
i) {
533 << row_grow_factor_[
i] <<
" set height to "
556 widget->
get_y() + movement.
y));
585 const std::vector<twidget*>& call_stack)
587 assert(!call_stack.empty() && call_stack.back() ==
this);
594 std::vector<twidget*> child_call_stack = call_stack;
601 return tgrid_implementation::find_at<twidget>(
602 *
this, coordinate, must_be_active);
606 const bool must_be_active)
const
608 return tgrid_implementation::find_at<const twidget>(
609 *
this, coordinate, must_be_active);
614 return tgrid_implementation::find<twidget>(*
this,
id, must_be_active);
620 return tgrid_implementation::find<const twidget>(*
this,
id, must_be_active);
687 <<
" may give unexpected problems.\n";
709 <<
" widget visible " <<
false <<
" returning 0,0"
717 <<
" widget visible " <<
true <<
" returning " << best_size
731 origin.
y += border_size_;
732 size.
y -= border_size_;
735 size.
y -= border_size_;
739 origin.
x += border_size_;
740 size.
x -= border_size_;
743 size.
x -= border_size_;
750 if(size <= best_size) {
752 <<
" in best size range setting widget to " << origin <<
" x "
766 if(maximum_size ==
tpoint(0, 0) || size <= maximum_size) {
769 <<
" in maximum size range setting widget to " << origin
770 <<
" x " << size <<
".\n";
778 std::min(size.
y, best_size.
y));
779 tpoint widget_orig = origin;
785 widget_size.
y = std::min(size.
y, maximum_size.
y);
787 widget_size.
y = size.
y;
790 << best_size.
y <<
" to " << widget_size.
y <<
".\n";
799 widget_orig.
y += (size.
y - widget_size.
y) / 2;
804 widget_orig.
y += (size.
y - widget_size.
y);
809 << v_flag <<
"' specified.\n";
817 widget_size.
x = std::min(size.
x, maximum_size.
x);
819 widget_size.
x = size.
x;
822 << best_size.
x <<
" to " << widget_size.
x <<
".\n";
830 widget_orig.
x += (size.
x - widget_size.
x) / 2;
835 widget_orig.
x += (size.
x - widget_size.
x);
837 <<
" horizontally aligned at the right.\n";
846 <<
" x " << widget_size <<
".\n";
856 widget_->layout_initialise(full_initialisation);
863 return widget_->id();
873 result.
y += border_size_;
875 result.
y += border_size_;
878 result.
x += border_size_;
880 result.
x += border_size_;
890 for(
unsigned col = 0; col <
cols_; ++col) {
894 <<
" at origin " << orig <<
" with size " << size
945 tgrid&
grid,
const unsigned row,
const unsigned maximum_height)
948 unsigned required_height = 0;
950 for(
size_t x = 0;
x < grid.
cols_; ++
x) {
952 cell_request_reduce_height(cell, maximum_height);
956 if(required_height == 0 || static_cast<size_t>(
size.y)
959 required_height =
size.y;
964 <<
" returning " << required_height <<
".\n";
966 return required_height;
973 unsigned required_width = 0;
975 for(
size_t y = 0;
y < grid.
rows_; ++
y) {
977 cell_request_reduce_width(cell, maximum_width);
981 if(required_width == 0 || static_cast<size_t>(
size.x)
984 required_width =
size.x;
989 <<
" returning " << required_width <<
".\n";
991 return required_width;
996 const unsigned maximum_height)
1010 const unsigned maximum_width)
Define the common log macros for the gui toolkit.
void set_single_child(tgrid &grid, twidget *widget)
Sets the single child in a grid.
Defines the exception classes for the layout algorithm.
void remove_child(const unsigned row, const unsigned col)
Removes and frees a widget in a cell.
unsigned cols_
The number of grid columns.
void reduce_height(const unsigned maximum_height)
Tries to reduce the height of a container.
static const unsigned BORDER_BOTTOM
virtual void demand_reduce_height(const unsigned maximum_height) override
See twidget::demand_reduce_height.
virtual void layout_children() override
See twidget::layout_children.
static const unsigned HORIZONTAL_MASK
tgrid(const unsigned rows=0, const unsigned cols=0)
static const unsigned HORIZONTAL_ALIGN_RIGHT
virtual void impl_draw_children(surface &frame_buffer, int x_offset, int y_offset) override
See twidget::impl_draw_children.
static const unsigned VERTICAL_GROW_SEND_TO_CLIENT
GLuint const GLfloat * val
lg::log_domain log_gui_layout("gui/layout")
virtual void place(const tpoint &origin, const tpoint &size) override
See twidget::place.
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT
tpoint recalculate_best_size()
Recalculates the best size.
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
static const unsigned BORDER_RIGHT
GLint GLint GLint GLint GLint GLint y
virtual void set_origin(const tpoint &origin) override
See twidget::set_origin.
static const unsigned BORDER_TOP
base class of top level items, the only item which needs to store the final canvases to draw on ...
std::vector< unsigned > row_height_
The row heights in the grid.
A class inherited from ttext_box that displays its input as stars.
void place(tpoint origin, tpoint size)
Places the widget in the cell.
static const unsigned HORIZONTAL_ALIGN_LEFT
void layout_initialise(const bool full_initialisation)
Forwards tgrid::layout_initialise to the cell.
virtual iterator::twalker_ * create_walker() override
See twidget::create_walker.
virtual void request_reduce_height(const unsigned maximum_height) override
See twidget::request_reduce_height.
virtual void set_active(const bool active)=0
Sets the control's state.
const tchild & child(const unsigned row, const unsigned col) const
const twidget * widget() const
tpoint get_config_maximum_size() const
Gets the best size as defined in the config.
unsigned rows_
The number of grid rows.
#define LOG_CHILD_SCOPE_HEADER
std::vector< unsigned > row_grow_factor_
The grow factor for all rows.
GLubyte GLubyte GLubyte GLubyte w
static unsigned row_request_reduce_height(tgrid &grid, const unsigned row, const unsigned maximum_height)
Helper function to do the resizing of a row.
void layout(const tpoint &origin)
Layouts the children in the grid.
void set_rows(const unsigned rows)
void set_active(const bool active)
Activates all children.
virtual void request_reduce_width(const unsigned maximum_width) override
See twidget::request_reduce_width.
#define log_scope2(domain, description)
static const unsigned VERTICAL_ALIGN_TOP
Exception thrown when the width resizing has failed.
std::vector< unsigned > col_grow_factor_
The grow factor for all columns.
GLuint GLuint GLsizei count
cl_event GLbitfield flags
virtual bool has_widget(const twidget &widget) const override
See twidget::has_widget.
virtual void set_visible_rectangle(const SDL_Rect &rectangle) override
See twidget::set_visible_rectangle.
GLenum GLenum GLvoid GLvoid * column
void set_border_size(const unsigned border_size)
virtual bool can_wrap() const override
See twidget::can_wrap.
static void cell_request_reduce_width(tgrid::tchild &child, const unsigned maximum_width)
Helper function to do the resizing of a widget.
GLfloat GLfloat GLfloat GLfloat h
twidget * swap_child(const std::string &id, twidget *widget, const bool recurse, twidget *new_parent=nullptr)
Exchanges a child in the grid.
tpoint border_space() const
Returns the space needed for the border.
GLint GLint GLint GLint GLint x
virtual tpoint calculate_best_size() const override
See twidget::calculate_best_size.
A walker for a gui2::tgrid.
virtual void demand_reduce_width(const unsigned maximum_width) override
See twidget::demand_reduce_width.
unsigned add_row(const unsigned count=1)
Adds a row to end of the grid.
static const unsigned VERTICAL_ALIGN_CENTER
bool can_wrap() const
Returns the can_wrap for the cell.
std::vector< tchild > children_
The child items.
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Base class for all visible items.
void set_widget(twidget *widget)
void set_rows_cols(const unsigned rows, const unsigned cols)
Wrapper to set_rows and set_cols.
GLenum GLenum GLvoid * row
void set_cols(const unsigned cols)
Helper for header for the grid.
const std::string & id() const
Returns the id of the widget/.
static unsigned column_request_reduce_width(tgrid &grid, const unsigned column, const unsigned maximum_width)
Helper function to do the resizing of a column.
twidget * widget_
Pointer to the widget.
static const unsigned HORIZONTAL_ALIGN_CENTER
void set_flags(const unsigned flags)
virtual void layout_initialise(const bool full_initialisation) override
See twidget::layout_initialise.
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
GLint GLint GLint GLint GLint GLint GLsizei width
static const unsigned VERTICAL_MASK
void set_child(twidget *widget, const unsigned row, const unsigned col, const unsigned flags, const unsigned border_size)
Sets a child in the grid.
const twidget * widget(const unsigned row, const unsigned col) const
Returns the widget in the selected cell.
The walker abstract base class.
void reduce_width(const unsigned maximum_width)
Tries to reduce the width of a container.
static void cell_request_reduce_height(tgrid::tchild &child, const unsigned maximum_height)
Helper function to do the resizing of a widget.
tpoint get_best_size() const
Returns the best size for the cell.
Exception thrown when the height resizing has failed.
static const unsigned VERTICAL_ALIGN_BOTTOM
virtual void child_populate_dirty_list(twindow &caller, const std::vector< twidget * > &call_stack) override
See twidget::child_populate_dirty_list.
GLsizei const GLcharARB ** string
virtual twidget * find_at(const tpoint &coordinate, const bool must_be_active) override
See twidget::find_at.
std::vector< unsigned > col_width_
The column widths in the grid.
static const unsigned BORDER_LEFT