From 8d143e3ed8ccba37d684f47aaf25617efc0c2217 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Mon, 9 Sep 2024 23:35:29 +0100 Subject: [PATCH] ui material node border calculations fix (#15119) # Objective Fixes #15115 ## Solution Retrieve the size of the node's parent in a separate query and base percentage border values on the parent node's width (or the width of the viewport in the case of root nodes). --- crates/bevy_ui/src/render/ui_material_pipeline.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/render/ui_material_pipeline.rs b/crates/bevy_ui/src/render/ui_material_pipeline.rs index ef81d3c33ff1d..1a3cf489ac9be 100644 --- a/crates/bevy_ui/src/render/ui_material_pipeline.rs +++ b/crates/bevy_ui/src/render/ui_material_pipeline.rs @@ -8,6 +8,7 @@ use bevy_ecs::{ system::lifetimeless::{Read, SRes}, system::*, }; +use bevy_hierarchy::Parent; use bevy_math::{FloatOrd, Mat4, Rect, Vec2, Vec4Swizzles}; use bevy_render::{ extract_component::ExtractComponentPlugin, @@ -352,6 +353,7 @@ impl Default for ExtractedUiMaterialNodes { } } +#[allow(clippy::too_many_arguments)] pub fn extract_ui_material_nodes( mut extracted_uinodes: ResMut>, materials: Extract>>, @@ -367,12 +369,14 @@ pub fn extract_ui_material_nodes( &ViewVisibility, Option<&CalculatedClip>, Option<&TargetCamera>, + Option<&Parent>, ), Without, >, >, windows: Extract>>, ui_scale: Extract>, + node_query: Extract>, ) { let ui_logical_viewport_size = windows .get_single() @@ -385,7 +389,7 @@ pub fn extract_ui_material_nodes( // If there is only one camera, we use it as default let default_single_camera = default_ui_camera.get(); - for (entity, uinode, style, transform, handle, view_visibility, clip, camera) in + for (entity, uinode, style, transform, handle, view_visibility, clip, camera, maybe_parent) in uinode_query.iter() { let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_single_camera) else { @@ -404,7 +408,11 @@ pub fn extract_ui_material_nodes( // Both vertical and horizontal percentage border values are calculated based on the width of the parent node // - let parent_width = uinode.size().x; + let parent_width = maybe_parent + .and_then(|parent| node_query.get(parent.get()).ok()) + .map(|parent_node| parent_node.size().x) + .unwrap_or(ui_logical_viewport_size.x); + let left = resolve_border_thickness(style.border.left, parent_width, ui_logical_viewport_size) / uinode.size().x;