Add support for a grid in a window definition.
This allows to add scrollbars to a window which in turn could avoid resize failures. (Support for the latter hasn't been added yet.)
This commit is contained in:
parent
66cf5212ae
commit
78d25d7d6c
5 changed files with 83 additions and 3 deletions
|
@ -149,7 +149,17 @@ twindow* build(CVideo& video, const std::string& type)
|
|||
|
||||
window->set_easy_close(definition->easy_close);
|
||||
|
||||
window->init_grid(definition->grid);
|
||||
boost::intrusive_ptr<const twindow_definition::tresolution> conf =
|
||||
boost::dynamic_pointer_cast<
|
||||
const twindow_definition::tresolution>(window->config());
|
||||
assert(conf);
|
||||
|
||||
if(conf->grid) {
|
||||
window->init_grid(conf->grid);
|
||||
window->finalize(definition->grid);
|
||||
} else {
|
||||
window->init_grid(definition->grid);
|
||||
}
|
||||
|
||||
window->add_to_keyboard_chain(window);
|
||||
|
||||
|
|
|
@ -1366,7 +1366,7 @@ tvertical_scrollbar_definition::tresolution::tresolution(const config& cfg) :
|
|||
}
|
||||
|
||||
twindow_definition::twindow_definition(const config& cfg) :
|
||||
tpanel_definition(cfg)
|
||||
tcontrol_definition(cfg)
|
||||
{
|
||||
/*WIKI
|
||||
* @page = GUIWidgetDefinitionWML
|
||||
|
@ -1380,6 +1380,21 @@ twindow_definition::twindow_definition(const config& cfg) :
|
|||
*/
|
||||
|
||||
DBG_GUI_P << "Parsing window " << id << '\n';
|
||||
|
||||
load_resolutions<tresolution>(cfg);
|
||||
}
|
||||
|
||||
twindow_definition::tresolution::tresolution(const config& cfg)
|
||||
: tpanel_definition::tresolution(cfg)
|
||||
, grid(NULL)
|
||||
{
|
||||
const config &child = cfg.child("grid");
|
||||
// VALIDATE(child, _("No grid defined."));
|
||||
|
||||
/** @todo Evaluate whether the grid should become mandatory. */
|
||||
if(child) {
|
||||
grid = new tbuilder_grid(child);
|
||||
}
|
||||
}
|
||||
|
||||
tresolution_definition_ptr get_control(
|
||||
|
|
|
@ -421,9 +421,18 @@ struct tvertical_scrollbar_definition : public tcontrol_definition
|
|||
};
|
||||
};
|
||||
|
||||
struct twindow_definition : public tpanel_definition
|
||||
struct twindow_definition
|
||||
: public tcontrol_definition
|
||||
{
|
||||
twindow_definition(const config& cfg);
|
||||
|
||||
struct tresolution
|
||||
: public tpanel_definition::tresolution
|
||||
{
|
||||
tresolution(const config& cfg);
|
||||
|
||||
tbuilder_grid_ptr grid;
|
||||
};
|
||||
};
|
||||
|
||||
struct tgui_definition
|
||||
|
|
|
@ -925,6 +925,44 @@ void twindow::draw(surface& /*surf*/, const bool /*force*/,
|
|||
assert(false);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
/**
|
||||
* Swaps an item in a grid for another one.*/
|
||||
void swap_grid(tgrid* grid,
|
||||
tgrid* content_grid, twidget* widget, const std::string& id)
|
||||
{
|
||||
assert(content_grid);
|
||||
assert(widget);
|
||||
|
||||
// Make sure the new child has same id.
|
||||
widget->set_id(id);
|
||||
|
||||
// Get the container containing the wanted widget.
|
||||
tgrid* parent_grid = NULL;
|
||||
if(grid) {
|
||||
parent_grid = NEW_find_widget<tgrid>(grid, id, false, false);
|
||||
}
|
||||
if(!parent_grid) {
|
||||
parent_grid = NEW_find_widget<tgrid>(content_grid, id, true, false);
|
||||
}
|
||||
parent_grid = dynamic_cast<tgrid*>(parent_grid->parent());
|
||||
assert(parent_grid);
|
||||
|
||||
// Replace the child.
|
||||
widget = parent_grid->swap_child(id, widget, false);
|
||||
assert(widget);
|
||||
|
||||
delete widget;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void twindow::finalize(const boost::intrusive_ptr<tbuilder_grid>& content_grid)
|
||||
{
|
||||
swap_grid(NULL, &grid(), content_grid->build(), "_content_grid");
|
||||
}
|
||||
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
|
||||
void twindow::generate_dot_file(const std::string& generator,
|
||||
|
|
|
@ -52,6 +52,7 @@ class twindow
|
|||
, public cursor::setter
|
||||
{
|
||||
friend class tdebug_layout_graph;
|
||||
friend twindow* build(CVideo&, const std::string&);
|
||||
friend struct twindow_implementation;
|
||||
|
||||
// Wants to use layout().
|
||||
|
@ -557,6 +558,13 @@ private:
|
|||
*/
|
||||
boost::function<void ()> event_loop_pre_cb_;
|
||||
|
||||
/**
|
||||
* Finishes the initialization of the grid.
|
||||
*
|
||||
* @param content_grid The new contents for the content grid.
|
||||
*/
|
||||
void finalize(const boost::intrusive_ptr<tbuilder_grid>& content_grid);
|
||||
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
tdebug_layout_graph* debug_layout_;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue