Skip to content

Commit 1add4bf

Browse files
authored
Rename ComputedNode::calculated_size to size (bevyengine#16131)
# Objective Remove `calculated_` from the name `ComputedNode::calculated_size` as redundant, It's obvious from context that it's the resolved size value and it's inconsistant since none of other fields of `ComputedNode` have a `calculated_` prefix. ## Alternatives Rename all the fields of `ComputedNode` to `calculated_*`, this seems worse.
1 parent 33c4945 commit 1add4bf

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

crates/bevy_ui/src/accessibility.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fn calc_bounds(
5353
let bounds = Rect::new(
5454
translation.x.into(),
5555
translation.y.into(),
56-
(translation.x + node.calculated_size.x).into(),
57-
(translation.y + node.calculated_size.y).into(),
56+
(translation.x + node.size.x).into(),
57+
(translation.y + node.size.y).into(),
5858
);
5959
accessible.set_bounds(bounds);
6060
}

crates/bevy_ui/src/layout/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ with UI components as a child of an entity without UI components, your UI layout
359359
+ 0.5 * (rounded_size - parent_size);
360360

361361
// only trigger change detection when the new values are different
362-
if node.calculated_size != rounded_size || node.unrounded_size != layout_size {
363-
node.calculated_size = rounded_size;
362+
if node.size != rounded_size || node.unrounded_size != layout_size {
363+
node.size = rounded_size;
364364
node.unrounded_size = layout_size;
365365
}
366366

@@ -374,12 +374,12 @@ with UI components as a child of an entity without UI components, your UI layout
374374
node.bypass_change_detection().border = taffy_rect_to_border_rect(layout.border);
375375
node.bypass_change_detection().padding = taffy_rect_to_border_rect(layout.padding);
376376

377-
let viewport_size = root_size.unwrap_or(node.calculated_size);
377+
let viewport_size = root_size.unwrap_or(node.size);
378378

379379
if let Some(border_radius) = maybe_border_radius {
380380
// We don't trigger change detection for changes to border radius
381381
node.bypass_change_detection().border_radius =
382-
border_radius.resolve(node.calculated_size, viewport_size);
382+
border_radius.resolve(node.size, viewport_size);
383383
}
384384

385385
if let Some(outline) = maybe_outline {
@@ -1129,9 +1129,9 @@ mod tests {
11291129
ui_schedule.run(&mut world);
11301130
let width_sum: f32 = children
11311131
.iter()
1132-
.map(|child| world.get::<ComputedNode>(*child).unwrap().calculated_size.x)
1132+
.map(|child| world.get::<ComputedNode>(*child).unwrap().size.x)
11331133
.sum();
1134-
let parent_width = world.get::<ComputedNode>(parent).unwrap().calculated_size.x;
1134+
let parent_width = world.get::<ComputedNode>(parent).unwrap().size.x;
11351135
assert!((width_sum - parent_width).abs() < 0.001);
11361136
assert!((width_sum - 320.).abs() <= 1.);
11371137
s += r;

crates/bevy_ui/src/render/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ pub fn extract_uinode_background_colors(
282282
color: background_color.0.into(),
283283
rect: Rect {
284284
min: Vec2::ZERO,
285-
max: uinode.calculated_size,
285+
max: uinode.size,
286286
},
287287
clip: clip.map(|clip| clip.clip),
288288
image: AssetId::default(),
@@ -351,7 +351,7 @@ pub fn extract_uinode_images(
351351
let mut rect = match (atlas_rect, image.rect) {
352352
(None, None) => Rect {
353353
min: Vec2::ZERO,
354-
max: uinode.calculated_size,
354+
max: uinode.size,
355355
},
356356
(None, Some(image_rect)) => image_rect,
357357
(Some(atlas_rect), None) => atlas_rect,

crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ pub fn extract_ui_texture_slices(
307307
color: image.color.into(),
308308
rect: Rect {
309309
min: Vec2::ZERO,
310-
max: uinode.calculated_size,
310+
max: uinode.size,
311311
},
312312
clip: clip.map(|clip| clip.clip),
313313
image: image.image.id(),

crates/bevy_ui/src/ui_node.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct ComputedNode {
2525
/// The size of the node as width and height in logical pixels
2626
///
2727
/// automatically calculated by [`super::layout::ui_layout_system`]
28-
pub(crate) calculated_size: Vec2,
28+
pub(crate) size: Vec2,
2929
/// The width of this node's outline.
3030
/// If this value is `Auto`, negative or `0.` then no outline will be rendered.
3131
/// Outline updates bypass change detection.
@@ -63,7 +63,7 @@ impl ComputedNode {
6363
///
6464
/// Automatically calculated by [`super::layout::ui_layout_system`].
6565
pub const fn size(&self) -> Vec2 {
66-
self.calculated_size
66+
self.size
6767
}
6868

6969
/// Check if the node is empty.
@@ -197,7 +197,7 @@ impl ComputedNode {
197197
impl ComputedNode {
198198
pub const DEFAULT: Self = Self {
199199
stack_index: 0,
200-
calculated_size: Vec2::ZERO,
200+
size: Vec2::ZERO,
201201
outline_width: 0.,
202202
outline_offset: 0.,
203203
unrounded_size: Vec2::ZERO,

0 commit comments

Comments
 (0)