]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a packing attribute to consider a widget even if it's hidden
authorMikko Rasa <tdb@tdb.fi>
Sun, 16 Jun 2013 19:59:20 +0000 (22:59 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 16 Jun 2013 19:59:20 +0000 (22:59 +0300)
source/layout.cpp
source/layout.h
source/panel.cpp
source/panel.h

index c616ff6fc7caff9833070cf1c30e7c7710e20ad9..743b30ebf3263b7246659191aeca349906623513 100644 (file)
@@ -213,7 +213,7 @@ void Layout::update_slot_indices()
        n_active_slots = 0;
        for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
        {
-               if((*i)->widget.is_visible())
+               if((*i)->widget.is_visible() || (*i)->ghost)
                        (*i)->index = n_active_slots++;
                else
                        (*i)->index = -1;
@@ -295,6 +295,19 @@ void Layout::set_expand(Widget &wdg, bool h, bool v)
        update();
 }
 
+void Layout::set_ghost(Widget &wdg, bool g)
+{
+       Slot &slot = get_slot_for_widget(wdg);
+
+       slot.ghost = g;
+
+       if(!wdg.is_visible())
+       {
+               update_slot_indices();
+               update();
+       }
+}
+
 void Layout::update()
 {
        solve_constraints(HORIZONTAL, UPDATE);
@@ -444,7 +457,8 @@ Layout::Packing::Packing():
 Layout::Slot::Slot(Layout &l, Widget &w):
        layout(l),
        index(0),
-       widget(w)
+       widget(w),
+       ghost(false)
 {
        vert_pack.gravity = 1;
        widget.signal_autosize_changed.connect(sigc::mem_fun(this, &Slot::autosize_changed));
@@ -458,7 +472,7 @@ void Layout::Slot::autosize_changed()
        widget.autosize();
        autosize_geom = widget.get_geometry();
 
-       if(!widget.is_visible())
+       if(!widget.is_visible() && !ghost)
                return;
 
        // If the widget fits in the area it had, just leave it there.
@@ -474,7 +488,7 @@ void Layout::Slot::autosize_changed()
 void Layout::Slot::visibility_changed(bool v)
 {
        layout.update_slot_indices();
-       if(v)
+       if(v || ghost)
        {
                layout.container->signal_autosize_changed.emit();
                layout.update();
@@ -530,6 +544,7 @@ Layout::WidgetLoader::WidgetLoader(Layout &l, Widget &w, const Layout::Loader::W
 {
        add("constraint", &WidgetLoader::constraint);
        add("expand",     &WidgetLoader::expand);
+       add("ghost",      &WidgetLoader::ghost);
        add("gravity",    &WidgetLoader::gravity);
 }
 
@@ -544,6 +559,11 @@ void Layout::WidgetLoader::expand(bool h, bool v)
        layout.set_expand(widget, h, v);
 }
 
+void Layout::WidgetLoader::ghost(bool g)
+{
+       layout.set_ghost(widget, g);
+}
+
 void Layout::WidgetLoader::gravity(int h, int v)
 {
        layout.set_gravity(widget, h, v);
index b8c4eddf51c526222538457b64a971d6e6e83ad2..a8ea3bf25b7f819492d14eb34c30a24380ba1f76 100644 (file)
@@ -119,6 +119,7 @@ private:
        private:
                void constraint(ConstraintType, const std::string &);
                void expand(bool, bool);
+               void ghost(bool);
                void gravity(int, int);
        };
 
@@ -151,6 +152,7 @@ private:
                std::list<Constraint> constraints;
                Packing horiz_pack;
                Packing vert_pack;
+               bool ghost;
 
                Slot(Layout &, Widget &);
 
@@ -220,6 +222,9 @@ public:
        void set_gravity(Widget &, int, int);
        void set_expand(Widget &, bool, bool);
 
+       /// Sets a widget as a ghost, taking up space even if it is hidden.
+       void set_ghost(Widget &, bool);
+
        void update();
        void autosize();
 
index 8c5dd38f26be2d400640258882da93c24a50690a..930a68f980f96a065552f11942c1b14f519ac2db 100644 (file)
@@ -90,6 +90,7 @@ Panel::Loader::Loader(Panel &p, map<string, Widget *> &m):
        add("dropdown",  &Loader::child<Dropdown>);
        add("entry",     &Loader::child<Entry>);
        add("expand",    &Loader::expand);
+       add("ghost",     &Loader::ghost);
        add("gravity",   &Loader::gravity);
        add("grid",      &Loader::grid);
        add("hslider",   &Loader::child<HSlider>);
@@ -148,6 +149,11 @@ void Panel::Loader::expand(bool h, bool v)
        get_layout().set_expand(get_last_widget(), h, v);
 }
 
+void Panel::Loader::ghost(bool g)
+{
+       get_layout().set_ghost(get_last_widget(), g);
+}
+
 void Panel::Loader::gravity(int h, int v)
 {
        get_layout().set_gravity(get_last_widget(), h, v);
index 79e8bd455a3b36cbd76f9f113641cb81baa79731..ee2859c1e12423ab0fd6dc009cae09e6868f80f6 100644 (file)
@@ -35,6 +35,7 @@ public:
                void child(const std::string &);
                void constraint(Layout::ConstraintType, const std::string &);
                void expand(bool, bool);
+               void ghost(bool);
                void gravity(int, int);
                void grid(unsigned);
                void layout();