-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[bevy_ui/layout] Make fields private in UiSurface #13359
Open
StrikeForceZero
wants to merge
4
commits into
bevyengine:main
Choose a base branch
from
StrikeForceZero:dev/bevy_ui/ui_surface_make_fields_private
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,000
−202
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b699e81
#12803 Changes (squashed)
StrikeForceZero 90afc38
#12804 changed Update internal mappings (squashed)
StrikeForceZero 73459f5
Make UiSurface fields private
StrikeForceZero 8b3f47c
Move debug print into UiSurface to access private fields
StrikeForceZero 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 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 |
---|---|---|
@@ -1,92 +1,17 @@ | ||
use std::fmt::Write; | ||
|
||
use taffy::{NodeId, TraversePartialTree}; | ||
|
||
use bevy_ecs::prelude::Entity; | ||
use bevy_utils::HashMap; | ||
|
||
use crate::layout::ui_surface::UiSurface; | ||
|
||
/// Prints a debug representation of the computed layout of the UI layout tree for each window. | ||
/// Prints a debug representation of the computed layout of the UI layout tree for each camera. | ||
#[deprecated( | ||
since = "0.13.3", | ||
note = "use `ui_surface.ui_layout_tree_debug_string()` instead" | ||
)] | ||
pub fn print_ui_layout_tree(ui_surface: &UiSurface) { | ||
let taffy_to_entity: HashMap<NodeId, Entity> = ui_surface | ||
.entity_to_taffy | ||
.iter() | ||
.map(|(entity, node)| (*node, *entity)) | ||
.collect(); | ||
for (&entity, roots) in &ui_surface.camera_roots { | ||
let mut out = String::new(); | ||
for root in roots { | ||
print_node( | ||
ui_surface, | ||
&taffy_to_entity, | ||
entity, | ||
root.implicit_viewport_node, | ||
false, | ||
String::new(), | ||
&mut out, | ||
); | ||
let debug_layout_tree = match ui_surface.ui_layout_tree_debug_string() { | ||
Ok(output) => output, | ||
Err(err) => { | ||
bevy_utils::tracing::error!("Failed to print ui layout tree: {err}"); | ||
return; | ||
} | ||
bevy_utils::tracing::info!("Layout tree for camera entity: {entity:?}\n{out}"); | ||
} | ||
} | ||
|
||
/// Recursively navigates the layout tree printing each node's information. | ||
fn print_node( | ||
ui_surface: &UiSurface, | ||
taffy_to_entity: &HashMap<NodeId, Entity>, | ||
entity: Entity, | ||
node: NodeId, | ||
has_sibling: bool, | ||
lines_string: String, | ||
acc: &mut String, | ||
) { | ||
let tree = &ui_surface.taffy; | ||
let layout = tree.layout(node).unwrap(); | ||
let style = tree.style(node).unwrap(); | ||
|
||
let num_children = tree.child_count(node); | ||
|
||
let display_variant = match (num_children, style.display) { | ||
(_, taffy::style::Display::None) => "NONE", | ||
(0, _) => "LEAF", | ||
(_, taffy::style::Display::Flex) => "FLEX", | ||
(_, taffy::style::Display::Grid) => "GRID", | ||
(_, taffy::style::Display::Block) => "BLOCK", | ||
}; | ||
|
||
let fork_string = if has_sibling { | ||
"├── " | ||
} else { | ||
"└── " | ||
}; | ||
writeln!( | ||
acc, | ||
"{lines}{fork} {display} [x: {x:<4} y: {y:<4} width: {width:<4} height: {height:<4}] ({entity:?}) {measured}", | ||
lines = lines_string, | ||
fork = fork_string, | ||
display = display_variant, | ||
x = layout.location.x, | ||
y = layout.location.y, | ||
width = layout.size.width, | ||
height = layout.size.height, | ||
measured = if tree.get_node_context(node).is_some() { "measured" } else { "" } | ||
).ok(); | ||
let bar = if has_sibling { "│ " } else { " " }; | ||
let new_string = lines_string + bar; | ||
|
||
// Recurse into children | ||
for (index, child_node) in tree.children(node).unwrap().iter().enumerate() { | ||
let has_sibling = index < num_children - 1; | ||
let child_entity = taffy_to_entity.get(child_node).unwrap(); | ||
print_node( | ||
ui_surface, | ||
taffy_to_entity, | ||
*child_entity, | ||
*child_node, | ||
has_sibling, | ||
new_string.clone(), | ||
acc, | ||
); | ||
} | ||
bevy_utils::tracing::info!("{debug_layout_tree}"); | ||
} |
Oops, something went wrong.
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.
see: #13359 (comment)
If we leave
ui_layout_tree_debug_string
inUiSurface
then this function should retain the deprecation notice so it can be removed later.