X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgrid.cpp;fp=source%2Fgrid.cpp;h=4bf01678c4a226b0ca3ff0c9a82bef857c78af83;hb=a84c813859b6908c511b12ab7d82d6643f4f1a42;hp=0000000000000000000000000000000000000000;hpb=01eaaef90f4c56cd4669d2f621e3061a938753eb;p=libs%2Fgltk.git diff --git a/source/grid.cpp b/source/grid.cpp new file mode 100644 index 0000000..4bf0167 --- /dev/null +++ b/source/grid.cpp @@ -0,0 +1,82 @@ +/* $Id$ + +This file is part of libmspgltk +Copyright © 2011 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include "grid.h" + +using namespace std; + +namespace Msp { +namespace GLtk { + +Grid::Grid(bool u): + uniform(u), + cur_column(0), + first(true), + skipped(false) +{ } + +void Grid::start_row() +{ + cur_column = 0; + first = true; +} + +void Grid::skip_cell() +{ + ++cur_column; + skipped = true; + if(cur_column>=columns.size()) + columns.push_back(0); +} + +Layout::Slot *Grid::create_slot(Widget &wdg) +{ + Slot *slot = new Slot(*this, wdg); + + slot->vert_pack.gravity = 1; + + if(!slots.empty()) + { + 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(uniform) + { + slot->constraints.push_back(Constraint(COPY_WIDTH, prev)); + slot->constraints.push_back(Constraint(COPY_HEIGHT, prev)); + } + + if(cur_columnconstraints.push_back(Constraint(ALIGN_LEFT, col)); + slot->constraints.push_back(Constraint(ALIGN_RIGHT, col)); + } + } + + if(cur_column>=columns.size()) + columns.push_back(slot); + else if(!columns[cur_column]) + columns[cur_column] = slot; + + first = false; + skipped = false; + ++cur_column; + + return slot; +} + +} // namespace GLtk +} // namespace Msp