diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index ca077a9e567db..20781ef9fb1b9 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -433,14 +433,20 @@ with UI components as a child of an entity without UI components, your UI layout let content_size = Vec2::new(layout.content_size.width, layout.content_size.height); let max_possible_offset = (content_size - layout_size).max(Vec2::ZERO); - let clamped_scroll_position = scroll_position.clamp(Vec2::ZERO, max_possible_offset); + let clamped_scroll_position = scroll_position.clamp( + Vec2::ZERO, + max_possible_offset * inverse_target_scale_factor, + ); if clamped_scroll_position != scroll_position { commands .entity(entity) - .insert(ScrollPosition::from(&clamped_scroll_position)); + .insert(ScrollPosition::from(clamped_scroll_position)); } + let physical_scroll_position = + (clamped_scroll_position / inverse_target_scale_factor).round(); + for child_uinode in ui_children.iter_ui_children(entity) { update_uinode_geometry_recursive( commands, @@ -451,7 +457,7 @@ with UI components as a child of an entity without UI components, your UI layout ui_children, inverse_target_scale_factor, layout_size, - clamped_scroll_position, + physical_scroll_position, ); } } diff --git a/crates/bevy_ui/src/ui_node.rs b/crates/bevy_ui/src/ui_node.rs index b35bf42dfad9c..594ce2b861091 100644 --- a/crates/bevy_ui/src/ui_node.rs +++ b/crates/bevy_ui/src/ui_node.rs @@ -238,9 +238,9 @@ impl Default for ComputedNode { #[derive(Component, Debug, Clone, Reflect)] #[reflect(Component, Default)] pub struct ScrollPosition { - /// How far across the node is scrolled, in pixels. (0 = not scrolled / scrolled to right) + /// How far across the node is scrolled, in logical pixels. (0 = not scrolled / scrolled to right) pub offset_x: f32, - /// How far down the node is scrolled, in pixels. (0 = not scrolled / scrolled to top) + /// How far down the node is scrolled, in logical pixels. (0 = not scrolled / scrolled to top) pub offset_y: f32, } @@ -263,8 +263,8 @@ impl From<&ScrollPosition> for Vec2 { } } -impl From<&Vec2> for ScrollPosition { - fn from(vec: &Vec2) -> Self { +impl From for ScrollPosition { + fn from(vec: Vec2) -> Self { ScrollPosition { offset_x: vec.x, offset_y: vec.y,