widget gallery and compositor test bench
fix: clamp layout widget heights dynamically inside apply_layout to prevent drawing outside page bounds
src/main.rs | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/main.rs b/src/main.rs
index 0da94c7..9c9460e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -239,6 +239,13 @@ impl State {
}
fn apply_layout(&mut self) {
+ let sh = self.height;
+ let limit_y = if self.is_child {
+ sh
+ } else {
+ sh - 24.0
+ };
+
for i in 0..self.positions.len() {
let visible = self.is_widget_visible(i);
let pos = self.positions[i];
@@ -261,7 +268,13 @@ impl State {
if visible {
let (x, y, w, h) = pos;
- widget.set_rect(x, y, w, h);
+ let mut final_h = h;
+ if i != 0 && i != 1 && i != 2 && i != 51 {
+ if y + h > limit_y {
+ final_h = (limit_y - y).max(0.0);
+ }
+ }
+ widget.set_rect(x, y, w, final_h);
} else {
widget.set_rect(-1000.0, -1000.0, 0.0, 0.0);
}