diff options
Diffstat (limited to 'ui.cpp')
-rw-r--r-- | ui.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
@@ -841,6 +841,61 @@ void UI::Container::on_render() { ui->mesh.set_clip(clip); } +UI::Table::Table(UI* ui, Element* parent, const int* rs): + Container(ui, parent) { + int c = 0, i; + const int* r = rs; + for (; *r; r++, c++); + rows = (int*)heap_alloc(ui->heap, c + 1 * sizeof *rows); + for (i = 0; i < c; i++) + rows[i] = rs[i]; + rows[i] = 0; +} + +UI::Table::~Table() { + heap_free(ui->heap, rows); +} + +UI::Rect UI::Table::layout(const Rect& avail) { + Rect used = avail; + Rect area = avail; + Element* child; + int* row = rows; + int cx = area.x + padding; + int rh = 0; + used.w = used.h = 0; + for (; *row; row++) + used.w += *row + padding; + row = rows; + for (child = children; child; child = child->next) { + if (!*row) { + int i = rh + padding; + cx = area.x + padding; + area.y += i; + area.h -= i * 2; + used.h += i; + rh = 0; + row = rows; + } + Rect carea = { + cx, + area.y, + used.w - padding * 2, + area.h + }; + Rect r = child->layout(carea); + if (r.h > rh) rh = r.h; + cx += *row; + row++; + } + used.h += rh + padding; + bound = used; + bound.clip(avail); + clip = bound; + clip.clip(ui->area); + return bound; +} + UI::Toolbar::Toolbar(UI* ui, Element* parent): Element(ui, parent), padding(0) {} @@ -1300,7 +1355,7 @@ void UI::Modal::on_render() { void UI::Modal::on_update() { if (dragging) { const App& app = *ui->app; - Rect avail = bound; + Rect avail = ui->area; avail.x = app.mx - drag_offset[0]; avail.y = app.my - drag_offset[1]; pos[0] = avail.x; |