From 8e0e47d9d16215b19c8a36fb6d839c58f0bdf2bc Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Fri, 11 Jul 2025 16:39:14 +0100 Subject: [PATCH] added scroll offset to `ComputedNode` and update it in `ui_layout_system` --- crates/bevy_ui/src/layout/mod.rs | 2 ++ crates/bevy_ui/src/ui_node.rs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index 287c9f958d..f5b1412386 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -333,6 +333,8 @@ with UI components as a child of an entity without UI components, your UI layout let physical_scroll_position = clamped_scroll_position.floor(); + node.bypass_change_detection().scroll_offset = physical_scroll_position; + for child_uinode in ui_children.iter_ui_children(entity) { update_uinode_geometry_recursive( commands, diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index 6ffedfb45f..b520675eca 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -46,6 +46,10 @@ pub struct ComputedNode { /// /// Automatically calculated by [`super::layout::ui_layout_system`]. pub scrollbar_size: Vec2, + /// Offset of scrolled content + /// + /// Automatically calculated by [`super::layout::ui_layout_system`]. + pub scroll_offset: Vec2, /// The width of this node's outline. /// If this value is `Auto`, negative or `0.` then no outline will be rendered. /// Outline updates bypass change detection. @@ -310,6 +314,7 @@ impl ComputedNode { size: Vec2::ZERO, content_size: Vec2::ZERO, scrollbar_size: Vec2::ZERO, + scroll_offset: Vec2::ZERO, outline_width: 0., outline_offset: 0., unrounded_size: Vec2::ZERO,