Merge branch 'gui2_widget_ptr_init_refactor'

This commit is contained in:
Charles Dang 2018-06-08 19:17:48 +11:00
commit 58d3cad315
89 changed files with 489 additions and 353 deletions

View file

@ -57,10 +57,16 @@
*
* "Calls" REGISTER_WIDGET3(id_definition, id, nullptr)
*/
#define REGISTER_WIDGET(id) REGISTER_WIDGET3(id##_definition, id, nullptr) \
#define REGISTER_WIDGET(id) \
REGISTER_WIDGET3(id##_definition, id, nullptr) \
\
const std::string& id::get_control_type() const \
const std::string& id::type() \
{ \
static const std::string result(#id); \
return result; \
} \
\
const std::string& id::get_control_type() const \
{ \
return id::type(); \
}

View file

@ -50,7 +50,7 @@ window_ptr_t build_window_impl(const builder_window::window_resolution* definiti
{
// We set the values from the definition since we can only determine the
// best size (if needed) after all widgets have been placed.
window_ptr_t win = std::make_unique<window>(definition);
auto win = std::make_unique<window>(definition);
assert(win);
for(const auto& lg : definition->linked_groups) {
@ -134,7 +134,7 @@ builder_widget_ptr create_widget_builder(const config& cfg)
FAIL("Unknown widget type " + cfg.ordered_begin()->key);
}
widget* build_single_widget_instance_helper(const std::string& type, const config& cfg)
widget_ptr build_single_widget(const std::string& type, const config& cfg)
{
const auto& iter = widget_builder_lookup().find(type);
VALIDATE(iter != widget_builder_lookup().end(), "Invalid widget type '" + type + "'");
@ -438,49 +438,21 @@ builder_grid::builder_grid(const config& cfg)
DBG_GUI_P << "Window builder: grid has " << rows << " rows and " << cols << " columns.\n";
}
grid* builder_grid::build() const
widget_ptr builder_grid::build() const
{
return build(new grid());
auto result = std::make_shared<grid>();
build(*result);
return result;
}
widget* builder_grid::build(const replacements_map& replacements) const
widget_ptr builder_grid::build(const replacements_map& replacements) const
{
grid* result = new grid();
auto result = std::make_shared<grid>();
build(*result, replacements);
return result;
}
grid* builder_grid::build(grid* grid) 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";
const unsigned int i = x * cols + y;
widget* widget = widgets[i]->build();
grid->set_child(widget, x, y, flags[i], border_size[i]);
}
}
return grid;
}
void builder_grid::build(grid& grid, const replacements_map& replacements) const
void builder_grid::build(grid& grid, optional_replacements_t replacements) const
{
grid.set_id(id);
grid.set_linked_group(linked_group);
@ -501,7 +473,14 @@ void builder_grid::build(grid& grid, const replacements_map& replacements) const
DBG_GUI_G << "Window builder: adding child at " << x << ',' << y << ".\n";
const unsigned int i = x * cols + y;
grid.set_child(widgets[i]->build(replacements), x, y, flags[i], border_size[i]);
if(replacements != boost::none) {
auto widget = widgets[i]->build(replacements.get());
grid.set_child(widget, x, y, flags[i], border_size[i]);
} else {
auto widget = widgets[i]->build();
grid.set_child(widget, x, y, flags[i], border_size[i]);
}
}
}
}

View file

@ -20,6 +20,8 @@
#include "gui/widgets/grid.hpp"
#include "utils/functional.hpp"
#include <boost/optional.hpp>
#include <memory>
class config;
@ -31,7 +33,6 @@ class window;
/** Contains the info needed to instantiate a widget. */
struct builder_widget
{
public:
/**
* The replacements type is used to define replacement types.
*
@ -40,7 +41,13 @@ public:
* using and `[instance]' widget this decision can be postponed until
* instantiation.
*/
typedef std::map<std::string, std::shared_ptr<builder_widget>> replacements_map;
using replacements_map = std::map<std::string, std::shared_ptr<builder_widget>>;
/**
* @todo: evaluate whether to combine the two @ref build() functions with this
* as the sole parameter.
*/
using optional_replacements_t = boost::optional<const replacements_map&>;
explicit builder_widget(const config& cfg);
@ -48,9 +55,9 @@ public:
{
}
virtual widget* build() const = 0;
virtual widget_ptr build() const = 0;
virtual widget* build(const replacements_map& replacements) const = 0;
virtual widget_ptr build(const replacements_map& replacements) const = 0;
/** Parameters for the widget. */
std::string id;
@ -60,8 +67,8 @@ public:
color_t debug_border_color;
};
typedef std::shared_ptr<builder_widget> builder_widget_ptr;
typedef std::shared_ptr<const builder_widget> builder_widget_const_ptr;
using builder_widget_ptr = std::shared_ptr<builder_widget>;
using builder_widget_const_ptr = std::shared_ptr<const builder_widget>;
/**
* Create a widget builder.
@ -75,34 +82,42 @@ typedef std::shared_ptr<const builder_widget> builder_widget_const_ptr;
*/
builder_widget_ptr create_widget_builder(const config& cfg);
/**
* Helper function to implement @ref build_single_widget_instance. This keeps the main
* logic in the implementation despite said function being a template and therefor
* needing to be fully implemented in the declaration.
*/
widget* build_single_widget_instance_helper(const std::string& type, const config& cfg);
/**
* Builds a single widget instance of the given type with the specified attributes.
*
* This should be used in place of creating a widget object directly, as it
* allows the widget-specific builder code to be executed.
*
* @tparam T The final widget type. The widget pointer will be
* cast to this.
* This is equivalent to calling @c build() on the result of @ref create_widget_builder.
*
* @param type String ID of the widget type.
* @param cfg Data config to pass to the widget's builder.
*
* @returns A shared_ptr of the base widget type containing
* the newly built widget.
*/
widget_ptr build_single_widget(const std::string& type, const config& cfg);
/**
* Convenience wrapper around @ref build_single_widget that casts the resulting
* widget pointer to the given type.
*
* @tparam T The final widget type. The widget pointer will be
* cast to this.
*
* @param cfg Data config to pass to the widget's builder.
*
* @returns A shared_ptr of the given type containing the
* newly build widget.
*/
template<typename T>
T* build_single_widget_instance(const std::string& type, const config& cfg = config())
std::shared_ptr<T> build_single_widget_and_cast_to(const config& cfg = {})
{
return dynamic_cast<T*>(build_single_widget_instance_helper(type, cfg));
return std::dynamic_pointer_cast<T>(build_single_widget(T::type(), cfg));
}
struct builder_grid : public builder_widget
{
public:
explicit builder_grid(const config& cfg);
unsigned rows;
@ -121,15 +136,18 @@ public:
/** The widgets per grid cell. */
std::vector<builder_widget_ptr> widgets;
grid* build() const;
widget* build(const replacements_map& replacements) const;
/** Inherited from @ref builder_widget. */
virtual widget_ptr build() const override;
grid* build(grid* grid) const;
void build(grid& grid, const replacements_map& replacements) const;
/** Inherited from @ref builder_widget. */
virtual widget_ptr build(const replacements_map& replacements) const override;
void build(grid& grid, optional_replacements_t replacements = boost::none) const;
};
typedef std::shared_ptr<builder_grid> builder_grid_ptr;
typedef std::shared_ptr<const builder_grid> builder_grid_const_ptr;
using builder_grid_ptr = std::shared_ptr<builder_grid>;
using builder_grid_const_ptr = std::shared_ptr<const builder_grid>;
using builder_grid_map = std::map<std::string, builder_grid_const_ptr>;
class builder_window
{
@ -144,7 +162,6 @@ public:
struct window_resolution
{
public:
explicit window_resolution(const config& cfg);
unsigned window_width;

View file

@ -29,12 +29,12 @@ builder_instance::builder_instance(const config& cfg)
{
}
widget* builder_instance::build() const
widget_ptr builder_instance::build() const
{
return build(replacements_map());
}
widget* builder_instance::build(const replacements_map& replacements) const
widget_ptr builder_instance::build(const replacements_map& replacements) const
{
const replacements_map::const_iterator itor = replacements.find(id);
if(itor != replacements.end()) {

View file

@ -28,9 +28,9 @@ struct builder_instance : public builder_widget
{
explicit builder_instance(const config& cfg);
widget* build() const;
virtual widget_ptr build() const override;
widget* build(const replacements_map& replacements) const;
virtual widget_ptr build(const replacements_map& replacements) const override;
/**
* Holds a copy of the cfg parameter in the constructor.

View file

@ -137,17 +137,17 @@ void drop_down_menu::pre_show(window& window)
find_widget<toggle_panel>(&new_row, "panel", false).set_tooltip(entry["tooltip"]);
if(entry.has_attribute("image")) {
image* img = build_single_widget_instance<image>("image");
auto img = build_single_widget_and_cast_to<image>();
img->set_label(entry["image"]);
grid* mi_grid = dynamic_cast<grid*>(new_row.find("menu_item", false));
if(mi_grid) {
mi_grid->swap_child("label", img, false);
mi_grid->swap_child("label", std::static_pointer_cast<widget>(img), false);
}
}
if(entry.has_attribute("checkbox")) {
toggle_button* checkbox = build_single_widget_instance<toggle_button>("toggle_button");
auto checkbox = build_single_widget_and_cast_to<toggle_button>();
checkbox->set_id("checkbox");
checkbox->set_value_bool(entry["checkbox"].to_bool(false));
@ -157,7 +157,7 @@ void drop_down_menu::pre_show(window& window)
grid* mi_grid = dynamic_cast<grid*>(new_row.find("menu_item", false));
if(mi_grid) {
mi_grid->swap_child("icon", checkbox, false);
mi_grid->swap_child("icon", std::static_pointer_cast<widget>(checkbox), false);
}
}
}

View file

@ -646,7 +646,7 @@ void preferences_dialog::post_build(window& window)
}
case ADVANCED_PREF_TYPE::SLIDER: {
slider* setter_widget = build_single_widget_instance<slider>("slider", config {"definition", "minimal"});
auto setter_widget = build_single_widget_and_cast_to<slider>(config {"definition", "minimal"});
setter_widget->set_id("setter");
// Maximum must be set first or this will assert
setter_widget->set_value_range(option["min"].to_int(), option["max"].to_int());
@ -693,7 +693,7 @@ void preferences_dialog::post_build(window& window)
selected = 0;
}
menu_button* setter_widget = build_single_widget_instance<menu_button>("menu_button");
auto setter_widget = build_single_widget_and_cast_to<menu_button>();
setter_widget->set_id("setter");
details_grid.swap_child("setter", setter_widget, true);
@ -718,7 +718,7 @@ void preferences_dialog::post_build(window& window)
case ADVANCED_PREF_TYPE::SPECIAL: {
//main_grid->remove_child("setter");
image* value_widget = build_single_widget_instance<image>("image");
auto value_widget = build_single_widget_and_cast_to<image>();
value_widget->set_label("icons/arrows/arrows_blank_right_25.png~CROP(3,3,18,18)");
main_grid->swap_child("value", value_widget, true);

View file

@ -50,7 +50,7 @@ const unsigned CONTROL_STACK_LAYER_PUBLISH = 2;
REGISTER_WIDGET(addon_list)
addon_list::addon_list(const implementation::builder_addon_list& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, addon_vector_()
, install_status_visibility_(visibility::visible)
, install_buttons_visibility_(visibility::invisible)
@ -461,9 +461,9 @@ builder_addon_list::builder_addon_list(const config& cfg)
}
}
widget* builder_addon_list::build() const
widget_ptr builder_addon_list::build() const
{
addon_list* widget = new addon_list(*this);
auto widget = std::make_shared<addon_list>(*this);
DBG_GUI_G << "Window builder: placed add-on list '" << id <<
"' with definition '" << definition << "'.\n";

View file

@ -177,6 +177,11 @@ private:
/** Needed because otherwise the add-on with the first ID would be initially selected. */
void select_first_addon();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -209,7 +214,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
widget::visibility install_status_visibility_;

View file

@ -41,7 +41,7 @@ namespace gui2
REGISTER_WIDGET(button)
button::button(const implementation::builder_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, clickable_item()
, state_(ENABLED)
, retval_(retval::NONE)
@ -241,9 +241,9 @@ builder_button::builder_button(const config& cfg)
{
}
widget* builder_button::build() const
widget_ptr builder_button::build() const
{
button* widget = new button(*this);
auto widget = std::make_shared<button>(*this);
widget->set_retval(get_retval(retval_id_, retval_, id));

View file

@ -97,6 +97,11 @@ private:
*/
int retval_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -142,7 +147,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
std::string retval_id_;

View file

@ -55,7 +55,7 @@ namespace gui2
REGISTER_WIDGET(chatbox)
chatbox::chatbox(const implementation::builder_chatbox& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, roomlistbox_(nullptr)
, chat_log_container_(nullptr)
, chat_input_(nullptr)
@ -810,9 +810,9 @@ builder_chatbox::builder_chatbox(const config& cfg)
{
}
widget* builder_chatbox::build() const
widget_ptr builder_chatbox::build() const
{
chatbox* widget = new chatbox(*this);
auto widget = std::make_shared<chatbox>(*this);
DBG_GUI_G << "Window builder: placed unit preview pane '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -150,6 +150,11 @@ private:
std::map<std::string, chatroom_log>* log_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -283,7 +288,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
};

View file

@ -257,7 +257,7 @@ container_base::init_grid(const std::shared_ptr<builder_grid>& grid_builder)
assert(grid_.get_rows() == 0 && grid_.get_cols() == 0);
grid_builder->build(&grid_);
grid_builder->build(grid_);
}
point container_base::border_space() const

View file

@ -193,7 +193,7 @@ public:
grid_.set_rows_cols(rows, cols);
}
void set_child(widget* widget,
void set_child(widget_ptr widget,
const unsigned row,
const unsigned col,
const unsigned flags,

View file

@ -32,7 +32,7 @@ namespace gui2
REGISTER_WIDGET(drawing)
drawing::drawing(const implementation::builder_drawing& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, best_size_(0, 0)
{
}
@ -175,9 +175,9 @@ builder_drawing::builder_drawing(const config& cfg)
assert(!draw.empty());
}
widget* builder_drawing::build() const
widget_ptr builder_drawing::build() const
{
drawing* widget = new drawing(*this);
auto widget = std::make_shared<drawing>(*this);
const wfl::map_formula_callable& size = get_screen_size_variables();

View file

@ -103,6 +103,11 @@ private:
/** When we're used as a fixed size item, this holds the best size. */
point best_size_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -130,7 +135,7 @@ struct builder_drawing : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
/** The width of the widget. */
typed_formula<unsigned> width;

View file

@ -1108,16 +1108,16 @@ static_assert(false, "GUI2/Generator: GENERATE_PLACEMENT already defined!");
#define GENERATE_PLACEMENT \
switch(placement) { \
case generator_base::horizontal_list: \
result = new generator<minimum, maximum, policy::placement::horizontal_list, select_action>; \
result = std::make_shared<generator<minimum, maximum, policy::placement::horizontal_list, select_action>>(); \
break; \
case generator_base::vertical_list: \
result = new generator<minimum, maximum, policy::placement::vertical_list, select_action>; \
result = std::make_shared<generator<minimum, maximum, policy::placement::vertical_list, select_action>>(); \
break; \
case generator_base::table: \
result = new generator<minimum, maximum, policy::placement::table, select_action>; \
result = std::make_shared<generator<minimum, maximum, policy::placement::table, select_action>>(); \
break; \
case generator_base::independent: \
result = new generator<minimum, maximum, policy::placement::independent, select_action>; \
result = std::make_shared<generator<minimum, maximum, policy::placement::independent, select_action>>(); \
break; \
default: \
assert(false); \
@ -1163,10 +1163,10 @@ static_assert(false, "GUI2/Generator: GENERATE_BODY already defined!");
}
#endif
generator_base* generator_base::build(
generator_ptr generator_base::build(
const bool has_minimum, const bool has_maximum, const placement placement, const bool select)
{
generator_base* result = nullptr;
generator_ptr result = nullptr;
GENERATE_BODY;
return result;
}

View file

@ -26,8 +26,11 @@ namespace gui2
struct builder_grid;
typedef std::shared_ptr<const builder_grid> builder_grid_const_ptr;
class generator_base;
class grid;
using generator_ptr = std::shared_ptr<generator_base>;
/**
* Abstract base class for the generator.
*
@ -59,7 +62,7 @@ public:
* @param has_minimum Does one item need to be selected.
* @param has_maximum Is one the maximum number of items that can
* be selected?
* @param placement The placement of the grids, see tplacement
* @param placement The placement of the grids, see placement
* for more info.
* @param select If a grid is selected, what should happen?
* If true the grid is selected, if false the
@ -68,7 +71,7 @@ public:
* @returns A pointer to a new object. The caller gets
* ownership of the new object.
*/
static generator_base* build(const bool has_minimum,
static generator_ptr build(const bool has_minimum,
const bool has_maximum,
const placement placement,
const bool select);

View file

@ -734,7 +734,7 @@ public:
assert(index == -1 || static_cast<unsigned>(index) <= items_.size());
child* item = new child;
list_builder->build(&item->child_grid);
list_builder->build(item->child_grid);
init(&item->child_grid, item_data, callback);

View file

@ -66,7 +66,7 @@ unsigned grid::add_row(const unsigned count)
return result;
}
void grid::set_child(widget* widget,
void grid::set_child(widget_ptr widget,
const unsigned row,
const unsigned col,
const unsigned flags,
@ -89,16 +89,17 @@ void grid::set_child(widget* widget,
cell.set_flags(flags);
cell.set_border_size(border_size);
cell.set_widget(widget);
if(cell.get_widget()) {
// make sure the new child is valid before deferring
cell.get_widget()->set_parent(this);
// make sure the new child is valid before deferring
if(gui2::widget* w = cell.get_widget()) {
w->set_parent(this);
}
}
std::unique_ptr<widget> grid::swap_child(const std::string& id,
widget* w,
const bool recurse,
widget* new_parent)
widget_ptr grid::swap_child(const std::string& id,
widget_ptr w,
const bool recurse,
widget* new_parent)
{
assert(w);
@ -111,7 +112,7 @@ std::unique_ptr<widget> grid::swap_child(const std::string& id,
grid* g = dynamic_cast<grid*>(child.get_widget());
if(g) {
std::unique_ptr<widget> old = g->swap_child(id, w, true);
widget_ptr old = g->swap_child(id, w, true);
if(old) {
return old;
}
@ -122,7 +123,7 @@ std::unique_ptr<widget> grid::swap_child(const std::string& id,
}
// Free widget from cell and validate.
std::unique_ptr<widget> old = child.free_widget();
widget_ptr old = child.free_widget();
assert(old);
old->set_parent(new_parent);
@ -1086,7 +1087,7 @@ grid_implementation::cell_request_reduce_width(grid::child& child,
child.widget_->request_reduce_width(maximum_width - child.border_space().x);
}
void set_single_child(grid& grid, widget* widget)
void set_single_child(grid& grid, widget_ptr widget)
{
grid.set_rows_cols(1, 1);
grid.set_child(widget,

View file

@ -120,7 +120,7 @@ public:
* @param border_size The size of the border for the cell, how the
* border is applied depends on the flags.
*/
void set_child(widget* widget,
void set_child(widget_ptr widget,
const unsigned row,
const unsigned col,
const unsigned flags,
@ -141,8 +141,8 @@ public:
* the widget is cleared). If no widget found
* and thus not replace nullptr will returned.
*/
std::unique_ptr<widget> swap_child(const std::string& id,
widget* w,
widget_ptr swap_child(const std::string& id,
widget_ptr w,
const bool recurse,
widget* new_parent = nullptr);
@ -391,16 +391,17 @@ private:
return widget_.get();
}
void set_widget(widget* widget)
/** Acquires an owning reference to the given widget. */
void set_widget(widget_ptr widget)
{
widget_.reset(widget);
widget_ = std::move(widget);
}
/**
* Releases widget from ownership by this child and returns it in the
* form of a new unique_ptr. widget_ will be null after this is called.
* form of a new shared_ptr. widget_ will be null after this is called.
*/
std::unique_ptr<widget> free_widget()
widget_ptr free_widget()
{
return std::exchange(widget_, nullptr);
}
@ -421,7 +422,7 @@ private:
* Once the widget is assigned to the grid we own the widget and it
* will be destroyed with the grid or @ref free_widget is called.
*/
std::unique_ptr<widget> widget_;
widget_ptr widget_;
/** Returns the space needed for the border. */
point border_space() const;
@ -442,14 +443,17 @@ public:
{
return iterator(++itor_);
}
iterator operator--()
{
return iterator(--itor_);
}
widget* operator->()
{
return itor_->get_widget();
}
widget* operator*()
{
return itor_->get_widget();
@ -550,6 +554,8 @@ private:
virtual void impl_draw_children() override;
};
using grid_ptr = std::shared_ptr<grid>;
/**
* Sets the single child in a grid.
*
@ -559,6 +565,6 @@ private:
* @param grid The grid to add the child to.
* @param widget The widget to add as child to the grid.
*/
void set_single_child(grid& grid, widget* widget);
void set_single_child(grid& grid, widget_ptr widget);
} // namespace gui2

View file

@ -34,7 +34,7 @@ namespace gui2
REGISTER_WIDGET(horizontal_scrollbar)
horizontal_scrollbar::horizontal_scrollbar(const implementation::builder_horizontal_scrollbar& builder)
: scrollbar_base(builder, get_control_type())
: scrollbar_base(builder, type())
{
}
@ -214,9 +214,9 @@ builder_horizontal_scrollbar::builder_horizontal_scrollbar(const config& cfg)
{
}
widget* builder_horizontal_scrollbar::build() const
widget_ptr builder_horizontal_scrollbar::build() const
{
horizontal_scrollbar* widget = new horizontal_scrollbar(*this);
auto widget = std::make_shared<horizontal_scrollbar>(*this);
widget->finalize_setup();

View file

@ -70,6 +70,11 @@ private:
return current.x - original.x;
}
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -103,7 +108,7 @@ struct builder_horizontal_scrollbar : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -37,7 +37,7 @@ namespace gui2
REGISTER_WIDGET(image)
image::image(const implementation::builder_image& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
{
}
@ -165,9 +165,9 @@ builder_image::builder_image(const config& cfg) : builder_styled_widget(cfg)
{
}
widget* builder_image::build() const
widget_ptr builder_image::build() const
{
image* widget = new image(*this);
auto widget = std::make_shared<image>(*this);
DBG_GUI_G << "Window builder: placed image '" << id << "' with definition '"
<< definition << "'.\n";

View file

@ -93,6 +93,11 @@ private:
ENABLED,
};
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -120,7 +125,7 @@ struct builder_image : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -41,7 +41,7 @@ namespace gui2
REGISTER_WIDGET(label)
label::label(const implementation::builder_label& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, state_(ENABLED)
, can_wrap_(false)
, characters_per_line_(0)
@ -309,9 +309,9 @@ builder_label::builder_label(const config& cfg)
{
}
widget* builder_label::build() const
widget_ptr builder_label::build() const
{
label* lbl = new label(*this);
auto lbl = std::make_shared<label>(*this);
const auto conf = lbl->cast_config_to<label_definition>();
assert(conf);

View file

@ -134,6 +134,11 @@ private:
return can_shrink_;
}
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -177,7 +182,7 @@ struct builder_label : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
bool wrap;

View file

@ -271,6 +271,11 @@ private:
/** See @ref container_base::set_self_active. */
virtual void set_self_active(const bool active) override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;

View file

@ -55,7 +55,7 @@ listbox::listbox(const implementation::builder_styled_widget& builder,
const bool has_minimum,
const bool has_maximum,
const bool select)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
, generator_(generator_base::build(has_minimum, has_maximum, placement, select))
, is_horizontal_(placement == generator_base::horizontal_list)
, list_builder_(list_builder)
@ -952,7 +952,7 @@ builder_listbox::builder_listbox(const config& cfg)
}
}
widget* builder_listbox::build() const
widget_ptr builder_listbox::build() const
{
#ifdef GUI2_EXPERIMENTAL_LISTBOX
list_view* widget = new list_view(true, true, generator_base::vertical_list, true, list_builder);
@ -965,7 +965,7 @@ widget* builder_listbox::build() const
return widget;
#else
listbox* widget = new listbox(*this, generator_base::vertical_list, list_builder, has_minimum_, has_maximum_);
auto widget = std::make_shared<listbox>(*this, generator_base::vertical_list, list_builder, has_minimum_, has_maximum_);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
@ -1069,7 +1069,7 @@ builder_horizontal_listbox::builder_horizontal_listbox(const config& cfg)
}
}
widget* builder_horizontal_listbox::build() const
widget_ptr builder_horizontal_listbox::build() const
{
#ifdef GUI2_EXPERIMENTAL_LISTBOX
list_view* widget = new list_view(true, true, generator_base::horizontal_list, true, list_builder);
@ -1082,7 +1082,7 @@ widget* builder_horizontal_listbox::build() const
return widget;
#else
listbox* widget = new listbox(*this, generator_base::horizontal_list, list_builder, has_minimum_, has_maximum_);
auto widget = std::make_shared<listbox>(*this, generator_base::horizontal_list, list_builder, has_minimum_, has_maximum_);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
@ -1186,7 +1186,7 @@ builder_grid_listbox::builder_grid_listbox(const config& cfg)
}
}
widget* builder_grid_listbox::build() const
widget_ptr builder_grid_listbox::build() const
{
#ifdef GUI2_EXPERIMENTAL_LISTBOX
list_view* widget = new list_view(true, true, generator_base::grid, true, list_builder);
@ -1199,7 +1199,7 @@ widget* builder_grid_listbox::build() const
return widget;
#else
listbox* widget = new listbox(*this, generator_base::table, list_builder, has_minimum_, has_maximum_);
auto widget = std::make_shared<listbox>(*this, generator_base::table, list_builder, has_minimum_, has_maximum_);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);

View file

@ -44,6 +44,7 @@ class listbox : public scrollbar_container
friend struct implementation::builder_listbox;
friend struct implementation::builder_horizontal_listbox;
friend struct implementation::builder_grid_listbox;
friend class debug_layout_graph;
public:
@ -66,6 +67,7 @@ public:
const bool select = true);
/***** ***** ***** ***** Row handling. ***** ***** ****** *****/
/**
* When an item in the list is selected by the user we need to
* update the state. We installed a callback handler which
@ -365,7 +367,7 @@ private:
* of the scrollbar_container super class and freed when it's grid is
* freed.
*/
generator_base* generator_;
generator_ptr generator_;
const bool is_horizontal_;
@ -414,6 +416,11 @@ private:
/** Inherited from scrollbar_container. */
virtual void set_content_size(const point& origin, const point& size) override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -444,7 +451,7 @@ struct builder_listbox : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;
@ -471,7 +478,7 @@ struct builder_horizontal_listbox : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;
@ -495,7 +502,7 @@ struct builder_grid_listbox : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;

View file

@ -87,11 +87,6 @@ matrix::matrix(const implementation::builder_matrix& builder)
pane_ = find_widget<pane>(&content_, "pane", false, true);
}
matrix* matrix::build(const implementation::builder_matrix& builder)
{
return new matrix(builder);
}
unsigned
matrix::create_item(const std::map<std::string, string_map>& item_data,
const std::map<std::string, std::string>& tags)
@ -286,9 +281,9 @@ builder_matrix::builder_matrix(const config& cfg)
}
}
widget* builder_matrix::build() const
widget_ptr builder_matrix::build() const
{
return matrix::build(*this);
return std::make_shared<matrix>(*this);
}
} // namespace implementation

View file

@ -100,11 +100,8 @@ class matrix : public tbase
{
friend class debug_layout_graph;
private:
explicit matrix(const implementation::builder_matrix& builder);
public:
static matrix* build(const implementation::builder_matrix& builder);
explicit matrix(const implementation::builder_matrix& builder);
/***** ***** ***** ***** Item handling. ***** ***** ****** *****/
@ -217,6 +214,11 @@ private:
*/
pane* pane_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -247,7 +249,7 @@ struct builder_matrix : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;

View file

@ -38,7 +38,7 @@ namespace gui2
REGISTER_WIDGET(menu_button)
menu_button::menu_button(const implementation::builder_menu_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, selectable_item()
, state_(ENABLED)
, retval_(retval::NONE)
@ -280,9 +280,9 @@ builder_menu_button::builder_menu_button(const config& cfg)
}
}
widget* builder_menu_button::build() const
widget_ptr builder_menu_button::build() const
{
menu_button* widget = new menu_button(*this);
auto widget = std::make_shared<menu_button>(*this);
widget->set_retval(get_retval(retval_id_, retval_, id));
if(!options_.empty()) {

View file

@ -140,6 +140,11 @@ private:
bool keep_open_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -182,7 +187,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
std::string retval_id_;

View file

@ -49,7 +49,7 @@ namespace gui2
REGISTER_WIDGET(minimap)
minimap::minimap(const implementation::builder_minimap& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, map_data_()
, terrain_(nullptr)
, map_(nullptr)
@ -168,9 +168,9 @@ builder_minimap::builder_minimap(const config& cfg) : builder_styled_widget(cfg)
{
}
widget* builder_minimap::build() const
widget_ptr builder_minimap::build() const
{
minimap* widget = new minimap(*this);
auto widget = std::make_shared<minimap>(*this);
DBG_GUI_G << "Window builder: placed minimap '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -92,6 +92,11 @@ private:
/** See @ref widget::impl_draw_background. */
virtual void impl_draw_background() override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -119,7 +124,7 @@ struct builder_minimap : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -34,7 +34,7 @@ namespace gui2
REGISTER_WIDGET(multi_page)
multi_page::multi_page(const implementation::builder_multi_page& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, generator_(generator_base::build(true, true, generator_base::independent, false))
, page_builders_()
{
@ -280,9 +280,9 @@ builder_multi_page::builder_multi_page(const config& cfg)
}
}
widget* builder_multi_page::build() const
widget_ptr builder_multi_page::build() const
{
multi_page* widget = new multi_page(*this);
auto widget = std::make_shared<multi_page>(*this);
widget->set_page_builders(builders);

View file

@ -29,7 +29,7 @@ namespace implementation
struct builder_multi_page;
}
class generator_base;
using generator_ptr = std::shared_ptr<class generator_base>;
/** The multi page class. */
class multi_page : public container_base
@ -174,7 +174,7 @@ public:
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_page_builders(const std::map<std::string, builder_grid_const_ptr>& page_builders)
void set_page_builders(const builder_grid_map& page_builders)
{
assert(!page_builders.empty());
page_builders_ = page_builders;
@ -195,14 +195,19 @@ private:
* of the scrollbar_container super class and freed when it's grid is
* freed.
*/
generator_base* generator_;
generator_ptr generator_;
/** Contains the builder for the new items. */
std::map<std::string, builder_grid_const_ptr> page_builders_;
builder_grid_map page_builders_;
/** See @ref widget::impl_draw_background. */
virtual void impl_draw_background() override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -235,9 +240,9 @@ struct builder_multi_page : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
std::map<std::string, builder_grid_const_ptr> builders;
builder_grid_map builders;
/**
* Multi page data.

View file

@ -40,7 +40,7 @@ namespace gui2
REGISTER_WIDGET(multimenu_button)
multimenu_button::multimenu_button(const implementation::builder_multimenu_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, state_(ENABLED)
, retval_(retval::NONE)
, max_shown_(1)
@ -339,9 +339,9 @@ builder_multimenu_button::builder_multimenu_button(const config& cfg)
}
}
widget* builder_multimenu_button::build() const
widget_ptr builder_multimenu_button::build() const
{
multimenu_button* widget = new multimenu_button(*this);
auto widget = std::make_shared<multimenu_button>(*this);
widget->set_retval(get_retval(retval_id_, retval_, id));
widget->set_max_shown(max_shown_);

View file

@ -186,6 +186,11 @@ private:
void update_config_from_toggle_states();
void update_label();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -230,7 +235,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
std::string retval_id_;

View file

@ -96,7 +96,7 @@ struct pane_implementation
{
if(item.id == id) {
return item.item_grid;
return item.item_grid.get();
}
}
@ -104,19 +104,6 @@ struct pane_implementation
}
};
pane::pane(const builder_grid_ptr item_builder)
: widget()
, items_()
, item_builder_(item_builder)
, item_id_generator_(0)
, placer_(placer_base::build(placer_base::tgrow_direction::vertical, 1))
{
connect_signal<event::REQUEST_PLACEMENT>(
std::bind(
&pane::signal_handler_request_placement, this, _1, _2, _3),
event::dispatcher::back_pre_child);
}
pane::pane(const implementation::builder_pane& builder)
: widget(builder)
, items_()
@ -130,22 +117,17 @@ pane::pane(const implementation::builder_pane& builder)
event::dispatcher::back_pre_child);
}
pane* pane::build(const implementation::builder_pane& builder)
{
return new pane(builder);
}
unsigned pane::create_item(const std::map<std::string, string_map>& item_data,
const std::map<std::string, std::string>& tags)
{
item item = { item_id_generator_++, tags, item_builder_->build() };
item item { item_id_generator_++, tags, std::dynamic_pointer_cast<grid>(item_builder_->build()) };
item.item_grid->set_parent(this);
for(const auto & data : item_data)
{
styled_widget* control
= find_widget<styled_widget>(item.item_grid, data.first, false, false);
= find_widget<styled_widget>(item.item_grid.get(), data.first, false, false);
if(control) {
control->set_members(data.second);
@ -419,14 +401,14 @@ builder_pane::builder_pane(const config& cfg)
VALIDATE(parallel_items > 0, _("Need at least 1 parallel item."));
}
widget* builder_pane::build() const
widget_ptr builder_pane::build() const
{
return build(replacements_map());
}
widget* builder_pane::build(const replacements_map& /*replacements*/) const
widget_ptr builder_pane::build(const replacements_map& /*replacements*/) const
{
return pane::build(*this);
return std::make_shared<pane>(*this);
}
} // namespace implementation

View file

@ -41,27 +41,20 @@ class pane : public widget
public:
struct item
{
unsigned id;
std::map<std::string, std::string> tags;
grid* item_grid;
grid_ptr item_grid;
};
typedef std::function<bool(const item&, const item&)> compare_functor_t;
typedef std::function<bool(const item&)> filter_functor_t;
/** @deprecated Use the second overload. */
explicit pane(const builder_grid_ptr item_builder);
private:
public:
explicit pane(const implementation::builder_pane& builder);
public:
static pane* build(const implementation::builder_pane& builder);
/**
/*
* Creates a new item.
*/
unsigned create_item(const std::map<std::string, string_map>& item_data,
@ -195,9 +188,9 @@ struct builder_pane : public builder_widget
{
explicit builder_pane(const config& cfg);
widget* build() const;
virtual widget_ptr build() const override;
widget* build(const replacements_map& replacements) const;
virtual widget_ptr build(const replacements_map& replacements) const override;
placer_base::tgrow_direction grow_direction;

View file

@ -36,7 +36,7 @@ namespace gui2
REGISTER_WIDGET(panel)
panel::panel(const implementation::builder_styled_widget& builder, const std::string& control_type)
: container_base(builder, control_type.empty() ? get_control_type() : control_type)
: container_base(builder, control_type.empty() ? type() : control_type)
{
}
@ -194,9 +194,9 @@ builder_panel::builder_panel(const config& cfg)
grid = std::make_shared<builder_grid>(c);
}
widget* builder_panel::build() const
widget_ptr builder_panel::build() const
{
panel* widget = new panel(*this);
auto widget = std::make_shared<panel>(*this);
DBG_GUI_G << "Window builder: placed panel '" << id << "' with definition '"
<< definition << "'.\n";

View file

@ -58,6 +58,11 @@ private:
/** See @ref widget::impl_draw_foreground. */
virtual void impl_draw_foreground() override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -97,7 +102,7 @@ struct builder_panel : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
builder_grid_ptr grid;
};

View file

@ -101,12 +101,17 @@ void password_box::paste_selection(const bool mouse)
insert_char(text);
}
const std::string& password_box::get_control_type() const
const std::string& password_box::type() \
{
static const std::string type = "password_box";
return type;
}
const std::string& password_box::get_control_type() const
{
return type();
}
// }---------- BUILDER -----------{
namespace implementation
@ -132,9 +137,9 @@ builder_password_box::builder_password_box(const config& cfg)
{
}
widget* builder_password_box::build() const
widget_ptr builder_password_box::build() const
{
password_box* widget = new password_box(*this);
auto widget = std::make_shared<password_box>(*this);
// A password box doesn't have a label but a text.
// It also has no history.

View file

@ -60,6 +60,11 @@ private:
std::string real_value_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** See @ref styled_widget::get_control_type. */
virtual const std::string& get_control_type() const override;
};
@ -78,7 +83,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
std::string history_;

View file

@ -33,7 +33,7 @@ namespace gui2
REGISTER_WIDGET(progress_bar)
progress_bar::progress_bar(const implementation::builder_progress_bar& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, percentage_(static_cast<unsigned>(-1))
{
// Force canvas update
@ -144,9 +144,9 @@ builder_progress_bar::builder_progress_bar(const config& cfg)
{
}
widget* builder_progress_bar::build() const
widget_ptr builder_progress_bar::build() const
{
progress_bar* widget = new progress_bar(*this);
auto widget = std::make_shared<progress_bar>(*this);
DBG_GUI_G << "Window builder: placed progress bar '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -69,6 +69,11 @@ private:
/** The percentage done. */
unsigned percentage_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -97,7 +102,7 @@ struct builder_progress_bar : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -36,7 +36,7 @@ namespace gui2
REGISTER_WIDGET(repeating_button)
repeating_button::repeating_button(const implementation::builder_repeating_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, clickable_item()
, state_(ENABLED)
, repeat_timer_(0)
@ -243,9 +243,9 @@ builder_repeating_button::builder_repeating_button(const config& cfg)
{
}
widget* builder_repeating_button::build() const
widget_ptr builder_repeating_button::build() const
{
repeating_button* widget = new repeating_button(*this);
auto widget = std::make_shared<repeating_button>(*this);
DBG_GUI_G << "Window builder: placed repeating button '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -102,6 +102,11 @@ private:
/** The timer for the repeating events. */
std::size_t repeat_timer_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -142,7 +147,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -40,7 +40,7 @@ namespace gui2
REGISTER_WIDGET(scroll_label)
scroll_label::scroll_label(const implementation::builder_scroll_label& builder)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
, state_(ENABLED)
, wrap_on_(builder.wrap_on)
, text_alignment_(builder.text_alignment)
@ -269,9 +269,9 @@ builder_scroll_label::builder_scroll_label(const config& cfg)
{
}
widget* builder_scroll_label::build() const
widget_ptr builder_scroll_label::build() const
{
scroll_label* widget = new scroll_label(*this);
auto widget = std::make_shared<scroll_label>(*this);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);

View file

@ -103,6 +103,11 @@ private:
label* get_internal_label();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/***** ***** ***** inherited ****** *****/
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
@ -138,7 +143,7 @@ struct builder_scroll_label : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;

View file

@ -759,10 +759,9 @@ void scrollbar_container::finalize_setup()
}
/***** Setup the content *****/
content_ = build_single_widget_instance<spacer>("spacer");
content_ = build_single_widget_and_cast_to<spacer>();
// TODO: possibly move this unique_ptr casting functionality to a helper function.
content_grid_.reset(dynamic_cast<grid*>(get_grid().swap_child("_content_grid", content_, true).release()));
content_grid_ = std::dynamic_pointer_cast<grid>(get_grid().swap_child("_content_grid", content_, true));
assert(content_grid_);
content_grid_->set_parent(this);
@ -1061,12 +1060,17 @@ void scrollbar_container::scrollbar_moved()
set_scrollbar_button_status();
}
const std::string& scrollbar_container::get_control_type() const
const std::string& scrollbar_container::type()
{
static const std::string type = "scrollbar_container";
return type;
}
const std::string& scrollbar_container::get_control_type() const
{
return type();
}
void scrollbar_container::signal_handler_sdl_key_down(
const event::ui_event event, bool& handled, const SDL_Keycode key, SDL_Keymod modifier)
{

View file

@ -478,10 +478,10 @@ private:
scrollbar_base *vertical_scrollbar_, *horizontal_scrollbar_;
/** The grid that holds the content. */
std::unique_ptr<grid> content_grid_;
grid_ptr content_grid_;
/** Dummy spacer to hold the contents location. */
spacer* content_;
std::shared_ptr<spacer> content_;
/**
* Cache for the visible area for the content.
@ -522,6 +522,11 @@ private:
/** Helper function which needs to be called after the scollbar moved. */
void scrollbar_moved();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** See @ref styled_widget::get_control_type. */
virtual const std::string& get_control_type() const override;

View file

@ -65,7 +65,7 @@ struct scrollbar_container_implementation
W* result = scrollbar_container.container_base::find_at(coordinate,
must_be_active);
if(result == scrollbar_container.content_) {
if(result == scrollbar_container.content_.get()) {
return scrollbar_container.content_grid_->find_at(coordinate,
must_be_active);
}

View file

@ -33,7 +33,7 @@ namespace gui2
REGISTER_WIDGET(scrollbar_panel)
scrollbar_panel::scrollbar_panel(const implementation::builder_scrollbar_panel& builder)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
{
}
@ -149,9 +149,9 @@ builder_scrollbar_panel::builder_scrollbar_panel(const config& cfg)
assert(grid_);
}
widget* builder_scrollbar_panel::build() const
widget_ptr builder_scrollbar_panel::build() const
{
scrollbar_panel* panel = new scrollbar_panel(*this);
auto panel = std::make_shared<scrollbar_panel>(*this);
panel->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
panel->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);
@ -183,7 +183,7 @@ widget* builder_scrollbar_panel::build() const
grid_->col_grow_factor[y]);
}
widget* widget = grid_->widgets[x * cols + y]->build();
auto widget = grid_->widgets[x * cols + y]->build();
content_grid->set_child(widget,
x,
y,

View file

@ -51,6 +51,9 @@ public:
/** See @ref styled_widget::get_state. */
virtual unsigned get_state() const override;
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -85,7 +88,7 @@ struct builder_scrollbar_panel : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;

View file

@ -28,7 +28,7 @@ namespace gui2
REGISTER_WIDGET(size_lock)
size_lock::size_lock(const implementation::builder_size_lock& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, width_(builder.width_)
, height_(builder.height_)
, widget_(nullptr)
@ -163,9 +163,9 @@ builder_size_lock::builder_size_lock(const config& cfg)
content_ = create_widget_builder(cfg.child("widget"));
}
widget* builder_size_lock::build() const
widget_ptr builder_size_lock::build() const
{
size_lock* widget = new size_lock(*this);
auto widget = std::make_shared<size_lock>(*this);
DBG_GUI_G << "Window builder: placed fixed size widget '" << id << "' with definition '" << definition << "'.\n";

View file

@ -68,7 +68,7 @@ private:
*
* The widget is owned by container_base (the base class).
*/
widget* widget_;
widget_ptr widget_;
/**
* Finishes the building initialization of the widget.
@ -78,6 +78,11 @@ private:
*/
void finalize(builder_widget_const_ptr widget_builder);
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -109,7 +114,7 @@ struct builder_size_lock : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
typed_formula<unsigned> width_;
typed_formula<unsigned> height_;

View file

@ -47,7 +47,7 @@ namespace gui2
REGISTER_WIDGET(slider)
slider::slider(const implementation::builder_slider& builder)
: slider_base(builder, get_control_type())
: slider_base(builder, type())
, best_slider_length_(0)
, minimum_value_(0)
, step_size_(1)
@ -450,9 +450,9 @@ builder_slider::builder_slider(const config& cfg)
}
}
widget* builder_slider::build() const
widget_ptr builder_slider::build() const
{
slider* widget = new slider(*this);
auto widget = std::make_shared<slider>(*this);
widget->set_best_slider_length(best_slider_length_);
widget->set_value_range(minimum_value_, maximum_value_);

View file

@ -195,6 +195,11 @@ private:
// void update_current_item_mouse_position();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -243,7 +248,7 @@ struct builder_slider : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
unsigned best_slider_length_;

View file

@ -29,7 +29,7 @@ namespace gui2
REGISTER_WIDGET(spacer)
spacer::spacer(const implementation::builder_spacer& builder, const std::string& w, const std::string& h)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, width_(w)
, height_(h)
{
@ -173,9 +173,9 @@ builder_spacer::builder_spacer(const config& cfg)
{
}
widget* builder_spacer::build() const
widget_ptr builder_spacer::build() const
{
spacer* widget = new spacer(*this, width_, height_);
auto widget = std::make_shared<spacer>(*this, width_, height_);
DBG_GUI_G << "Window builder: placed spacer '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -81,6 +81,11 @@ private:
/** See @ref widget::impl_draw_background. */
virtual void impl_draw_background() override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -108,7 +113,7 @@ struct builder_spacer : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
// We store these as strings since they could contain formulas.

View file

@ -57,7 +57,7 @@ struct stacked_widget_implementation
};
stacked_widget::stacked_widget(const implementation::builder_stacked_widget& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, generator_(generator_base::build(false, false, generator_base::independent, false))
, selected_layer_(-1)
, find_in_all_layers_(false)
@ -282,9 +282,9 @@ builder_stacked_widget::builder_stacked_widget(const config& real_cfg)
}
}
widget* builder_stacked_widget::build() const
widget_ptr builder_stacked_widget::build() const
{
stacked_widget* widget = new stacked_widget(*this);
auto widget = std::make_shared<stacked_widget>(*this);
DBG_GUI_G << "Window builder: placed stacked widget '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -31,7 +31,7 @@ namespace implementation
struct builder_stacked_widget;
}
class generator_base;
using generator_ptr = std::shared_ptr<class generator_base>;
class stacked_widget : public container_base
{
@ -143,7 +143,7 @@ private:
* In that case, the generator would not allow the interim state where no layer
* before the new chosen layer is reached in the loop.
*/
generator_base* generator_;
generator_ptr generator_;
/**
* The number of the current selected layer.
@ -161,6 +161,11 @@ private:
/** Internal implementation detail for selecting layers. */
void select_layer_impl(std::function<bool(unsigned int i)> display_condition);
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -200,7 +205,7 @@ struct builder_stacked_widget : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
/** The builders for all layers of the stack .*/
std::vector<builder_grid_const_ptr> stack;

View file

@ -661,7 +661,7 @@ builder_styled_widget::builder_styled_widget(const config& cfg)
<< "' and definition '" << definition << "'.\n";
}
widget* builder_styled_widget::build(const replacements_map& /*replacements*/) const
widget_ptr builder_styled_widget::build(const replacements_map& /*replacements*/) const
{
return build();
}

View file

@ -400,13 +400,22 @@ private:
public:
/**
* Returns the control_type of the styled_widget.
* Returns the type of this styled_widget.
*
* The control_type parameter for gui_definition::get_control() To keep the
* code more generic this type is required so the controls need to return
* the proper string here. Might be used at other parts as well the get the
* type of
* styled_widget involved.
* This is used as the control_type parameter for @ref get_control.
*
* Do note that each widget also must have a public static type() function;
* it's use to implement this function. The reason for this system is twofold:
*
* 1) Due to an oddity in C++, one technically may not call a virtual function
* in a derived class's *initializer list*, which we do liberally. Calling
* it in the constructor *body* is fine, but doing so in the initializer list
* is technically undefined behavior and will give "invalid vptr" errors
* under UBSanitizer.
*
* 2) Having a static type getter allows the type string to be fetched without
* constructing an instance of the widget. A good example of this usecase is
* in @ref build_single_widget_and_cast_to.
*/
virtual const std::string& get_control_type() const = 0;
@ -498,7 +507,7 @@ public:
using builder_widget::build;
virtual widget* build(const replacements_map& replacements) const override;
virtual widget_ptr build(const replacements_map& replacements) const override;
/** Parameters for the styled_widget. */
std::string definition;

View file

@ -95,7 +95,7 @@ std::string text_history::get_value() const
}
text_box::text_box(const implementation::builder_styled_widget& builder)
: text_box_base(builder, get_control_type())
: text_box_base(builder, type())
, history_()
, max_input_length_(0)
, text_x_offset_(0)
@ -485,9 +485,9 @@ builder_text_box::builder_text_box(const config& cfg)
{
}
widget* builder_text_box::build() const
widget_ptr builder_text_box::build() const
{
text_box* widget = new text_box(*this);
auto widget = std::make_shared<text_box>(*this);
// A textbox doesn't have a label but a text
widget->set_value(label_string);

View file

@ -272,6 +272,11 @@ private:
/** Inherited from text_box_base. */
void handle_key_clear_line(SDL_Keymod modifier, bool& handled) override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -318,7 +323,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
std::string history;

View file

@ -36,7 +36,7 @@ namespace gui2
REGISTER_WIDGET(toggle_button)
toggle_button::toggle_button(const implementation::builder_toggle_button& builder)
: styled_widget(builder, get_control_type())
: styled_widget(builder, type())
, state_(ENABLED)
, state_num_(0)
, retval_(retval::NONE)
@ -278,9 +278,9 @@ builder_toggle_button::builder_toggle_button(const config& cfg)
{
}
widget* builder_toggle_button::build() const
widget_ptr builder_toggle_button::build() const
{
toggle_button* widget = new toggle_button(*this);
auto widget = std::make_shared<toggle_button>(*this);
widget->set_icon_name(icon_name_);
widget->set_retval(get_retval(retval_id_, retval_, id));

View file

@ -122,6 +122,11 @@ private:
*/
std::string icon_name_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -161,7 +166,7 @@ struct builder_toggle_button : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
std::string icon_name_;

View file

@ -38,7 +38,7 @@ namespace gui2
REGISTER_WIDGET(toggle_panel)
toggle_panel::toggle_panel(const implementation::builder_toggle_panel& builder)
: panel(builder, get_control_type())
: panel(builder, type())
, state_(ENABLED)
, state_num_(0)
, retval_(retval::NONE)
@ -398,9 +398,9 @@ builder_toggle_panel::builder_toggle_panel(const config& cfg)
grid = std::make_shared<builder_grid>(c);
}
widget* builder_toggle_panel::build() const
widget_ptr builder_toggle_panel::build() const
{
toggle_panel* widget = new toggle_panel(*this);
auto widget = std::make_shared<toggle_panel>(*this);
widget->set_retval(get_retval(retval_id_, retval_, id));

View file

@ -153,6 +153,11 @@ private:
/** See @ref widget::impl_draw_foreground. */
virtual void impl_draw_foreground() override;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -200,7 +205,7 @@ struct builder_toggle_panel : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
builder_grid_ptr grid;

View file

@ -38,7 +38,7 @@ namespace gui2
REGISTER_WIDGET(tree_view)
tree_view::tree_view(const implementation::builder_tree_view& builder)
: scrollbar_container(builder, get_control_type())
: scrollbar_container(builder, type())
, node_definitions_(builder.nodes)
, indentation_step_size_(0)
, need_layout_(false)
@ -69,13 +69,13 @@ tree_view_node& tree_view::add_node(
int tree_view::remove_node(tree_view_node* node)
{
assert(node && node != root_node_ && node->parent_node_);
assert(node && node != root_node_.get() && node->parent_node_);
const point node_size = node->get_size();
tree_view_node::node_children_vector& siblings = node->parent_node_->children_;
auto node_itor = std::find_if(siblings.begin(), siblings.end(),
[node](const std::unique_ptr<tree_view_node>& c) { return c.get() == node; }
[node](const auto& c) { return c.get() == node; }
);
assert(node_itor != siblings.end());
@ -375,13 +375,13 @@ builder_tree_view::builder_tree_view(const config& cfg)
VALIDATE(!nodes.empty(), _("No nodes defined for a tree view."));
}
widget* builder_tree_view::build() const
widget_ptr builder_tree_view::build() const
{
/*
* TODO see how much we can move in the constructor instead of
* building in several steps.
*/
tree_view* widget = new tree_view(*this);
auto widget = std::make_shared<tree_view>(*this);
widget->set_vertical_scrollbar_mode(vertical_scrollbar_mode);
widget->set_horizontal_scrollbar_mode(horizontal_scrollbar_mode);

View file

@ -125,7 +125,7 @@ private:
bool need_layout_;
tree_view_node* root_node_;
std::shared_ptr<tree_view_node> root_node_;
tree_view_node* selected_item_;
@ -157,6 +157,11 @@ private:
/** Inherited from container_base. */
virtual void finalize_setup();
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -197,7 +202,7 @@ struct builder_tree_view : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
scrollbar_container::scrollbar_mode vertical_scrollbar_mode;
scrollbar_container::scrollbar_mode horizontal_scrollbar_mode;

View file

@ -60,7 +60,7 @@ tree_view_node::tree_view_node(
continue;
}
node_definition.builder->build(&grid_);
node_definition.builder->build(grid_);
init_grid(&grid_, data);
if(parent_node_ && parent_node_->toggle_) {

View file

@ -16,6 +16,7 @@
#include "gui/widgets/widget.hpp"
#include "gui/widgets/grid.hpp"
#include <memory>
namespace gui2
@ -34,7 +35,8 @@ class tree_view_node : public widget
friend class tree_view;
public:
using node_children_vector = std::vector<std::unique_ptr<tree_view_node>>;
using ptr_t = std::shared_ptr<tree_view_node>;
using node_children_vector = std::vector<ptr_t>;
bool operator==(const tree_view_node& node)
{

View file

@ -52,7 +52,7 @@ namespace gui2
REGISTER_WIDGET(unit_preview_pane)
unit_preview_pane::unit_preview_pane(const implementation::builder_unit_preview_pane& builder)
: container_base(builder, get_control_type())
: container_base(builder, type())
, current_type_()
, icon_type_(nullptr)
, icon_race_(nullptr)
@ -587,9 +587,9 @@ builder_unit_preview_pane::builder_unit_preview_pane(const config& cfg)
{
}
widget* builder_unit_preview_pane::build() const
widget_ptr builder_unit_preview_pane::build() const
{
unit_preview_pane* widget = new unit_preview_pane(*this);
auto widget = std::make_shared<unit_preview_pane>(*this);
DBG_GUI_G << "Window builder: placed unit preview pane '" << id
<< "' with definition '" << definition << "'.\n";

View file

@ -97,6 +97,11 @@ private:
ENABLED
};
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
@ -132,7 +137,7 @@ public:
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
private:
const std::string image_mods_;

View file

@ -29,7 +29,7 @@ namespace gui2
REGISTER_WIDGET(vertical_scrollbar)
vertical_scrollbar::vertical_scrollbar(const implementation::builder_vertical_scrollbar& builder)
: scrollbar_base(builder, get_control_type())
: scrollbar_base(builder, type())
{
}
@ -194,9 +194,9 @@ builder_vertical_scrollbar::builder_vertical_scrollbar(const config& cfg)
{
}
widget* builder_vertical_scrollbar::build() const
widget_ptr builder_vertical_scrollbar::build() const
{
vertical_scrollbar* widget = new vertical_scrollbar(*this);
auto widget = std::make_shared<vertical_scrollbar>(*this);
widget->finalize_setup();

View file

@ -67,6 +67,11 @@ private:
return current.y - original.y;
}
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;
};
@ -100,7 +105,7 @@ struct builder_vertical_scrollbar : public builder_styled_widget
using builder_styled_widget::build;
widget* build() const;
virtual widget_ptr build() const override;
};
} // namespace implementation

View file

@ -62,7 +62,7 @@ struct viewport_implementation
coordinate.x -= viewport->get_x();
coordinate.y -= viewport->get_y();
return viewport->widget_.find_at(coordinate, must_be_active);
return viewport->widget_->find_at(coordinate, must_be_active);
}
template <class W>
@ -72,60 +72,45 @@ struct viewport_implementation
if(viewport->widget::find(id, must_be_active)) {
return viewport;
} else {
return viewport->widget_.find(id, must_be_active);
return viewport->widget_->find(id, must_be_active);
}
}
};
viewport::viewport(widget& widget) : widget_(widget), owns_widget_(false)
{
widget_.set_parent(this);
}
viewport::viewport(const implementation::builder_viewport& builder,
const builder_widget::replacements_map& replacements)
: widget(builder)
, widget_(*builder.widget_->build(replacements))
, owns_widget_(true)
, widget_(builder.widget_->build(replacements))
{
widget_.set_parent(this);
widget_->set_parent(this);
}
viewport::~viewport()
{
if(owns_widget_) {
delete &widget_;
}
}
viewport* viewport::build(const implementation::builder_viewport& builder,
const builder_widget::replacements_map& replacements)
{
return new viewport(builder, replacements);
}
void viewport::place(const point& origin, const point& size)
{
widget::place(origin, size);
widget_.place(point(), widget_.get_best_size());
widget_->place(point(), widget_->get_best_size());
}
void viewport::layout_initialize(const bool full_initialization)
{
widget::layout_initialize(full_initialization);
if(widget_.get_visible() != widget::visibility::invisible) {
widget_.layout_initialize(full_initialization);
if(widget_->get_visible() != widget::visibility::invisible) {
widget_->layout_initialize(full_initialization);
}
}
void viewport::impl_draw_children()
{
if(widget_.get_visible() != widget::visibility::invisible) {
widget_.draw_background();
widget_.draw_children();
widget_.draw_foreground();
if(widget_->get_visible() != widget::visibility::invisible) {
widget_->draw_background();
widget_->draw_children();
widget_->draw_foreground();
}
}
@ -157,7 +142,7 @@ const widget* viewport::find(const std::string& id, const bool must_be_active)
point viewport::calculate_best_size() const
{
return widget_.get_best_size();
return widget_->get_best_size();
}
bool viewport::disable_click_dismiss() const
@ -211,14 +196,14 @@ builder_viewport::builder_viewport(const config& cfg)
{
}
widget* builder_viewport::build() const
widget_ptr builder_viewport::build() const
{
return build(replacements_map());
}
widget* builder_viewport::build(const replacements_map& replacements) const
widget_ptr builder_viewport::build(const replacements_map& replacements) const
{
return viewport::build(*this, replacements);
return std::make_shared<viewport>(*this, replacements);
}
} // namespace implementation

View file

@ -34,17 +34,9 @@ class viewport : public widget
friend struct viewport_implementation;
public:
/** @deprecated use the second overload. */
explicit viewport(widget& widget);
private:
viewport(const implementation::builder_viewport& builder,
const builder_widget::replacements_map& replacements);
public:
static viewport* build(const implementation::builder_viewport& builder,
const builder_widget::replacements_map& replacements);
~viewport();
/** See @ref widget::place. */
@ -86,9 +78,7 @@ public:
virtual iteration::walker_base* create_walker() override;
private:
widget& widget_;
bool owns_widget_;
widget_ptr widget_;
};
// }---------- BUILDER -----------{
@ -100,9 +90,9 @@ struct builder_viewport : public builder_widget
{
explicit builder_viewport(const config& cfg);
widget* build() const;
virtual widget_ptr build() const override;
widget* build(const replacements_map& replacements) const;
virtual widget_ptr build(const replacements_map& replacements) const override;
builder_widget_ptr widget_;
};

View file

@ -728,4 +728,6 @@ public:
virtual iteration::walker_base* create_walker() = 0;
};
using widget_ptr = std::shared_ptr<widget>;
} // namespace gui2

View file

@ -16,13 +16,12 @@
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/widget.hpp"
#include <cassert>
namespace gui2
{
void swap_grid(grid* g, grid* content_grid, widget* widget, const std::string& id)
void swap_grid(grid* g, grid* content_grid,widget_ptr widget, const std::string& id)
{
assert(content_grid);
assert(widget);

View file

@ -14,15 +14,16 @@
#pragma once
#include "gui/widgets/widget.hpp"
#include <string>
namespace gui2
{
class grid;
class widget;
/**
* Swaps an item in a grid for another one.
*/
void swap_grid(grid* g, grid* content_grid, widget* widget, const std::string& id);
void swap_grid(grid* g, grid* content_grid, widget_ptr widget, const std::string& id);
}

View file

@ -98,7 +98,7 @@ public:
using builder_styled_widget::build;
widget* build() const
virtual widget_ptr build() const override
{
return nullptr;
}
@ -252,7 +252,7 @@ window* manager::get_window(const unsigned id)
} // namespace
window::window(const builder_window::window_resolution* definition)
: panel(implementation::builder_window(::config {"definition", definition->definition}), get_control_type())
: panel(implementation::builder_window(::config {"definition", definition->definition}), type())
, cursor::setter(cursor::NORMAL)
, video_(CVideo::get_singleton())
, status_(NEW)
@ -948,7 +948,7 @@ namespace
*/
void window_swap_grid(grid* g,
grid* content_grid,
widget* widget,
widget_ptr widget,
const std::string& id)
{
assert(content_grid);

View file

@ -611,6 +611,11 @@ private:
*/
int mouse_button_state_;
public:
/** Static type getter that does not rely on the widget being constructed. */
static const std::string& type();
private:
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
virtual const std::string& get_control_type() const override;