]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a flag to make widgets in a LinearArrangement the same size
authorMikko Rasa <tdb@tdb.fi>
Thu, 5 Sep 2019 21:08:08 +0000 (00:08 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 5 Sep 2019 21:08:08 +0000 (00:08 +0300)
source/column.cpp
source/lineararrangement.cpp
source/lineararrangement.h
source/row.cpp

index e7f709531a06f2e5785ac9e070c7aef31f6f988d..e90d334adf12c4106eb7f54b89485546bc29f6ed 100644 (file)
@@ -9,6 +9,7 @@ Column::Column(Layout &l):
 
 void Column::finish_widget(Widget &wdg)
 {
+       LinearArrangement::finish_widget(wdg);
        layout.set_gravity(wdg, -1, (gravity==BOTTOM ? -1 : 1));
 }
 
index fb2e71c180dac87aa81c41ec3fce0d6c80b06a4b..5294252a11b5f38ffec445c24880e0d4009f69eb 100644 (file)
@@ -11,9 +11,18 @@ LinearArrangement::LinearArrangement(Layout &l, Side p):
        split_here(false),
        gravity(opposite),
        internal_aligned(false),
+       uniform(false),
+       uniform_ref(0),
        next_spacing(-1)
 { }
 
+void LinearArrangement::set_uniform(bool u)
+{
+       uniform = u;
+       if(!uniform)
+               uniform_ref = 0;
+}
+
 void LinearArrangement::split()
 {
        if(gravity==primary)
@@ -60,6 +69,20 @@ void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned)
        }
 }
 
+void LinearArrangement::finish_widget(Widget &wdg)
+{
+       if(uniform)
+       {
+               if(!uniform_ref)
+                       uniform_ref = &wdg;
+               else
+               {
+                       Layout::ConstraintType ct = ((primary==LEFT || primary==RIGHT) ? Layout::COPY_WIDTH : Layout::COPY_HEIGHT);
+                       layout.add_constraint(wdg, ct, *uniform_ref);
+               }
+       }
+}
+
 void LinearArrangement::finish_slot()
 {
        internal_aligned = next.aligned;
@@ -79,6 +102,7 @@ LinearArrangement::Loader::Loader(LinearArrangement &c):
        add("expand", &Loader::expand);
        add("spacing", &Loader::spacing);
        add("split", &Loader::split);
+       add("uniform", &Loader::uniform);
 }
 
 void LinearArrangement::Loader::expand()
@@ -96,5 +120,10 @@ void LinearArrangement::Loader::split()
        obj.split();
 }
 
+void LinearArrangement::Loader::uniform(bool u)
+{
+       obj.set_uniform(u);
+}
+
 } // namespace GLtk
 } // namespace Msp
index 4b149a4ad2d7284901dea33d995f361ae78cf985..ce49b34edf38c99d9618a2f424cbcc73bafb2adb 100644 (file)
@@ -18,6 +18,7 @@ public:
                void expand();
                void spacing(unsigned);
                void split();
+               void uniform(bool);
        };
 
 protected:
@@ -28,17 +29,21 @@ protected:
        bool split_here;
        Side gravity;
        bool internal_aligned;
+       bool uniform;
+       Widget *uniform_ref;
        int next_spacing;
 
        LinearArrangement(Layout &, Side);
 
 public:
+       void set_uniform(bool);
        void split();
        void expand();
        void spacing(unsigned);
 
 protected:
        virtual void process_widget(Widget &, Side, bool);
+       virtual void finish_widget(Widget &);
        virtual void finish_slot();
 };
 
index 0188f4a663c4dec2a75e71abadd285fab640759e..6a5e45be92e6309f2325f129a198557cebaf8fc1 100644 (file)
@@ -9,6 +9,7 @@ Row::Row(Layout &l):
 
 void Row::finish_widget(Widget &wdg)
 {
+       LinearArrangement::finish_widget(wdg);
        layout.set_gravity(wdg, (gravity==LEFT ? -1 : 1), 1);
 }