From fef09a8d2fe38dcc8fd3beff3e132f945a4d4c8a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 16 Jun 2013 15:03:48 +0300 Subject: [PATCH] Support widget expansion in linear layouts --- source/arrangement.cpp | 15 ++++++++++++++- source/arrangement.h | 1 + source/lineararrangement.cpp | 19 +++++++++++++++++++ source/lineararrangement.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/source/arrangement.cpp b/source/arrangement.cpp index 581e6b4..9982691 100644 --- a/source/arrangement.cpp +++ b/source/arrangement.cpp @@ -45,7 +45,8 @@ void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge) { for(list::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i) - layout.add_constraint(wdg, type, **i); + if(*i!=&wdg) + layout.add_constraint(wdg, type, **i); } Layout::ConstraintType Arrangement::get_order_constraint(Side s, bool slack) @@ -95,5 +96,17 @@ void Arrangement::Edge::add(Widget &wdg, bool algn) aligned = algn; } +void Arrangement::Edge::align() +{ + if(aligned || widgets.empty()) + return; + + list::iterator second = widgets.begin(); + ++second; + + widgets.erase(second, widgets.end()); + aligned = true; +} + } // namespace GLtk } // namespace Msp diff --git a/source/arrangement.h b/source/arrangement.h index fc3ec82..f323a9b 100644 --- a/source/arrangement.h +++ b/source/arrangement.h @@ -38,6 +38,7 @@ protected: bool empty() { return widgets.empty(); } void clear(); void add(Widget &, bool); + void align(); }; Layout &layout; diff --git a/source/lineararrangement.cpp b/source/lineararrangement.cpp index 891b858..9e6441a 100644 --- a/source/lineararrangement.cpp +++ b/source/lineararrangement.cpp @@ -21,6 +21,19 @@ void LinearArrangement::split() gravity = primary; } +void LinearArrangement::expand() +{ + if(gravity==primary) + throw arrangement_error("already split"); + if(edges[primary].empty()) + throw arrangement_error("no widgets"); + + add_constraint(*edges[primary].widgets.front(), get_align_constraint(primary), primary); + layout.set_expand(*edges[primary].widgets.front(), false, true); + edges[primary].align(); + gravity = primary; +} + void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned) { if(side==opposite) @@ -52,9 +65,15 @@ void LinearArrangement::finish_slot() LinearArrangement::Loader::Loader(LinearArrangement &c): DataFile::ObjectLoader(c) { + add("expand", &Loader::expand); add("split", &Loader::split); } +void LinearArrangement::Loader::expand() +{ + obj.expand(); +} + void LinearArrangement::Loader::split() { obj.split(); diff --git a/source/lineararrangement.h b/source/lineararrangement.h index 571e279..3fd5ef7 100644 --- a/source/lineararrangement.h +++ b/source/lineararrangement.h @@ -15,6 +15,7 @@ public: public: Loader(LinearArrangement &); private: + void expand(); void split(); }; -- 2.45.2