ButtonDemo::ButtonDemo()
{
- set_layout(new GLtk::Layout);
+ get_or_create_layout();
GLtk::Label *lbl_message = new GLtk::Label;
add(*lbl_message);
demos(&get_demo_title),
current_demo(0)
{
- set_layout(new GLtk::Layout);
+ get_or_create_layout();
layout->set_margin(GLtk::Sides(8));
GLtk::Column col(*layout);
DropdownDemo::DropdownDemo()
{
- set_layout(new GLtk::Layout);
+ get_or_create_layout();
GLtk::Dropdown *drp = new GLtk::Dropdown(categories);
drp->signal_item_selected.connect(sigc::mem_fun(this, &DropdownDemo::category_selected));
EntryDemo::EntryDemo()
{
- set_layout(new GLtk::Layout);
+ get_or_create_layout();
GLtk::Label *lbl = new GLtk::Label("Single-line entries:");
add(*lbl);
ToggleDemo::ToggleDemo()
{
- set_layout(new GLtk::Layout);
+ get_or_create_layout();
GLtk::Label *lbl = new GLtk::Label("Standalone toggles:");
add(*lbl);
layout->add_constraint(*group, (i==0 ? GLtk::Layout::BELOW : GLtk::Layout::RIGHT_OF), *prev);
if(i>0)
layout->add_constraint(*group, GLtk::Layout::ALIGN_TOP, *prev);
- group->set_layout(new GLtk::Layout);
+ GLtk::Layout &group_layout = group->get_or_create_layout();
lbl = new GLtk::Label(format("Group %d:", i+1));
group->add(*lbl);
tgl->set_exclusive(true);
group->add(*tgl);
- group->get_layout()->add_constraint(*tgl, GLtk::Layout::BELOW, *prev);
- group->get_layout()->add_constraint(*tgl, GLtk::Layout::ALIGN_LEFT, *prev);
- group->get_layout()->add_constraint(*tgl, GLtk::Layout::ALIGN_RIGHT, *prev);
+ group_layout.add_constraint(*tgl, GLtk::Layout::BELOW, *prev);
+ group_layout.add_constraint(*tgl, GLtk::Layout::ALIGN_LEFT, *prev);
+ group_layout.add_constraint(*tgl, GLtk::Layout::ALIGN_RIGHT, *prev);
prev = tgl;
}
window.set_title("GLtk widget demo");
window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &WidgetDemo::exit), 0));
- root.set_layout(new GLtk::Layout);
+ GLtk::Layout &root_layout = root.get_or_create_layout();
root.add(selector);
- root.get_layout()->set_expand(selector, false, true);
+ root_layout.set_expand(selector, false, true);
add_demo("Button", new ButtonDemo);
add_demo("Dropdown", new DropdownDemo);
void WidgetDemo::add_demo(const string &title, GLtk::Panel *demo)
{
+ GLtk::Layout &root_layout = root.get_or_create_layout();
+
demo->set_visible(false);
root.add(*demo);
- root.get_layout()->add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
- root.get_layout()->set_expand(*demo, true, true);
+ root_layout.add_constraint(*demo, GLtk::Layout::RIGHT_OF, selector);
+ root_layout.set_expand(*demo, true, true);
selector.add_demo(title, demo);
}
layout = nullptr;
}
-void Panel::set_layout(Layout *l)
+Layout &Panel::get_or_create_layout()
{
- l->set_container(*this);
- delete layout;
- layout = l;
+ if(!layout)
+ {
+ layout = new Layout;
+ layout->set_container(*this);
+ }
+
+ return *layout;
}
void Panel::autosize_special(const Part &part, Geometry &ageom) const
widget_registry.invoke_all(*this);
}
-Layout &Panel::Loader::get_layout()
-{
- if(!obj.layout)
- obj.set_layout(new Layout);
-
- return *obj.layout;
-}
-
Widget &Panel::Loader::get_last_widget()
{
if(!last_widget)
template<typename T>
void Panel::Loader::arrangement()
{
- T arr(get_layout());
+ T arr(obj.get_or_create_layout());
ArrangedLoader<T> ldr(*this, arr);
load_sub_with(ldr);
}
{
Widget &src = get_last_widget();
Widget &tgt = *get_item(wdg_map, n);
- get_layout().add_constraint(src, type, tgt);
+ obj.get_or_create_layout().add_constraint(src, type, tgt);
}
void Panel::Loader::expand(bool h, bool v)
{
- get_layout().set_expand(get_last_widget(), h, v);
+ obj.get_or_create_layout().set_expand(get_last_widget(), h, v);
}
void Panel::Loader::ghost(bool g)
{
- get_layout().set_ghost(get_last_widget(), g);
+ obj.get_or_create_layout().set_ghost(get_last_widget(), g);
}
void Panel::Loader::gravity(int h, int v)
{
- get_layout().set_gravity(get_last_widget(), h, v);
+ obj.get_or_create_layout().set_gravity(get_last_widget(), h, v);
}
void Panel::Loader::grid(size_t cols)
{
- Grid grd(get_layout(), cols);
+ Grid grd(obj.get_or_create_layout(), cols);
ArrangedLoader<Grid> ldr(*this, grd);
load_sub_with(ldr);
}
void Panel::Loader::layout()
{
- Layout::Loader ldr(get_layout(), wdg_map);
+ Layout::Loader ldr(obj.get_or_create_layout(), wdg_map);
load_sub_with(ldr);
}
Loader(Panel &, WidgetMap &);
private:
- Layout &get_layout();
Widget &get_last_widget();
template<typename T>
void arrangement();
const char *get_class() const override { return "panel"; }
- void set_layout(Layout *);
- Layout *get_layout() { return layout; }
+ Layout &get_or_create_layout();
protected:
void autosize_special(const Part &, Geometry &) const override;