X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flayout.cpp;h=d3d015f7305c7ddb70a024c4884ee88cbf3711f2;hb=eb6eee5fabf05abca4a0434c2a8f8f62c900afec;hp=ccd02830924b0622eb12dcf86ba4a0aa9b5a2b74;hpb=e291dcf478052c771d85089409f9bc22a4c8ab93;p=libs%2Fgltk.git diff --git a/source/layout.cpp b/source/layout.cpp index ccd0283..d3d015f 100644 --- a/source/layout.cpp +++ b/source/layout.cpp @@ -110,6 +110,28 @@ void Layout::set_margin(const Sides &m) update(); } +void Layout::set_spacing(unsigned s) +{ + row_spacing = s; + col_spacing = s; + if(container) + update(); +} + +void Layout::set_row_spacing(unsigned s) +{ + row_spacing = s; + if(container) + update(); +} + +void Layout::set_column_spacing(unsigned s) +{ + col_spacing = s; + if(container) + update(); +} + void Layout::add_widget(Widget &wdg) { if(!container) @@ -181,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"); @@ -194,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); @@ -282,6 +316,16 @@ void Layout::solve_constraints(int dir, SolveMode mode) row.back() = geom.*(ptrs.dim)-margin.*(ptrs.high_margin); } + if(((*i)->*(ptrs.packing)).gravity==0) + { + /* This forces the widget's distance from the left and right edge of + the container to be equal. It's a bit of a hack, but more time and + thought is needed for a better solution. */ + LinearProgram::Row row = linprog.add_row(); + row[(*i)->index*5+2] = 1; + row[(*i)->index*5+3] = -1; + } + { /* Only allow the widget's dimension to increase. The geometry has previously been set to the smallest allowable size. */ @@ -307,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)); } } @@ -336,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) { }