Skip to content

Commit 303953d

Browse files
ickshonpemockersf
authored andcommitted
Rename ComputedNode::calculated_size to size (#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 dfd3d61 commit 303953d

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

crates/bevy_ui/src/accessibility.rs

+2-2
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

+6-6
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub fn extract_uinode_background_colors(
281281
color: background_color.0.into(),
282282
rect: Rect {
283283
min: Vec2::ZERO,
284-
max: uinode.calculated_size,
284+
max: uinode.size,
285285
},
286286
clip: clip.map(|clip| clip.clip),
287287
image: AssetId::default(),
@@ -350,7 +350,7 @@ pub fn extract_uinode_images(
350350
let mut rect = match (atlas_rect, image.rect) {
351351
(None, None) => Rect {
352352
min: Vec2::ZERO,
353-
max: uinode.calculated_size,
353+
max: uinode.size,
354354
},
355355
(None, Some(image_rect)) => image_rect,
356356
(Some(atlas_rect), None) => atlas_rect,

crates/bevy_ui/src/render/ui_texture_slice_pipeline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ pub fn extract_ui_texture_slices(
306306
color: image.color.into(),
307307
rect: Rect {
308308
min: Vec2::ZERO,
309-
max: uinode.calculated_size,
309+
max: uinode.size,
310310
},
311311
clip: clip.map(|clip| clip.clip),
312312
image: image.image.id(),

crates/bevy_ui/src/ui_node.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub struct ComputedNode {
2727
/// The size of the node as width and height in logical pixels
2828
///
2929
/// automatically calculated by [`super::layout::ui_layout_system`]
30-
pub(crate) calculated_size: Vec2,
30+
pub(crate) size: Vec2,
3131
/// The width of this node's outline.
3232
/// If this value is `Auto`, negative or `0.` then no outline will be rendered.
3333
/// Outline updates bypass change detection.
@@ -65,7 +65,7 @@ impl ComputedNode {
6565
///
6666
/// Automatically calculated by [`super::layout::ui_layout_system`].
6767
pub const fn size(&self) -> Vec2 {
68-
self.calculated_size
68+
self.size
6969
}
7070

7171
/// Check if the node is empty.
@@ -199,7 +199,7 @@ impl ComputedNode {
199199
impl ComputedNode {
200200
pub const DEFAULT: Self = Self {
201201
stack_index: 0,
202-
calculated_size: Vec2::ZERO,
202+
size: Vec2::ZERO,
203203
outline_width: 0.,
204204
outline_offset: 0.,
205205
unrounded_size: Vec2::ZERO,

0 commit comments

Comments
 (0)