Skip to content
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] Replace unwrap, expect, and panic with Result #12805

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d2bdbc6
Promote UiSurface to mod
StrikeForceZero Mar 29, 2024
57d3261
Update visibility for ui_surface, RootNodePair, and UiSurface
StrikeForceZero Mar 29, 2024
9353506
Optimize imports in bevy_ui/layout
StrikeForceZero Mar 29, 2024
0ab5686
Remove unused imports in bevy_ui/layout
StrikeForceZero Mar 29, 2024
042b21c
Apply rustfmt in bevy_ui/layout
StrikeForceZero Mar 29, 2024
be7e6a2
Simplify GlobalTransform update in bevy_ui/layout tests
StrikeForceZero Mar 29, 2024
d761918
Add missing asserts and Debug fields in UiSurface from #12268 and #12698
StrikeForceZero Mar 29, 2024
9715779
Widen type for parameter children in UiSurface::update_children
StrikeForceZero Mar 29, 2024
d65c0b2
Add tests for bevy_ui/layout/ui_surface
StrikeForceZero Mar 29, 2024
c730631
Rename RootNodePair to RootNodeData
StrikeForceZero Mar 29, 2024
32ee4aa
Rename camera_id to camera_entity
StrikeForceZero Mar 29, 2024
207067c
Extract default viewport style into inline fn
StrikeForceZero Mar 29, 2024
54ca220
Deprecate user_root_node in RootNodeData
StrikeForceZero Mar 29, 2024
2d93de3
Implement updated map structure in UiSurface
StrikeForceZero Mar 29, 2024
28b2443
Remove user_root_node field in favor of using entity_to_taffy
StrikeForceZero Mar 30, 2024
94d258e
Apply rustfmt in bevy_ui/layout
StrikeForceZero Mar 30, 2024
22c3d53
Expand tests to cover different methods of despawn
StrikeForceZero Mar 30, 2024
ca744e0
Add support demoting root nodes into normal ui nodes
StrikeForceZero Mar 30, 2024
3cdf374
Add test for promoting normal ui nodes into root nodes
StrikeForceZero Mar 30, 2024
117177d
Add explicit taffy node counts to tests
StrikeForceZero Mar 30, 2024
4b54585
Use mark_root_node_as_orphaned
StrikeForceZero Mar 30, 2024
9134921
Use replace_camera_association to reduce redundant code
StrikeForceZero Mar 30, 2024
2dc4e2a
Update documentation
StrikeForceZero Mar 30, 2024
965c92b
Fix promote_ui_node, add a test, and set to only be in cfg(test)
StrikeForceZero Mar 30, 2024
2f165ee
Remove duplicated / dead code
StrikeForceZero Mar 30, 2024
9e75434
Rename DUMMY_LAYOUT_CONTEXT to TEST_LAYOUT_CONTEXT
StrikeForceZero Mar 30, 2024
d7d4836
Fix placement of attribute
StrikeForceZero Mar 30, 2024
e3aa0a3
Apply rustfmt in bevy_ui/layout
StrikeForceZero Mar 30, 2024
ce722db
Make missing root_node_data in compute_camera_layout an error
StrikeForceZero Mar 30, 2024
0003fc3
Add/update documentation for UiSurface
StrikeForceZero Mar 30, 2024
64370bb
Remove message from unreachable!
StrikeForceZero Mar 30, 2024
704f3ef
Apply rustfmt in bevy_ui/layout/debug
StrikeForceZero Mar 30, 2024
f9c16ef
Replace unwrap, expect, panic!, unreachable! with Result
StrikeForceZero Mar 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions crates/bevy_ui/src/layout/debug.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
use crate::UiSurface;
use bevy_ecs::prelude::Entity;
use bevy_utils::HashMap;
use std::fmt::Write;

use taffy::prelude::Node;
use taffy::tree::LayoutTree;

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.
pub fn print_ui_layout_tree(ui_surface: &UiSurface) {
let taffy_to_entity: HashMap<Node, 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 {
.map(|(&ui_entity, &taffy_node)| (taffy_node, ui_entity))
.collect::<HashMap<Node, Entity>>();
for (&camera_entity, root_node_set) in ui_surface.camera_root_nodes.iter() {
bevy_utils::tracing::info!("Layout tree for camera entity: {camera_entity}");
for &root_node_entity in root_node_set.iter() {
let Some(implicit_viewport_node) = ui_surface
.root_node_data
.get(&root_node_entity)
.map(|rnd| rnd.implicit_viewport_node)
else {
continue;
};
let mut out = String::new();
print_node(
ui_surface,
&taffy_to_entity,
entity,
root.implicit_viewport_node,
camera_entity,
implicit_viewport_node,
false,
String::new(),
&mut out,
);

bevy_utils::tracing::info!("{out}");
}
bevy_utils::tracing::info!("Layout tree for camera entity: {entity:?}\n{out}");
}
}

Expand Down
Loading
Loading