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
af24a871c3
commit
819ecc33f6
@ -64,6 +64,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
|
||||||
}
|
}
|
||||||
@ -71,8 +72,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.
|
||||||
@ -86,6 +87,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
|
||||||
}
|
}
|
||||||
@ -95,7 +97,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +105,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +113,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
|
||||||
@ -121,20 +124,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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +145,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +153,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,13 +183,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