-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix various bugs with UI rounded borders #13523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e88a1f1
fix sdf calculation
hymm 34b3463
rework antialiasing
hymm 6aed9b3
fix antialiasing
hymm 518bc5c
draw background with internal instead of external
hymm ba14dd6
use width in background and image nodes to clip
hymm fc0b74d
revert change, not needed with antialiasing change
hymm 0485005
cleanup
hymm 564bd26
clippy
hymm 656dd3a
Fix comment style
alice-i-cecile File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,8 +199,11 @@ pub fn extract_uinode_background_colors( | |
Option<&TargetCamera>, | ||
&BackgroundColor, | ||
Option<&BorderRadius>, | ||
&Style, | ||
Option<&Parent>, | ||
)>, | ||
>, | ||
node_query: Extract<Query<&Node>>, | ||
) { | ||
for ( | ||
entity, | ||
|
@@ -211,6 +214,8 @@ pub fn extract_uinode_background_colors( | |
camera, | ||
background_color, | ||
border_radius, | ||
style, | ||
parent, | ||
) in &uinode_query | ||
{ | ||
let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) | ||
|
@@ -232,6 +237,23 @@ pub fn extract_uinode_background_colors( | |
// so we have to divide by `UiScale` to get the size of the UI viewport. | ||
/ ui_scale.0; | ||
|
||
// Both vertical and horizontal percentage border values are calculated based on the width of the parent node | ||
// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-width> | ||
let parent_width = 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); | ||
let right = | ||
resolve_border_thickness(style.border.right, parent_width, ui_logical_viewport_size); | ||
let top = | ||
resolve_border_thickness(style.border.top, parent_width, ui_logical_viewport_size); | ||
let bottom = | ||
resolve_border_thickness(style.border.bottom, parent_width, ui_logical_viewport_size); | ||
|
||
let border = [left, top, right, bottom]; | ||
Comment on lines
+242
to
+255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of this makes sense and is straightforward to read 👍 |
||
|
||
let border_radius = if let Some(border_radius) = border_radius { | ||
resolve_border_radius( | ||
border_radius, | ||
|
@@ -259,14 +281,15 @@ pub fn extract_uinode_background_colors( | |
flip_x: false, | ||
flip_y: false, | ||
camera_entity, | ||
border: [0.; 4], | ||
border, | ||
border_radius, | ||
node_type: NodeType::Rect, | ||
}, | ||
); | ||
} | ||
} | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn extract_uinode_images( | ||
mut commands: Commands, | ||
mut extracted_uinodes: ResMut<ExtractedUiNodes>, | ||
|
@@ -285,11 +308,25 @@ pub fn extract_uinode_images( | |
Option<&TextureAtlas>, | ||
Option<&ComputedTextureSlices>, | ||
Option<&BorderRadius>, | ||
Option<&Parent>, | ||
&Style, | ||
)>, | ||
>, | ||
node_query: Extract<Query<&Node>>, | ||
) { | ||
for (uinode, transform, view_visibility, clip, camera, image, atlas, slices, border_radius) in | ||
&uinode_query | ||
for ( | ||
uinode, | ||
transform, | ||
view_visibility, | ||
clip, | ||
camera, | ||
image, | ||
atlas, | ||
slices, | ||
border_radius, | ||
parent, | ||
style, | ||
) in &uinode_query | ||
{ | ||
let Some(camera_entity) = camera.map(TargetCamera::entity).or(default_ui_camera.get()) | ||
else { | ||
|
@@ -342,6 +379,23 @@ pub fn extract_uinode_images( | |
// so we have to divide by `UiScale` to get the size of the UI viewport. | ||
/ ui_scale.0; | ||
|
||
// Both vertical and horizontal percentage border values are calculated based on the width of the parent node | ||
// <https://developer.mozilla.org/en-US/docs/Web/CSS/border-width> | ||
let parent_width = 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); | ||
let right = | ||
resolve_border_thickness(style.border.right, parent_width, ui_logical_viewport_size); | ||
let top = | ||
resolve_border_thickness(style.border.top, parent_width, ui_logical_viewport_size); | ||
let bottom = | ||
resolve_border_thickness(style.border.bottom, parent_width, ui_logical_viewport_size); | ||
|
||
let border = [left, top, right, bottom]; | ||
|
||
let border_radius = if let Some(border_radius) = border_radius { | ||
resolve_border_radius( | ||
border_radius, | ||
|
@@ -366,7 +420,7 @@ pub fn extract_uinode_images( | |
flip_x: image.flip_x, | ||
flip_y: image.flip_y, | ||
camera_entity, | ||
border: [0.; 4], | ||
border, | ||
border_radius, | ||
node_type: NodeType::Rect, | ||
}, | ||
|
@@ -513,6 +567,11 @@ pub fn extract_uinode_borders( | |
|
||
let border = [left, top, right, bottom]; | ||
|
||
// don't extract border if no border | ||
if left == 0.0 && top == 0.0 && right == 0.0 && bottom == 0.0 { | ||
continue; | ||
} | ||
|
||
let border_radius = resolve_border_radius( | ||
border_radius, | ||
node.size(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layout and style is a complex topic, having these comments that refers back to source material helps a lot, thanks!