Skip to content

Commit

Permalink
Remove viewport offset from flex module
Browse files Browse the repository at this point in the history
  • Loading branch information
oceantume committed Sep 11, 2022
1 parent f8240c9 commit 108c2e2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions crates/bevy_ui/src/flex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ pub fn flex_node_system(

// update root nodes
for flex_root in &flex_roots {
let physical_size = flex_root.physical_rect.1 - flex_root.physical_rect.0;
flex_surface.update_root(&flex_root.entity, &physical_size);
flex_surface.update_root(&flex_root.entity, &flex_root.physical_size);
}

// TODO: check individual roots for changed scaling factor instead of updating all of them.
Expand Down Expand Up @@ -280,7 +279,6 @@ pub fn flex_node_system(
&mut node_transform_query,
&full_children_query,
flex_root.scaling_factor,
&flex_root.physical_rect.0,
None,
&flex_root.entity,
);
Expand Down Expand Up @@ -335,15 +333,13 @@ fn update_node_transforms_recursively(
node_transform_query: &mut Query<(Entity, &mut Node, &mut Transform)>,
children_query: &Query<&Children, With<Node>>,
scaling_factor: f64,
position_offset: &UVec2,
parent: Option<&Entity>,
entity: &Entity,
) {
update_node_transform(
flex_surface,
node_transform_query,
scaling_factor,
position_offset,
parent,
entity,
);
Expand All @@ -356,7 +352,6 @@ fn update_node_transforms_recursively(
node_transform_query,
children_query,
scaling_factor,
position_offset,
Some(entity),
child,
);
Expand All @@ -369,7 +364,6 @@ fn update_node_transform(
flex_surface: &FlexSurface,
node_transform_query: &mut Query<(Entity, &mut Node, &mut Transform)>,
scaling_factor: f64,
position_offset: &UVec2,
parent: Option<&Entity>,
entity: &Entity,
) {
Expand All @@ -388,10 +382,8 @@ fn update_node_transform(
node.size = new_size;
}
let mut new_position = transform.translation;
new_position.x =
to_logical(layout.location.x + position_offset.x as f32 + layout.size.width / 2.0);
new_position.y =
to_logical(layout.location.y + position_offset.y as f32 + layout.size.height / 2.0);
new_position.x = to_logical(layout.location.x + layout.size.width / 2.0);
new_position.y = to_logical(layout.location.y + layout.size.height / 2.0);
if let Some(parent) = parent {
if let Ok(parent_layout) = flex_surface.get_layout(*parent) {
new_position.x -= to_logical(parent_layout.size.width / 2.0);
Expand All @@ -408,7 +400,7 @@ fn update_node_transform(
struct FlexRoot {
entity: Entity,
scaling_factor: f64,
physical_rect: (UVec2, UVec2),
physical_size: UVec2,
}

/// Returns the list of roots for all ui trees with their physical rect and scaling factor.
Expand All @@ -430,15 +422,15 @@ fn get_flex_roots(
entity,
scaling_factor: camera.target_scaling_factor().unwrap_or(1.0) * ui_scale.scale,
// TODO: make sure this won't explode and it makes sense in system ordering.
physical_rect: camera.physical_viewport_rect().unwrap_or((UVec2::default(), UVec2::default())),
physical_size: camera.physical_viewport_size().unwrap_or_default(),
})
.or_else(|| {
windows.get_primary().map(|window| FlexRoot {
entity,
scaling_factor: window.scale_factor() * ui_scale.scale,
physical_rect: (
UVec2::new(0, 0),
UVec2::new(window.physical_width(), window.physical_height()),
physical_size: UVec2::new(
window.physical_width(),
window.physical_height(),
),
})
})
Expand Down

0 comments on commit 108c2e2

Please sign in to comment.