From: Mikko Rasa Date: Sat, 15 Dec 2012 18:11:56 +0000 (+0200) Subject: Allow specifying a custom spacing for a constraint X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5e97c5c224c30e68c26fddd2153694088f932bee;p=libs%2Fgltk.git Allow specifying a custom spacing for a constraint --- diff --git a/source/layout.cpp b/source/layout.cpp index bfe46c4..d3d015f 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -203,7 +203,7 @@ Layout::ConstraintType Layout::complement(ConstraintType type) return type; } -void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt) +void Layout::create_constraint(Widget &src, ConstraintType type, Widget &tgt, int sp) { if(&src==&tgt) throw invalid_argument("&src==&tgt"); @@ -216,11 +216,23 @@ void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt) return; src_slot.constraints.push_back(Constraint(type, tgt_slot)); + src_slot.constraints.back().spacing = sp; tgt_slot.constraints.push_back(Constraint(complement(type), src_slot)); + tgt_slot.constraints.back().spacing = sp; update(); } +void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt) +{ + create_constraint(src, type, tgt, -1); +} + +void Layout::add_constraint(Widget &src, ConstraintType type, Widget &tgt, unsigned spacing) +{ + create_constraint(src, type, tgt, spacing); +} + void Layout::set_gravity(Widget &wdg, int h, int v) { Slot &slot = get_slot_for_widget(wdg); @@ -339,7 +351,7 @@ void Layout::solve_constraints(int dir, SolveMode mode) if(j->type&TARGET_DIM) row[j->target.index*5+1] = -1; if(j->type&SPACING) - row.back() = this->*(ptrs.spacing); + row.back() = (j->spacing>=0 ? j->spacing : this->*(ptrs.spacing)); } } @@ -368,7 +380,8 @@ void Layout::solve_constraints(int dir, SolveMode mode) Layout::Constraint::Constraint(ConstraintType t, Slot &s): type(t), - target(s) + target(s), + spacing(-1) { } diff --git a/source/layout.h b/source/layout.h index cbd763e..2303651 100644 --- a/source/layout.h +++ b/source/layout.h @@ -84,6 +84,7 @@ protected: { ConstraintType type; Slot ⌖ + int spacing; Constraint(ConstraintType, Slot &); }; @@ -147,8 +148,16 @@ protected: virtual Slot *create_slot(Widget &); Slot &get_slot_for_widget(Widget &); static ConstraintType complement(ConstraintType); + void create_constraint(Widget &, ConstraintType, Widget &, int); + public: - void add_constraint(Widget &, ConstraintType, Widget &); + /** Adds a constraint between two widgets. */ + void add_constraint(Widget &src, ConstraintType type, Widget &tgt); + + /** Adds a constraint between two widgets, overriding the default spacing. + Not all constraint types use a spacing. */ + void add_constraint(Widget &src, ConstraintType type, Widget &tgt, unsigned); + void set_gravity(Widget &, int, int); void set_expand(Widget &, bool, bool);