summaryrefslogtreecommitdiff
path: root/ui.cpp
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-01-14 23:39:47 +1100
committerquou <quou@disroot.org>2025-01-14 23:39:47 +1100
commitec1ab61e120858b3fc646f9b330bc6a977d576a9 (patch)
tree55d9415bbc970d0379fa4c0a8f0854ef2aeb454a /ui.cpp
parented62713bbed8f82ed3044c41e6863bcccff3d890 (diff)
UI table layout
Diffstat (limited to 'ui.cpp')
-rw-r--r--ui.cpp57
1 files changed, 56 insertions, 1 deletions
diff --git a/ui.cpp b/ui.cpp
index dc41268..5197559 100644
--- a/ui.cpp
+++ b/ui.cpp
@@ -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;