diff --git a/src/gui/auxiliary/window_builder.cpp b/src/gui/auxiliary/window_builder.cpp index e243a64f1ea..d32455aa284 100644 --- a/src/gui/auxiliary/window_builder.cpp +++ b/src/gui/auxiliary/window_builder.cpp @@ -265,29 +265,9 @@ twindow* build(CVideo& video, const std::string& type) , definition->definition); assert(window); - log_scope2(log_gui_general, "Window builder: building grid for window"); - window->set_easy_close(definition->easy_close); - const unsigned rows = definition->grid->rows; - const unsigned cols = definition->grid->cols; - - window->set_rows_cols(rows, cols); - - for(unsigned x = 0; x < rows; ++x) { - window->set_row_grow_factor(x, definition->grid->row_grow_factor[x]); - for(unsigned y = 0; y < cols; ++y) { - - if(x == 0) { - window->set_col_grow_factor(y, definition->grid->col_grow_factor[y]); - } - - twidget* widget = definition->grid->widgets[x * cols + y]->build(); - window->set_child(widget, x, y, - definition->grid->flags[x * cols + y], - definition->grid->border_size[x * cols + y]); - } - } + window->init_grid(definition->grid); window->add_to_keyboard_chain(window); @@ -679,8 +659,7 @@ twidget* tbuilder_listbox::build() const (listbox->config()); assert(conf); - - conf->grid->build(&listbox->grid()); + listbox->init_grid(conf->grid); listbox->finalize(header, footer, list_data); @@ -761,7 +740,7 @@ twidget* tbuilder_multi_page::build() const (multi_page->config()); assert(conf); - conf->grid->build(&multi_page->grid()); + multi_page->init_grid(conf->grid); multi_page->finalize(data); @@ -805,27 +784,7 @@ twidget* tbuilder_panel::build() const DBG_GUI_G << "Window builder: placed panel '" << id << "' with defintion '" << definition << "'.\n"; - - log_scope2(log_gui_general, "Window builder: building grid for panel."); - - const unsigned rows = grid->rows; - const unsigned cols = grid->cols; - - panel->set_rows_cols(rows, cols); - - for(unsigned x = 0; x < rows; ++x) { - panel->set_row_grow_factor(x, grid->row_grow_factor[x]); - for(unsigned y = 0; y < cols; ++y) { - - if(x == 0) { - panel->set_col_grow_factor(y, grid->col_grow_factor[y]); - } - - twidget* widget = grid->widgets[x * cols + y]->build(); - panel->set_child(widget, x, y, grid->flags[x * cols + y], grid->border_size[x * cols + y]); - } - } - + panel->init_grid(grid); return panel; } @@ -840,7 +799,7 @@ twidget* tbuilder_scroll_label::build() const (widget->config()); assert(conf); - conf->grid->build(&widget->grid()); + widget->init_grid(conf->grid); widget->finalize_setup(); DBG_GUI_G << "Window builder: placed scroll label '" << id << "' with defintion '" @@ -971,7 +930,7 @@ twidget* tbuilder_scrollbar_panel::build() const assert(conf); - conf->grid->build(&scrollbar_panel->grid()); + scrollbar_panel->init_grid(conf->grid); scrollbar_panel->finalize_setup(); /*** Fill the content grid. ***/ @@ -1001,6 +960,7 @@ twidget* tbuilder_scrollbar_panel::build() const } } + return scrollbar_panel; } @@ -1095,26 +1055,7 @@ twidget* tbuilder_toggle_panel::build() const DBG_GUI_G << "Window builder: placed toggle panel '" << id << "' with defintion '" << definition << "'.\n"; - log_scope2(log_gui_general, "Window builder: building grid for toggle panel."); - - const unsigned rows = grid->rows; - const unsigned cols = grid->cols; - - toggle_panel->set_rows_cols(rows, cols); - - for(unsigned x = 0; x < rows; ++x) { - toggle_panel->set_row_grow_factor(x, grid->row_grow_factor[x]); - for(unsigned y = 0; y < cols; ++y) { - - if(x == 0) { - toggle_panel->set_col_grow_factor(y, grid->col_grow_factor[y]); - } - - twidget* widget = grid->widgets[x * cols + y]->build(); - toggle_panel->set_child(widget, x, y, grid->flags[x * cols + y], grid->border_size[x * cols + y]); - } - } - + toggle_panel->init_grid(grid); return toggle_panel; } diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index f53aa4ee249..5b2cc84ac36 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -147,5 +147,15 @@ bool tcontainer_::disable_easy_close() const return tcontrol::disable_easy_close() && grid_.disable_easy_close(); } +void tcontainer_::init_grid( + const boost::intrusive_ptr& grid_builder) +{ + log_scope2(log_gui_general, "tcontainer: Building initial grid."); + + assert(initial_grid().get_rows() == 0 && initial_grid().get_cols() == 0); + + grid_builder->build(&initial_grid()); +} + } // namespace gui2 diff --git a/src/gui/widgets/container.hpp b/src/gui/widgets/container.hpp index 9696f0b998b..a248eea642d 100644 --- a/src/gui/widgets/container.hpp +++ b/src/gui/widgets/container.hpp @@ -146,6 +146,16 @@ public: /** Inherited from tcontrol. */ bool disable_easy_close() const; + /** + * Initializes and builds the grid. + * + * This function should only be called upon an empty grid. This grid is + * returned by initial_grid(); + * + * @grid_builder The builder for the grid. + */ + void init_grid(const boost::intrusive_ptr& grid_builder); + /***** **** ***** ***** wrappers to the grid **** ********* *****/ tgrid::iterator begin() { return grid_.begin(); } @@ -184,6 +194,13 @@ private: /** The grid which holds the child objects. */ tgrid grid_; + /** + * Returns the grid to initialize while building. + * + * @todo Evaluate whether this function is overridden if not remove. + */ + virtual tgrid& initial_grid() { return grid_; } + /** Returns the space used by the border. */ virtual tpoint border_space() const { return tpoint(0, 0); }