diff options
author | quou <quou@disroot.org> | 2024-12-31 13:59:13 +1100 |
---|---|---|
committer | quou <quou@disroot.org> | 2024-12-31 13:59:13 +1100 |
commit | 92c41a7f7c5c96d07476f04a3bded2a8d04d2204 (patch) | |
tree | 9fe4f9e51616cf7bdc68789bbe3d8590af986984 | |
parent | a9a0d1ee84397621b6172693330b48e9474b0a91 (diff) |
fix invalid clip rects
-rw-r--r-- | ui.cpp | 19 | ||||
-rw-r--r-- | ui.hpp | 2 |
2 files changed, 15 insertions, 6 deletions
@@ -147,6 +147,8 @@ void UI::Rect::clip(const Rect& other) { w -= n; if ((n = y + h - (other.y + other.h)) > 0) h -= n; + if (w < 0) w = 0; + if (h < 0) h = 0; } void UI::Rect::shrink(int a) { @@ -154,6 +156,8 @@ void UI::Rect::shrink(int a) { y += a; w -= a * 2; h -= a * 2; + if (w < 0) w = 0; + if (h < 0) h = 0; } bool UI::Rect::contains(int px, int py) { @@ -335,6 +339,8 @@ void UI::Vertex_Buffer::reset(const Rect& c) { void UI::Vertex_Buffer::set_clip(const Rect& r) { clip = r; + assert(r.x >= 0 && r.y >= 0); + assert(r.w >= 0 && r.h >= 0); if (next) next->set_clip(r); } @@ -442,10 +448,8 @@ void UI::destroy() { } void UI::layout(int w, int h) { - area_w = w; - area_h = h; - Rect avail(0, 0, w, h); - root->layout(avail); + area = Rect(0, 0, w, h); + root->layout(area); layout_dirty = 0; } @@ -475,7 +479,7 @@ void UI::update(Arena* s) { } } if (layout_dirty) - layout(area_w, area_h); + layout(area.w, area.h); } void UI::render(Arena* s, Texture_Id target) { @@ -757,6 +761,7 @@ UI::Rect UI::Container::layout(const Rect& avail) { used.w = used.h = 0; bound = avail; clip = avail; + clip.clip(ui->area); for (child = children; child; child = child->next) { Rect r = child->layout(area); area.y += r.h + padding; @@ -788,6 +793,7 @@ UI::Rect UI::Toolbar::layout(const Rect& avail) { bound = used; bound.w = avail.w; clip = bound; + clip.clip(ui->area); return used; } @@ -823,6 +829,7 @@ UI::Rect UI::Button::layout(const Rect& avail) { bound = r; clip = r; clip.shrink(ui_padding); + clip.clip(ui->area); return r; } @@ -866,6 +873,7 @@ UI::Rect UI::Label::layout(const Rect& avail) { bound = r; clip = r; clip.shrink(ui_padding); + clip.clip(ui->area); return r; } @@ -917,6 +925,7 @@ UI::Rect UI::Modal::layout(const Rect& avail) { title_bar->layout(content_size); bound = content_size; clip = content_size; + clip.clip(ui->area); return content_size; } @@ -98,7 +98,7 @@ struct UI { Pipeline* pipeline; Render_Pass* render_pass; Element* root, * hot, * hovered; - int area_w, area_h; + Rect area; bool layout_dirty; struct UI_CBuffer { |