git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commite1d30ca126e00b8004801afd93979ce95cd430eb
parentf8ec309b8a
authorLucas Galante <[email protected]>
date2026-06-25 14:42
Fix cce-ui compilation and pointer comparison warnings for scrollbar

 src/context.rs               | 38 +++++++++++++++++++++++++++++++++++---
 src/widget/container/page.rs | 17 ++++-------------
 2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/src/context.rs b/src/context.rs
index 14314d4..a618bd0 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -1,5 +1,5 @@
 use std::collections::HashMap;
-use crate::widget::{Element, WidgetId, LayoutTree, Key, MouseButton, ElementState, Event};
+use crate::widget::{Element, WidgetId, LayoutTree, Key, MouseButton, ElementState, Event, ScrollBar};
 use crate::widget::core::hover_animation::HoverState;
 use crate::widget::core::context_menu::ContextMenuState;
 
@@ -76,7 +76,23 @@ impl UiContext {
             match event {
                 Event::PointerMove { .. } | Event::Tick(_) => {
                     for child in children.into_iter().rev() {
-                        if self.propagate_event(event, child) {
+                        let mut adjusted_event = event.clone();
+                        if (*root).is_page() {
+                            if let Some(page) = (*root).as_any().downcast_ref::<crate::widget::Page>() {
+                                let sb_ptr = &page.scroll_bar as *const ScrollBar as *mut ScrollBar as *mut (dyn Element + 'static);
+                                if std::ptr::addr_eq(child, sb_ptr) {
+                                    match &mut adjusted_event {
+                                        Event::PointerMove { y, .. }
+                                        | Event::MouseButton { y, .. }
+                                        | Event::MouseWheel { y, .. } => {
+                                            *y -= page.scroll_y;
+                                        }
+                                        _ => {}
+                                    }
+                                }
+                            }
+                        }
+                        if self.propagate_event(&adjusted_event, child) {
                             handled = true;
                         }
                     }
@@ -87,7 +103,23 @@ impl UiContext {
                 }
                 _ => {
                     for child in children.into_iter().rev() {
-                        if self.propagate_event(event, child) {
+                        let mut adjusted_event = event.clone();
+                        if (*root).is_page() {
+                            if let Some(page) = (*root).as_any().downcast_ref::<crate::widget::Page>() {
+                                let sb_ptr = &page.scroll_bar as *const ScrollBar as *mut ScrollBar as *mut (dyn Element + 'static);
+                                if std::ptr::addr_eq(child, sb_ptr) {
+                                    match &mut adjusted_event {
+                                        Event::PointerMove { y, .. }
+                                        | Event::MouseButton { y, .. }
+                                        | Event::MouseWheel { y, .. } => {
+                                            *y -= page.scroll_y;
+                                        }
+                                        _ => {}
+                                    }
+                                }
+                            }
+                        }
+                        if self.propagate_event(&adjusted_event, child) {
                             return true;
                         }
                     }
diff --git a/src/widget/container/page.rs b/src/widget/container/page.rs
index e5f16bf..158eae5 100644
--- a/src/widget/container/page.rs
+++ b/src/widget/container/page.rs
@@ -180,10 +180,10 @@ impl Element for Page {
         if !self.visible {
             return;
         }
-        let content_h = self.layout.layout(x, y, w, h, &self.base.children);
-        self.content_h = content_h;
+        let layout_content_h = self.layout.layout(x, y, w, h, &self.base.children);
+        self.content_h = self.content_h.max(layout_content_h);
 
-        let max_scroll = (content_h - h).max(0.0);
+        let max_scroll = (self.content_h - h).max(0.0);
         self.scroll_y = self.scroll_y.clamp(0.0, max_scroll);
 
         // Position the scroll bar
@@ -191,19 +191,10 @@ impl Element for Page {
         let sb_padding = 2.0;
         let sb_x = x + w - sb_w - sb_padding;
         self.scroll_bar.set_rect(sb_x, y + 4.0, sb_w, h - 8.0);
-        self.scroll_bar.update(self.scroll_y, content_h, h);
+        self.scroll_bar.update(self.scroll_y, self.content_h, h);
         
         let self_ptr = self as *mut Page as *mut (dyn Element + 'static);
         self.scroll_bar.parent = Some(self_ptr);
-
-        if self.scroll_y > 0.0 {
-            // Apply scroll offset to children
-            for &child_ptr in &self.base.children {
-                let child = unsafe { &mut *child_ptr };
-                let (cx, cy, cw, ch) = child.rect();
-                child.set_rect(cx, cy - self.scroll_y, cw, ch);
-            }
-        }
     }
 
     fn color(&self) -> [f32; 4] {