Constify ComputedNode (#16134)
# Objective Make all the methods and associated functions belonging to `ComputedNode` const. ## Solution Constify (except for `inner_radius` which uses non-const `min` and `max`). --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
f005a96dd4
commit
dae39aceb5
@ -62,6 +62,7 @@ impl ComputedNode {
|
|||||||
/// The calculated node size as width and height in logical pixels.
|
/// The calculated node size as width and height in logical pixels.
|
||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
|
#[inline]
|
||||||
pub const fn size(&self) -> Vec2 {
|
pub const fn size(&self) -> Vec2 {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
@ -69,8 +70,8 @@ impl ComputedNode {
|
|||||||
/// Check if the node is empty.
|
/// Check if the node is empty.
|
||||||
/// A node is considered empty if it has a zero or negative extent along either of its axes.
|
/// A node is considered empty if it has a zero or negative extent along either of its axes.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_empty(&self) -> bool {
|
pub const fn is_empty(&self) -> bool {
|
||||||
self.size().cmple(Vec2::ZERO).any()
|
self.size.x <= 0. || self.size.y <= 0.
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The order of the node in the UI layout.
|
/// The order of the node in the UI layout.
|
||||||
@ -84,6 +85,7 @@ impl ComputedNode {
|
|||||||
/// The calculated node size as width and height in logical pixels before rounding.
|
/// The calculated node size as width and height in logical pixels before rounding.
|
||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
|
#[inline]
|
||||||
pub const fn unrounded_size(&self) -> Vec2 {
|
pub const fn unrounded_size(&self) -> Vec2 {
|
||||||
self.unrounded_size
|
self.unrounded_size
|
||||||
}
|
}
|
||||||
@ -93,7 +95,7 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outline_width(&self) -> f32 {
|
pub const fn outline_width(&self) -> f32 {
|
||||||
self.outline_width
|
self.outline_width
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outline_offset(&self) -> f32 {
|
pub const fn outline_offset(&self) -> f32 {
|
||||||
self.outline_offset
|
self.outline_offset
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,8 +111,9 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outlined_node_size(&self) -> Vec2 {
|
pub const fn outlined_node_size(&self) -> Vec2 {
|
||||||
self.size() + 2. * (self.outline_offset + self.outline_width)
|
let offset = 2. * (self.outline_offset + self.outline_width);
|
||||||
|
Vec2::new(self.size.x + offset, self.size.y + offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the border radius for each corner of the outline
|
/// Returns the border radius for each corner of the outline
|
||||||
@ -119,20 +122,20 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn outline_radius(&self) -> ResolvedBorderRadius {
|
pub const fn outline_radius(&self) -> ResolvedBorderRadius {
|
||||||
let outer_distance = self.outline_width + self.outline_offset;
|
let outer_distance = self.outline_width + self.outline_offset;
|
||||||
let compute_radius = |radius| {
|
const fn compute_radius(radius: f32, outer_distance: f32) -> f32 {
|
||||||
if radius > 0. {
|
if radius > 0. {
|
||||||
radius + outer_distance
|
radius + outer_distance
|
||||||
} else {
|
} else {
|
||||||
0.
|
0.
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
ResolvedBorderRadius {
|
ResolvedBorderRadius {
|
||||||
top_left: compute_radius(self.border_radius.top_left),
|
top_left: compute_radius(self.border_radius.top_left, outer_distance),
|
||||||
top_right: compute_radius(self.border_radius.top_right),
|
top_right: compute_radius(self.border_radius.top_right, outer_distance),
|
||||||
bottom_left: compute_radius(self.border_radius.bottom_left),
|
bottom_left: compute_radius(self.border_radius.bottom_left, outer_distance),
|
||||||
bottom_right: compute_radius(self.border_radius.bottom_right),
|
bottom_right: compute_radius(self.border_radius.bottom_right, outer_distance),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +143,7 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn border(&self) -> BorderRect {
|
pub const fn border(&self) -> BorderRect {
|
||||||
self.border
|
self.border
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +151,7 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn border_radius(&self) -> ResolvedBorderRadius {
|
pub const fn border_radius(&self) -> ResolvedBorderRadius {
|
||||||
self.border_radius
|
self.border_radius
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,13 +181,13 @@ impl ComputedNode {
|
|||||||
///
|
///
|
||||||
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
/// Automatically calculated by [`super::layout::ui_layout_system`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn padding(&self) -> BorderRect {
|
pub const fn padding(&self) -> BorderRect {
|
||||||
self.padding
|
self.padding
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the combined inset on each edge including both padding and border thickness in logical pixels.
|
/// Returns the combined inset on each edge including both padding and border thickness in logical pixels.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn content_inset(&self) -> BorderRect {
|
pub const fn content_inset(&self) -> BorderRect {
|
||||||
BorderRect {
|
BorderRect {
|
||||||
left: self.border.left + self.padding.left,
|
left: self.border.left + self.padding.left,
|
||||||
right: self.border.right + self.padding.right,
|
right: self.border.right + self.padding.right,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user