X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgrid.cpp;h=b3e9c43c311898896638e267d13edcdc88cba1a7;hb=646af3dd91a6ca981572a5b69a0f0bd205d9af49;hp=fb08823817db11fa7b04da88b46ad5169fb45e70;hpb=df07e8f3e239b146cbc458d3cbd69758e590d255;p=libs%2Fgltk.git diff --git a/source/grid.cpp b/source/grid.cpp index fb08823..b3e9c43 100644 --- a/source/grid.cpp +++ b/source/grid.cpp @@ -1,74 +1,87 @@ #include "grid.h" -using namespace std; - namespace Msp { namespace GLtk { -Grid::Grid(bool u): - uniform(u), - cur_column(0), - first(true), - skipped(false) +Grid::Grid(Layout &l, unsigned c): + Arrangement(l), + columns(c), + first_row(true), + column(0) { } -void Grid::start_row() +void Grid::skip() { - cur_column = 0; - first = true; + finish_slot(); } -void Grid::skip_cell() +void Grid::next_row() { - ++cur_column; - skipped = true; - if(cur_column>=columns.size()) - columns.push_back(0); + finish_row(); } -Layout::Slot *Grid::create_slot(Widget &wdg) +void Grid::process_widget(Widget &wdg, Side side, bool aligned) { - Slot *slot = new Slot(*this, wdg); + if(side==TOP) + { + Edge &top_edge = (first_row ? edges[TOP] : row_top); + if(top_edge.aligned && aligned) + add_constraint(wdg, Layout::ALIGN_TOP, top_edge); - slot->vert_pack.gravity = 1; + bool snug = (edges[BOTTOM].aligned && aligned); + add_constraint(wdg, (snug ? Layout::BELOW : Layout::FAR_BELOW), BOTTOM); - if(!slots.empty()) + top_edge.add(wdg, aligned); + } + else if(side==BOTTOM) { - Slot &prev = *slots.back(); - if(first) - slot->constraints.push_back(Constraint(BELOW, prev)); - else - { - slot->constraints.push_back(Constraint(ALIGN_TOP, prev)); - slot->constraints.push_back(Constraint(ALIGN_BOTTOM, prev)); - if(!skipped) - slot->constraints.push_back(Constraint(RIGHT_OF, prev)); - } + if(row_bottom.aligned && aligned) + add_constraint(wdg, Layout::ALIGN_BOTTOM, row_bottom); - if(uniform) + row_bottom.add(wdg, aligned); + } + else if(side==LEFT) + { + if(columns[column].left.aligned && aligned) + add_constraint(wdg, Layout::ALIGN_LEFT, columns[column].left); + else if(column>0) { - slot->constraints.push_back(Constraint(COPY_WIDTH, prev)); - slot->constraints.push_back(Constraint(COPY_HEIGHT, prev)); + bool snug = (columns[column-1].right.aligned && aligned); + add_constraint(wdg, (snug ? Layout::RIGHT_OF : Layout::FAR_RIGHT_OF), columns[column-1].right); } - if(cur_columnconstraints.push_back(Constraint(ALIGN_LEFT, col)); - slot->constraints.push_back(Constraint(ALIGN_RIGHT, col)); - } + edges[LEFT].add(wdg, (aligned && !column)); + columns[column].left.add(wdg, aligned); } + else if(side==RIGHT) + { + if(columns[column].right.aligned && aligned) + add_constraint(wdg, Layout::ALIGN_RIGHT, columns[column].right); - if(cur_column>=columns.size()) - columns.push_back(slot); - else if(!columns[cur_column]) - columns[cur_column] = slot; + edges[RIGHT].add(wdg, (aligned && column+1==columns.size())); + columns[column].right.add(wdg, aligned); + } +} - first = false; - skipped = false; - ++cur_column; +void Grid::finish_widget(Widget &wdg) +{ + layout.set_gravity(wdg, -1, 1); +} - return slot; +void Grid::finish_slot() +{ + ++column; + if(column==columns.size()) + finish_row(); +} + +void Grid::finish_row() +{ + edges[BOTTOM] = row_bottom; + row_bottom.clear(); + row_top.clear(); + first_row = false; + column = 0; } } // namespace GLtk