Add a new instance dummy widget.
This widget is used to postpone instantiation of a widget. This will be used in the new matrix widget where the definition needs a widget which will only be available when the matrix widget is instantiated in a window. The code is used to experiment with a different approach of the implementation of a listbox.
This commit is contained in:
parent
b2a8da1f0e
commit
83b510cb16
16 changed files with 221 additions and 7 deletions
|
@ -1399,6 +1399,12 @@
|
|||
max="-1"
|
||||
super="generic/widget_instance"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="instance"
|
||||
min="0"
|
||||
max="-1"
|
||||
super="generic/widget_instance"
|
||||
[/tag]
|
||||
[tag]
|
||||
name="label"
|
||||
min="0"
|
||||
|
|
|
@ -47,6 +47,7 @@ src/gui/auxiliary/window_builder/helper.cpp
|
|||
src/gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
src/gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
src/gui/auxiliary/window_builder/image.cpp
|
||||
src/gui/auxiliary/window_builder/instance.cpp
|
||||
src/gui/auxiliary/window_builder/label.cpp
|
||||
src/gui/auxiliary/window_builder/listbox.cpp
|
||||
src/gui/auxiliary/window_builder/minimap.cpp
|
||||
|
|
|
@ -454,6 +454,7 @@ set(wesnoth-main_SRC
|
|||
gui/auxiliary/window_builder/helper.cpp
|
||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/instance.cpp
|
||||
gui/auxiliary/window_builder/image.cpp
|
||||
gui/auxiliary/window_builder/label.cpp
|
||||
gui/auxiliary/window_builder/listbox.cpp
|
||||
|
|
|
@ -298,6 +298,7 @@ wesnoth_sources = Split("""
|
|||
gui/auxiliary/window_builder/helper.cpp
|
||||
gui/auxiliary/window_builder/horizontal_listbox.cpp
|
||||
gui/auxiliary/window_builder/horizontal_scrollbar.cpp
|
||||
gui/auxiliary/window_builder/instance.cpp
|
||||
gui/auxiliary/window_builder/image.cpp
|
||||
gui/auxiliary/window_builder/label.cpp
|
||||
gui/auxiliary/window_builder/listbox.cpp
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "gui/auxiliary/window_builder/password_box.hpp"
|
||||
#include "gui/auxiliary/window_builder/viewport.hpp"
|
||||
#endif
|
||||
#include "gui/auxiliary/window_builder/instance.hpp"
|
||||
#include "gui/widgets/settings.hpp"
|
||||
#include "gui/widgets/window.hpp"
|
||||
#include "formula_string_utils.hpp"
|
||||
|
@ -173,6 +174,10 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
return new tbuilder_grid(c);
|
||||
}
|
||||
|
||||
if(const config &instance = cfg.child("instance")) {
|
||||
return new implementation::tbuilder_instance(instance);
|
||||
}
|
||||
|
||||
if(const config& pane = cfg.child("pane")) {
|
||||
return new implementation::tbuilder_pane(pane);
|
||||
}
|
||||
|
@ -180,6 +185,7 @@ tbuilder_widget_ptr create_builder_widget(const config& cfg)
|
|||
if(const config& viewport = cfg.child("viewport")) {
|
||||
return new implementation::tbuilder_viewport(viewport);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is rather odd, when commented out the classes no longer seem to be in
|
||||
* the executable, no real idea why, except maybe of an overzealous optimizer
|
||||
|
@ -545,6 +551,13 @@ tgrid* tbuilder_grid::build() const
|
|||
return build(new tgrid());
|
||||
}
|
||||
|
||||
twidget* tbuilder_grid::build(const treplacements& replacements) const
|
||||
{
|
||||
tgrid* result = new tgrid();
|
||||
build(*result, replacements);
|
||||
return result;
|
||||
}
|
||||
|
||||
tgrid* tbuilder_grid::build (tgrid* grid) const
|
||||
{
|
||||
grid->set_id(id);
|
||||
|
@ -575,6 +588,39 @@ tgrid* tbuilder_grid::build (tgrid* grid) const
|
|||
return grid;
|
||||
}
|
||||
|
||||
void tbuilder_grid::build(tgrid& grid, const treplacements& replacements) const
|
||||
{
|
||||
grid.set_id(id);
|
||||
grid.set_linked_group(linked_group);
|
||||
grid.set_rows_cols(rows, cols);
|
||||
|
||||
log_scope2(log_gui_general, "Window builder: building grid");
|
||||
|
||||
DBG_GUI_G << "Window builder: grid '" << id
|
||||
<< "' has " << rows << " rows and "
|
||||
<< cols << " columns.\n";
|
||||
|
||||
for(unsigned x = 0; x < rows; ++x) {
|
||||
grid.set_row_grow_factor(x, row_grow_factor[x]);
|
||||
for(unsigned y = 0; y < cols; ++y) {
|
||||
|
||||
if(x == 0) {
|
||||
grid.set_column_grow_factor(y, col_grow_factor[y]);
|
||||
}
|
||||
|
||||
DBG_GUI_G << "Window builder: adding child at "
|
||||
<< x << ',' << y << ".\n";
|
||||
|
||||
grid.set_child(
|
||||
widgets[x * cols + y]->build(replacements)
|
||||
, x
|
||||
, y
|
||||
, flags[x * cols + y]
|
||||
, border_size[x * cols + y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
/*WIKI
|
||||
* @page = GUIToolkitWML
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -46,12 +47,28 @@ struct tbuilder_widget
|
|||
: public reference_counted_object
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* The replacements type is used to define replacement types.
|
||||
*
|
||||
* Certain widgets need to build a part of themselves upon instantiation
|
||||
* but at the time of the definition it's not yet known what exactly. By
|
||||
* using and `[instance]' widget this decision can be postponed until
|
||||
* instantiation.
|
||||
*/
|
||||
typedef std::map<
|
||||
std::string
|
||||
, boost::intrusive_ptr<tbuilder_widget>
|
||||
> treplacements;
|
||||
|
||||
explicit tbuilder_widget(const config& cfg);
|
||||
|
||||
virtual ~tbuilder_widget() {}
|
||||
|
||||
virtual twidget* build() const = 0;
|
||||
|
||||
virtual twidget* build(const treplacements& replacements) const = 0;
|
||||
|
||||
/** Parameters for the widget. */
|
||||
std::string id;
|
||||
std::string linked_group;
|
||||
|
@ -129,7 +146,11 @@ public:
|
|||
std::vector<tbuilder_widget_ptr> widgets;
|
||||
|
||||
tgrid* build() const;
|
||||
twidget* build(const treplacements& replacements) const;
|
||||
|
||||
|
||||
tgrid* build(tgrid* grid) const;
|
||||
void build(tgrid& grid, const treplacements& replacements) const;
|
||||
};
|
||||
|
||||
typedef boost::intrusive_ptr<tbuilder_grid> tbuilder_grid_ptr;
|
||||
|
|
|
@ -67,6 +67,11 @@ void tbuilder_control::init_control(tcontrol* control) const
|
|||
#endif
|
||||
}
|
||||
|
||||
twidget* tbuilder_control::build(const treplacements& /*replacements*/) const
|
||||
{
|
||||
return build();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -31,6 +31,10 @@ public:
|
|||
|
||||
tbuilder_control(const config& cfg);
|
||||
|
||||
using tbuilder_widget::build;
|
||||
|
||||
twidget* build(const treplacements& replacements) const;
|
||||
|
||||
/** @deprecated The control can initalise itself. */
|
||||
void init_control(tcontrol* control) const;
|
||||
|
||||
|
|
59
src/gui/auxiliary/window_builder/instance.cpp
Normal file
59
src/gui/auxiliary/window_builder/instance.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2012 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/window_builder/instance.hpp"
|
||||
|
||||
#include "gui/auxiliary/window_builder/spacer.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
tbuilder_instance::tbuilder_instance(const config& cfg)
|
||||
: tbuilder_widget(cfg)
|
||||
, configuration(cfg)
|
||||
{
|
||||
}
|
||||
|
||||
twidget* tbuilder_instance::build() const
|
||||
{
|
||||
return build(treplacements());
|
||||
}
|
||||
|
||||
twidget* tbuilder_instance::build(const treplacements& replacements) const
|
||||
{
|
||||
const treplacements::const_iterator itor = replacements.find(id);
|
||||
if(itor != replacements.end()) {
|
||||
return itor->second->build();
|
||||
} else {
|
||||
implementation::tbuilder_spacer builder(configuration);
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
/*WIKI
|
||||
* @page = GUIWidgetInstanceWML
|
||||
* @order = 2_instance
|
||||
* @begin{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
* @begin{tag}{name="instance"}{min=0}{max=-1}{super="generic/widget_instance"}
|
||||
* @end{tag}{name="instance"}
|
||||
* @end{parent}{name="gui/window/resolution/grid/row/column/"}
|
||||
*/
|
47
src/gui/auxiliary/window_builder/instance.hpp
Normal file
47
src/gui/auxiliary/window_builder/instance.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2012 by Mark de Wever <koraq@xs4all.nl>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GUI_AUXILIARY_WINDOW_BUILDER_INSTANCE_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_INSTANCE_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
namespace implementation {
|
||||
|
||||
struct tbuilder_instance
|
||||
: public tbuilder_widget
|
||||
{
|
||||
explicit tbuilder_instance(const config& cfg);
|
||||
|
||||
twidget* build() const;
|
||||
|
||||
twidget* build(const treplacements& replacements) const;
|
||||
|
||||
/**
|
||||
* Holds a copy of the cfg parameter in the constructor.
|
||||
*
|
||||
* This is used when instantiating a spacer, it can still use the
|
||||
* parameters orginally sent.
|
||||
*/
|
||||
config configuration;
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
|
@ -34,6 +34,11 @@ tbuilder_pane::tbuilder_pane(const config& cfg)
|
|||
}
|
||||
|
||||
tpane* tbuilder_pane::build() const
|
||||
{
|
||||
return build(treplacements());
|
||||
}
|
||||
|
||||
tpane* tbuilder_pane::build(const treplacements& /*replacements*/) const
|
||||
{
|
||||
return tpane::build(*this);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ struct tbuilder_pane
|
|||
|
||||
tpane* build() const;
|
||||
|
||||
tpane* build(const treplacements& replacements) const;
|
||||
|
||||
tplacer_::tgrow_direction grow_direction;
|
||||
|
||||
unsigned parallel_items;
|
||||
|
|
|
@ -31,7 +31,12 @@ tbuilder_viewport::tbuilder_viewport(const config& cfg)
|
|||
|
||||
twidget* tbuilder_viewport::build() const
|
||||
{
|
||||
return tviewport::build(*this);
|
||||
return build(treplacements());
|
||||
}
|
||||
|
||||
twidget* tbuilder_viewport::build(const treplacements& replacements) const
|
||||
{
|
||||
return tviewport::build(*this, replacements);
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
|
|
@ -29,6 +29,8 @@ struct tbuilder_viewport
|
|||
|
||||
twidget* build() const;
|
||||
|
||||
twidget* build(const treplacements& replacements) const;
|
||||
|
||||
tbuilder_widget_ptr widget;
|
||||
|
||||
};
|
||||
|
|
|
@ -90,9 +90,11 @@ tviewport::tviewport(twidget& widget)
|
|||
widget_.set_parent(this);
|
||||
}
|
||||
|
||||
tviewport::tviewport(const implementation::tbuilder_viewport& builder)
|
||||
tviewport::tviewport(
|
||||
const implementation::tbuilder_viewport& builder
|
||||
, const tbuilder_widget::treplacements& replacements)
|
||||
: twidget(builder)
|
||||
, widget_(*builder.widget->build())
|
||||
, widget_(*builder.widget->build(replacements))
|
||||
, owns_widget_(true)
|
||||
{
|
||||
widget_.set_parent(this);
|
||||
|
@ -105,9 +107,11 @@ tviewport::~tviewport()
|
|||
}
|
||||
}
|
||||
|
||||
tviewport* tviewport::build(const implementation::tbuilder_viewport& builder)
|
||||
tviewport* tviewport::build(
|
||||
const implementation::tbuilder_viewport& builder
|
||||
, const tbuilder_widget::treplacements& replacements)
|
||||
{
|
||||
return new tviewport(builder);
|
||||
return new tviewport(builder, replacements);
|
||||
}
|
||||
|
||||
void tviewport::place(const tpoint& origin, const tpoint& size)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef GUI_WIDGETS_VIEWPORT_HPP_INCLUDED
|
||||
#define GUI_WIDGETS_VIEWPORT_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
#include "gui/widgets/widget.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
@ -37,11 +38,15 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
explicit tviewport(const implementation::tbuilder_viewport& builder);
|
||||
tviewport(
|
||||
const implementation::tbuilder_viewport& builder
|
||||
, const tbuilder_widget::treplacements& replacements);
|
||||
|
||||
public:
|
||||
|
||||
static tviewport* build(const implementation::tbuilder_viewport& builder);
|
||||
static tviewport* build(
|
||||
const implementation::tbuilder_viewport& builder
|
||||
, const tbuilder_widget::treplacements& replacements);
|
||||
|
||||
~tviewport();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue