diff options
Diffstat (limited to 'ui.cpp')
-rw-r--r-- | ui.cpp | 19 |
1 files changed, 14 insertions, 5 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; } |