Skip to content

Commit

Permalink
Using crate::sys Types
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoISnoTarget committed Jun 21, 2024
1 parent c879ec4 commit b0b9237
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/style/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use crate::geometry::{Rect, Size};
use crate::style_helpers::{FromLength, FromPercent, TaffyAuto, TaffyMaxContent, TaffyMinContent, TaffyZero};
use crate::sys::{Arc, Box, Vec};
use crate::util::sys::abs;
use core::ops::Neg;
use num_traits::{Signed, Zero};
use std::ops::Neg;
use std::sync::Arc;

/// A unit of linear measurement
///
Expand Down Expand Up @@ -207,6 +207,11 @@ impl Calc {
self.0.resolve(percentage_length)
}
}
impl From<CalcNode> for Calc {
fn from(value: CalcNode) -> Self {
Self(Arc::new(value))
}
}

#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand All @@ -222,7 +227,7 @@ pub enum CalcNode {
Min(Vec<CalcNode>),
Max(Vec<CalcNode>),

Clamp { min: Box<CalcNode>, center: Box<CalcNode>, max: Box<CalcNode> },
Clamp { min: Box<CalcNode>, value: Box<CalcNode>, max: Box<CalcNode> },
Round { strategy: RoundingStrategy, value: Box<CalcNode>, interval: Box<CalcNode> },
}
impl CalcNode {
Expand All @@ -240,7 +245,7 @@ impl CalcNode {
CalcNode::Max(nodes) => {
nodes.iter().map(|node| node.resolve(percentage_length)).reduce(f32::max).unwrap_or_default()
}
CalcNode::Clamp { min, center: value, max } => {
CalcNode::Clamp { min, value, max } => {
let min = min.resolve(percentage_length);
let value = value.resolve(percentage_length);
let max = max.resolve(percentage_length);
Expand Down Expand Up @@ -326,9 +331,10 @@ impl CalcNode {
}
}
}

fn into_calc(self) -> Calc {
Calc(Arc::new(self))
}
impl From<LengthPercentage> for CalcNode {
fn from(value: LengthPercentage) -> Self {
CalcNode::Leaf(value)
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/util/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ mod std {
Vec::with_capacity(capacity)
}

pub(crate) type Box<A> = std::boxed::Box<A>;
pub(crate) type Arc<A> = std::sync::Arc<A>;

/// Rounds to the nearest whole number
#[must_use]
#[inline(always)]
Expand Down Expand Up @@ -76,6 +79,9 @@ mod alloc {
Vec::with_capacity(capacity)
}

pub(crate) type Box<A> = alloc::boxed::Box<A>;
pub(crate) type Arc<A> = alloc::sync::Arc<A>;

/// Rounds to the nearest whole number
#[must_use]
#[inline(always)]
Expand Down

0 comments on commit b0b9237

Please sign in to comment.