From: Mikko Rasa Date: Thu, 5 Sep 2019 21:08:08 +0000 (+0300) Subject: Add a flag to make widgets in a LinearArrangement the same size X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d2491d05fe17541a01bd7f3264e693fad616f2d9;p=libs%2Fgltk.git Add a flag to make widgets in a LinearArrangement the same size --- diff --git a/source/column.cpp b/source/column.cpp index e7f7095..e90d334 100644 --- a/source/column.cpp +++ b/source/column.cpp @@ -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)); } diff --git a/source/lineararrangement.cpp b/source/lineararrangement.cpp index fb2e71c..5294252 100644 --- a/source/lineararrangement.cpp +++ b/source/lineararrangement.cpp @@ -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 diff --git a/source/lineararrangement.h b/source/lineararrangement.h index 4b149a4..ce49b34 100644 --- a/source/lineararrangement.h +++ b/source/lineararrangement.h @@ -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(); }; diff --git a/source/row.cpp b/source/row.cpp index 0188f4a..6a5e45b 100644 --- a/source/row.cpp +++ b/source/row.cpp @@ -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); }