Introduce a `Units` trait
Signed-off-by: Nico Burns <nico@nicoburns.com>
7bbb03eb96b50247931bc232204d201ef03fa69e · ruwaq Nico Burns · (1 wata ñawpaq) · tayta 7c123d3d5 · kay commitpi sach'ata qhaway
Semántico sayk'uy · 35
examples/custom_tree_owned_partial.rs
examples/custom_tree_owned_unsafe.rs
examples/custom_tree_vec.rs
src/compute/grid/explicit_grid.rs
src/compute/grid/implicit_grid.rs
src/compute/grid/placement.rs
src/compute/grid/types/named.rs
src/compute/grid/util/test_helpers.rs
diff --git a/examples/custom_tree_owned_partial.rs b/examples/custom_tree_owned_partial.rs
index 9019f3b23..58cb71a13 100644
--- a/examples/custom_tree_owned_partial.rs
+++ b/examples/custom_tree_owned_partial.rs
@@ -13,7 +13,7 @@ use common::image::{image_measure_function, ImageContext};
use common::text::{text_measure_function, FontMetrics, TextContext, WritingMode, LOREM_IPSUM};
use taffy::{
compute_cached_layout, compute_flexbox_layout, compute_grid_layout, compute_leaf_layout, compute_root_layout,
- prelude::*, Cache, CacheTree, Layout, Style,
+ prelude::*, Cache, CacheTree, DefaultUnits, Layout, Style,
};
#[derive(Debug, Copy, Clone)]
@@ -138,7 +138,7 @@ impl taffy::LayoutPartialTree for Node {
where
Self: 'a;
- type CustomIdent = String;
+ type Units = DefaultUnits;
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_> {
&self.node_from_id(node_id).style
diff --git a/examples/custom_tree_owned_unsafe.rs b/examples/custom_tree_owned_unsafe.rs
index d6c2856f5..b70386ed1 100644
--- a/examples/custom_tree_owned_unsafe.rs
+++ b/examples/custom_tree_owned_unsafe.rs
@@ -9,7 +9,7 @@ use taffy::tree::Cache;
use taffy::util::print_tree;
use taffy::{
compute_cached_layout, compute_flexbox_layout, compute_grid_layout, compute_leaf_layout, compute_root_layout,
- prelude::*, round_layout, CacheTree,
+ prelude::*, round_layout, CacheTree, DefaultUnits,
};
#[derive(Debug, Copy, Clone)]
@@ -136,7 +136,7 @@ impl LayoutPartialTree for StatelessLayoutTree {
where
Self: 'a;
- type CustomIdent = String;
+ type Units = DefaultUnits;
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_> {
unsafe { &node_from_id(node_id).style }
diff --git a/examples/custom_tree_vec.rs b/examples/custom_tree_vec.rs
index 2683f19cc..a556c8f8f 100644
--- a/examples/custom_tree_vec.rs
+++ b/examples/custom_tree_vec.rs
@@ -7,7 +7,7 @@ use common::text::{text_measure_function, FontMetrics, TextContext, WritingMode,
use taffy::util::print_tree;
use taffy::{
compute_cached_layout, compute_flexbox_layout, compute_grid_layout, compute_leaf_layout, compute_root_layout,
- prelude::*, round_layout, Cache, CacheTree,
+ prelude::*, round_layout, Cache, CacheTree, DefaultUnits,
};
#[derive(Debug, Copy, Clone)]
@@ -139,7 +139,7 @@ impl taffy::TraversePartialTree for Tree {
impl taffy::TraverseTree for Tree {}
impl taffy::LayoutPartialTree for Tree {
- type CustomIdent = String;
+ type Units = DefaultUnits;
type CoreContainerStyle<'a>
= &'a Style
diff --git a/src/compute/grid/explicit_grid.rs b/src/compute/grid/explicit_grid.rs
index 5e5c02aca..812d00294 100644
--- a/src/compute/grid/explicit_grid.rs
+++ b/src/compute/grid/explicit_grid.rs
@@ -323,7 +323,7 @@ mod test {
use crate::compute::grid::util::*;
use crate::geometry::AbsoluteAxis;
use crate::prelude::*;
- use crate::sys::DefaultCheapStr;
+ use crate::DefaultUnits;
#[test]
fn explicit_grid_sizing_no_repeats() {
@@ -352,7 +352,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_exact_fit() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(120.0), height: length(80.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0)])],
@@ -383,7 +383,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_non_exact_fit() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(140.0), height: length(90.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0)])],
@@ -414,7 +414,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_min_size_exact_fit() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
min_size: Size { width: length(120.0), height: length(80.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0)])],
@@ -445,7 +445,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_min_size_non_exact_fit() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
min_size: Size { width: length(140.0), height: length(90.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0)])],
@@ -476,7 +476,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_multiple_repeated_tracks() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(140.0), height: length(100.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0), length(20.0)])],
@@ -507,7 +507,7 @@ mod test {
#[test]
fn explicit_grid_sizing_auto_fill_gap() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(140.0), height: length(100.0) },
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0)])],
@@ -539,7 +539,7 @@ mod test {
#[test]
fn explicit_grid_sizing_no_defined_size() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
grid_template_columns: vec![repeat(AutoFill, vec![length(40.0), percent(0.5), length(20.0)])],
grid_template_rows: vec![repeat(AutoFill, vec![length(20.0)])],
@@ -570,7 +570,7 @@ mod test {
#[test]
fn explicit_grid_sizing_mix_repeated_and_non_repeated() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(140.0), height: length(100.0) },
grid_template_columns: vec![length(20.0), repeat(AutoFill, vec![length(40.0)])],
@@ -602,7 +602,7 @@ mod test {
#[test]
fn explicit_grid_sizing_mix_with_padding() {
use RepetitionCount::AutoFill;
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
size: Size { width: length(120.0), height: length(120.0) },
padding: Rect { left: length(10.0), right: length(10.0), top: length(20.0), bottom: length(20.0) },
@@ -642,7 +642,7 @@ mod test {
let maxpx100 = MaxTrackSizingFunction::from_length(100.0);
// Setup test
- let grid_style: Style<DefaultCheapStr> = Style {
+ let grid_style: Style<DefaultUnits> = Style {
display: Display::Grid,
gap: length(20.0),
grid_template_columns: vec![length(100.0), minmax(length(100.0), fr(2.0)), fr(1.0)],
diff --git a/src/compute/grid/implicit_grid.rs b/src/compute/grid/implicit_grid.rs
index 143e7c380..f6dc973d1 100644
--- a/src/compute/grid/implicit_grid.rs
+++ b/src/compute/grid/implicit_grid.rs
@@ -2,7 +2,7 @@
//! to reduce the number of allocations required when creating a grid.
use crate::geometry::Line;
use crate::style::{GenericGridPlacement, GridPlacement};
-use crate::{CheapCloneStr, Direction, GridItemStyle};
+use crate::{CheapCloneStr, Direction, GridItemStyle, Units};
use core::cmp::{max, min};
use super::types::TrackCounts;
@@ -77,9 +77,9 @@ fn get_known_child_positions<'a, S: GridItemStyle + 'a>(
// Note: that the children reference the lines in between (and around) the tracks not tracks themselves,
// and thus we must subtract 1 to get an accurate estimate of the number of tracks
let (mut child_col_min, mut child_col_max, child_col_span) =
- child_min_line_max_line_span::<S::CustomIdent>(col_line, explicit_col_count);
+ child_min_line_max_line_span::<<S::Units as Units>::Str>(col_line, explicit_col_count);
let (child_row_min, child_row_max, child_row_span) =
- child_min_line_max_line_span::<S::CustomIdent>(row_line, explicit_row_count);
+ child_min_line_max_line_span::<<S::Units as Units>::Str>(row_line, explicit_row_count);
// Placement mirrors horizontal spans in RTL, so mirror known column line bounds here
// to keep implicit-grid pre-sizing consistent with actual placement.
diff --git a/src/compute/grid/placement.rs b/src/compute/grid/placement.rs
index 761077518..ef07aceb1 100644
--- a/src/compute/grid/placement.rs
+++ b/src/compute/grid/placement.rs
@@ -4,10 +4,10 @@ use super::types::{CellOccupancyMatrix, CellOccupancyState, GridItem};
use super::{NamedLineResolver, OriginZeroLine};
use crate::geometry::Line;
use crate::geometry::{AbsoluteAxis, InBothAbsAxis};
-use crate::style::{AlignItems, GridAutoFlow, OriginZeroGridPlacement, Units};
+use crate::style::{AlignItems, GridAutoFlow, OriginZeroGridPlacement};
use crate::tree::NodeId;
use crate::util::sys::Vec;
-use crate::{CoreStyle, Direction, GridItemStyle};
+use crate::{Direction, GridItemStyle};
#[inline]
/// Returns whether placement/search should run in reverse for this axis.
@@ -87,7 +87,7 @@ pub(super) fn place_grid_items<'a, S, ChildIter>(
grid_auto_flow: GridAutoFlow,
align_items: AlignItems,
justify_items: AlignItems,
- named_line_resolver: &NamedLineResolver<<S::Units as Units>::Str>,
+ named_line_resolver: &NamedLineResolver<S::Units>,
) where
S: GridItemStyle + 'a,
ChildIter: Iterator<Item = (usize, NodeId, S)>,
diff --git a/src/compute/grid/types/named.rs b/src/compute/grid/types/named.rs
index 9b784c002..6c44b3d2c 100644
--- a/src/compute/grid/types/named.rs
+++ b/src/compute/grid/types/named.rs
@@ -2,7 +2,7 @@
use crate::{
CheapCloneStr, GenericGridTemplateComponent, GenericRepetition as _, GridAreaAxis, GridAreaEnd, GridContainerStyle,
- GridPlacement, GridTemplateArea, Line, NonNamedGridPlacement, RepetitionCount,
+ GridPlacement, GridTemplateArea, Line, NonNamedGridPlacement, RepetitionCount, Units,
};
use core::{borrow::Borrow, cmp::Ordering, fmt::Debug};
@@ -44,15 +44,15 @@ impl<T: CheapCloneStr> Borrow<str> for StrHasher<T> {
/// Resolver that takes grid lines names and area names as input and can then be used to
/// resolve line names of grid placement properties into line numbers.
-pub(crate) struct NamedLineResolver<S: CheapCloneStr> {
+pub(crate) struct NamedLineResolver<U: Units> {
/// Map of row line names to line numbers. Each line name may correspond to multiple lines
/// so we store a `Vec`
- row_lines: Map<StrHasher<S>, Vec<u16>>,
+ row_lines: Map<StrHasher<U::Str>, Vec<u16>>,
/// Map of column line names to line numbers. Each line name may correspond to multiple lines
/// so we store a `Vec`
- column_lines: Map<StrHasher<S>, Vec<u16>>,
+ column_lines: Map<StrHasher<U::Str>, Vec<u16>>,
/// Map of area names to area definitions (start and end lines numbers in each axis)
- areas: Map<StrHasher<S>, GridTemplateArea<S>>,
+ areas: Map<StrHasher<U::Str>, GridTemplateArea<U::Str>>,
/// Number of columns implied by grid area definitions
area_column_count: u16,
/// Number of rows implied by grid area definitions
@@ -70,16 +70,16 @@ fn upsert_line_name_map<S: CheapCloneStr>(map: &mut Map<StrHasher<S>, Vec<u16>>,
map.entry(StrHasher(key)).and_modify(|lines| lines.push(value)).or_insert_with(|| single_value_vec(value));
}
-impl<S: CheapCloneStr> NamedLineResolver<S> {
+impl<U: Units> NamedLineResolver<U> {
/// Create and initialise a new `NamedLineResolver`
pub(crate) fn new(
- style: &impl GridContainerStyle<CustomIdent = S>,
+ style: &impl GridContainerStyle<Units = U>,
column_auto_repetitions: u16,
row_auto_repetitions: u16,
) -> Self {
- let mut areas: Map<StrHasher<S>, GridTemplateArea<_>> = Map::new();
- let mut column_lines: Map<StrHasher<S>, Vec<u16>> = Map::new();
- let mut row_lines: Map<StrHasher<S>, Vec<u16>> = Map::new();
+ let mut areas: Map<StrHasher<U::Str>, GridTemplateArea<_>> = Map::new();
+ let mut column_lines: Map<StrHasher<U::Str>, Vec<u16>> = Map::new();
+ let mut row_lines: Map<StrHasher<U::Str>, Vec<u16>> = Map::new();
let mut area_column_count = 0;
let mut area_row_count = 0;
@@ -91,13 +91,13 @@ impl<S: CheapCloneStr> NamedLineResolver<S> {
area_column_count = area_column_count.max(area.column_end.max(1) - 1);
area_row_count = area_row_count.max(area.row_end.max(1) - 1);
- let col_start_name = S::from(format!("{}-start", area.name.as_ref()));
+ let col_start_name = U::Str::from(format!("{}-start", area.name.as_ref()));
upsert_line_name_map(&mut column_lines, col_start_name, area.column_start);
- let col_end_name = S::from(format!("{}-end", area.name.as_ref()));
+ let col_end_name = U::Str::from(format!("{}-end", area.name.as_ref()));
upsert_line_name_map(&mut column_lines, col_end_name, area.column_end);
- let row_start_name = S::from(format!("{}-start", area.name.as_ref()));
+ let row_start_name = U::Str::from(format!("{}-start", area.name.as_ref()));
upsert_line_name_map(&mut row_lines, row_start_name, area.row_start);
- let row_end_name = S::from(format!("{}-end", area.name.as_ref()));
+ let row_end_name = U::Str::from(format!("{}-end", area.name.as_ref()));
upsert_line_name_map(&mut row_lines, row_end_name, area.row_end);
}
}
@@ -197,13 +197,13 @@ impl<S: CheapCloneStr> NamedLineResolver<S> {
/// Resolve named lines for both the `start` and `end` of a row-axis grid placement
#[inline(always)]
- pub(crate) fn resolve_row_names(&self, line: &Line<GridPlacement<S>>) -> Line<NonNamedGridPlacement> {
+ pub(crate) fn resolve_row_names(&self, line: &Line<GridPlacement<U::Str>>) -> Line<NonNamedGridPlacement> {
self.resolve_line_names(line, GridAreaAxis::Row)
}
/// Resolve named lines for both the `start` and `end` of a column-axis grid placement
#[inline(always)]
- pub(crate) fn resolve_column_names(&self, line: &Line<GridPlacement<S>>) -> Line<NonNamedGridPlacement> {
+ pub(crate) fn resolve_column_names(&self, line: &Line<GridPlacement<U::Str>>) -> Line<NonNamedGridPlacement> {
self.resolve_line_names(line, GridAreaAxis::Column)
}
@@ -211,7 +211,7 @@ impl<S: CheapCloneStr> NamedLineResolver<S> {
#[inline(always)]
pub(crate) fn resolve_line_names(
&self,
- line: &Line<GridPlacement<S>>,
+ line: &Line<GridPlacement<U::Str>>,
axis: GridAreaAxis,
) -> Line<NonNamedGridPlacement> {
let start_holder;
@@ -293,7 +293,7 @@ impl<S: CheapCloneStr> NamedLineResolver<S> {
/// Resolve the grid line for a named grid line or span
fn find_line_index(
&self,
- name: &S,
+ name: &U::Str,
idx: i16,
axis: GridAreaAxis,
end: GridAreaEnd,
@@ -390,7 +390,7 @@ impl<S: CheapCloneStr> NamedLineResolver<S> {
}
}
-impl<S: CheapCloneStr> Debug for NamedLineResolver<S> {
+impl<U: Units> Debug for NamedLineResolver<U> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
writeln!(f, "Grid Areas:")?;
for area in self.areas.values() {
diff --git a/src/compute/grid/util/test_helpers.rs b/src/compute/grid/util/test_helpers.rs
index 8830550ea..b4c045680 100644
--- a/src/compute/grid/util/test_helpers.rs
+++ b/src/compute/grid/util/test_helpers.rs
@@ -1,7 +1,7 @@
//! Helpers for use in unit tests within the grid module
use super::super::OriginZeroLine;
-use crate::prelude::*;
use crate::style::{Dimension, GridPlacement, Style};
+use crate::{prelude::*, DefaultUnits};
pub(crate) trait CreateParentTestNode {
fn into_grid(self) -> Style;
@@ -23,7 +23,7 @@ pub(crate) trait CreateChildTestNode {
impl CreateChildTestNode
for (GridPlacement<String>, GridPlacement<String>, GridPlacement<String>, GridPlacement<String>)
{
- fn into_grid_child(self) -> Style<String> {
+ fn into_grid_child(self) -> Style<DefaultUnits> {
Style {
display: Display::Grid,
grid_column: Line { start: self.0, end: self.1 },
diff --git a/src/style/flex.rs b/src/style/flex.rs
index a8f05ebd4..08777f5d1 100644
--- a/src/style/flex.rs
+++ b/src/style/flex.rs
@@ -1,7 +1,5 @@
//! Style types for Flexbox layout
-use super::{
- AlignContent, AlignItems, AlignSelf, CoreStyle, Dimension, JustifyContent, LengthPercentage, Style, Units,
-};
+use super::{AlignContent, AlignItems, AlignSelf, CoreStyle, Dimension, JustifyContent, LengthPercentage, Style};
use crate::geometry::Size;
/// The set of styles required for a Flexbox container
diff --git a/src/style/mod.rs b/src/style/mod.rs
index 840a6123b..4be7baf89 100644
--- a/src/style/mod.rs
+++ b/src/style/mod.rs
@@ -17,7 +17,6 @@ pub use self::alignment::{AlignContent, AlignItems, AlignSelf, JustifyContent, J
pub use self::available_space::AvailableSpace;
pub use self::compact_length::CompactLength;
pub use self::dimension::{Dimension, LengthPercentage, LengthPercentageAuto};
-use crate::sys::DefaultCheapStr;
#[cfg(feature = "block_layout")]
pub use self::block::{BlockContainerStyle, BlockItemStyle, TextAlign};
@@ -64,6 +63,10 @@ impl<T> CheapCloneStr for T where
{
}
+/// Trait that represent a `calc()` expression
+pub trait Calc: Clone + Debug + 'static {}
+impl<T> Calc for T where T: Clone + Debug + 'static {}
+
/// Allows Taffy to abstract of the types it uses to represent strings and calc expressions.
/// In future it may be extended to abstract the scalar number type (currently f32)
pub trait Units {
@@ -73,9 +76,11 @@ pub trait Units {
/// Type representing a calc expression.
/// If you're not using Calc then you can just use `()`
- type Calc: 'static;
+ type Calc: Calc;
}
+/// A default implementation of the [`Units`] trait
+#[derive(Debug, Copy, Clone, Default, Eq, PartialEq)]
pub struct DefaultUnits;
impl Units for DefaultUnits {
@@ -446,7 +451,7 @@ crate::util::parse::impl_parse_for_keyword_enum!(Direction,
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(default))]
-pub struct Style<U: Units = DefaultCheapStr> {
+pub struct Style<U: Units = DefaultUnits> {
/// This is a dummy field which is necessary to make Taffy compile with the `grid` feature disabled
/// It should always be set to `core::marker::PhantomData`.
pub dummy: core::marker::PhantomData<U>,
@@ -586,10 +591,10 @@ pub struct Style<U: Units = DefaultCheapStr> {
pub grid_template_areas: GridTrackVec<GridTemplateArea<U::Str>>,
/// The named lines between the columns
#[cfg(feature = "grid")]
- pub grid_template_column_names: GridTrackVec<GridTrackVec<U>>,
+ pub grid_template_column_names: GridTrackVec<GridTrackVec<U::Str>>,
/// The named lines between the rows
#[cfg(feature = "grid")]
- pub grid_template_row_names: GridTrackVec<GridTrackVec<U>>,
+ pub grid_template_row_names: GridTrackVec<GridTrackVec<U::Str>>,
// Grid child properties
/// Defines which row in the grid the item should start and end at
@@ -671,9 +676,9 @@ impl<U: Units> Style<U> {
#[cfg(feature = "grid")]
grid_auto_flow: GridAutoFlow::Row,
#[cfg(feature = "grid")]
- grid_row: Line { start: GridPlacement::<U>::Auto, end: GridPlacement::<U>::Auto },
+ grid_row: Line { start: GridPlacement::<U::Str>::Auto, end: GridPlacement::<U::Str>::Auto },
#[cfg(feature = "grid")]
- grid_column: Line { start: GridPlacement::<U>::Auto, end: GridPlacement::<U>::Auto },
+ grid_column: Line { start: GridPlacement::<U::Str>::Auto, end: GridPlacement::<U::Str>::Auto },
};
}
@@ -1206,7 +1211,7 @@ mod tests {
use std::sync::Arc;
use super::Style;
- use crate::sys::DefaultCheapStr;
+ use crate::DefaultUnits;
use crate::{geometry::*, style_helpers::TaffyAuto as _};
#[test]
@@ -1214,7 +1219,7 @@ mod tests {
#[cfg(feature = "grid")]
use super::GridPlacement;
- let old_defaults: Style<DefaultCheapStr> = Style {
+ let old_defaults: Style<DefaultUnits> = Style {
dummy: core::marker::PhantomData,
display: Default::default(),
item_is_table: false,
@@ -1283,7 +1288,7 @@ mod tests {
grid_column: Line { start: GridPlacement::Auto, end: GridPlacement::Auto },
};
- assert_eq!(Style::DEFAULT, Style::<DefaultCheapStr>::default());
+ assert_eq!(Style::DEFAULT, Style::<DefaultUnits>::default());
assert_eq!(Style::DEFAULT, old_defaults);
}
@@ -1345,18 +1350,19 @@ mod tests {
assert_type_size::<MaxTrackSizingFunction>(8);
assert_type_size::<TrackSizingFunction>(16);
assert_type_size::<Vec<TrackSizingFunction>>(24);
- assert_type_size::<Vec<GridTemplateComponent<U>>>(24);
+ assert_type_size::<Vec<GridTemplateComponent<S>>>(24);
// String-type dependent (String)
assert_type_size::<GridTemplateComponent<String>>(56);
assert_type_size::<GridPlacement<String>>(32);
assert_type_size::<Line<GridPlacement<String>>>(64);
- assert_type_size::<Style<String>>(536);
// String-type dependent (Arc<str>)
assert_type_size::<GridTemplateComponent<Arc<str>>>(56);
assert_type_size::<GridPlacement<Arc<str>>>(24);
assert_type_size::<Line<GridPlacement<Arc<str>>>>(48);
- assert_type_size::<Style<Arc<str>>>(504);
+
+ // Overall size (default units)
+ assert_type_size::<Style<DefaultUnits>>(536);
}
}
diff --git a/src/tree/taffy_tree.rs b/src/tree/taffy_tree.rs
index ab9beb038..342fabeb0 100644
--- a/src/tree/taffy_tree.rs
+++ b/src/tree/taffy_tree.rs
@@ -9,7 +9,6 @@ use slotmap::{DefaultKey, SlotMap};
use crate::block::BlockContext;
use crate::geometry::Size;
use crate::style::{AvailableSpace, Display, Style};
-use crate::sys::DefaultCheapStr;
use crate::tree::{
Cache, ClearState, Layout, LayoutInput, LayoutOutput, LayoutPartialTree, NodeId, PrintTree, RoundTree, RunMode,
TraversePartialTree, TraverseTree,
@@ -20,14 +19,13 @@ use crate::util::sys::{new_vec_with_capacity, ChildrenVec, Vec};
use crate::compute::{
compute_cached_layout, compute_hidden_layout, compute_leaf_layout, compute_root_layout, round_layout,
};
-use crate::CacheTree;
-
#[cfg(feature = "block_layout")]
use crate::{compute::compute_block_layout, LayoutBlockContainer};
#[cfg(feature = "flexbox")]
use crate::{compute::compute_flexbox_layout, LayoutFlexboxContainer};
#[cfg(feature = "grid")]
use crate::{compute::compute_grid_layout, LayoutGridContainer};
+use crate::{CacheTree, DefaultUnits};
#[cfg(all(feature = "detailed_layout_info", feature = "grid"))]
use crate::compute::grid::DetailedGridInfo;
@@ -375,7 +373,7 @@ where
where
Self: 'a;
- type CustomIdent = DefaultCheapStr;
+ type Units = DefaultUnits;
#[inline(always)]
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_> {
diff --git a/src/tree/traits.rs b/src/tree/traits.rs
index b91f9ca2b..4b7e0f2c1 100644
--- a/src/tree/traits.rs
+++ b/src/tree/traits.rs
@@ -130,12 +130,11 @@ use super::{Layout, LayoutInput, LayoutOutput, NodeId, RequestedAxis, RunMode, S
#[cfg(feature = "detailed_layout_info")]
use crate::debug::debug_log;
use crate::geometry::{AbsoluteAxis, Line, Size};
-use crate::style::{AvailableSpace, CoreStyle};
+use crate::style::{AvailableSpace, CoreStyle, Units};
#[cfg(feature = "flexbox")]
use crate::style::{FlexboxContainerStyle, FlexboxItemStyle};
#[cfg(feature = "grid")]
use crate::style::{GridContainerStyle, GridItemStyle};
-use crate::CheapCloneStr;
#[cfg(feature = "block_layout")]
use crate::{BlockContainerStyle, BlockContext, BlockItemStyle};
@@ -174,13 +173,13 @@ pub trait TraverseTree: TraversePartialTree {}
pub trait LayoutPartialTree: TraversePartialTree {
/// The style type representing the core container styles that all containers should have
/// Used when laying out the root node of a tree
- type CoreContainerStyle<'a>: CoreStyle<CustomIdent = Self::CustomIdent>
+ type CoreContainerStyle<'a>: CoreStyle<Units = Self::Units>
where
Self: 'a;
/// String type for representing "custom identifiers" (for example, named grid lines or areas)
/// If you are unsure what to use here then consider `Arc<str>`.
- type CustomIdent: CheapCloneStr;
+ type Units: Units;
/// Get core style
fn get_core_container_style(&self, node_id: NodeId) -> Self::CoreContainerStyle<'_>;
@@ -258,12 +257,12 @@ pub trait LayoutFlexboxContainer: LayoutPartialTree {
/// Extends [`LayoutPartialTree`] with getters for the styles required for CSS Grid layout
pub trait LayoutGridContainer: LayoutPartialTree {
/// The style type representing the CSS Grid container's styles
- type GridContainerStyle<'a>: GridContainerStyle<CustomIdent = Self::CustomIdent>
+ type GridContainerStyle<'a>: GridContainerStyle<Units = Self::Units>
where
Self: 'a;
/// The style type representing each CSS Grid item's styles
- type GridItemStyle<'a>: GridItemStyle<CustomIdent = Self::CustomIdent>
+ type GridItemStyle<'a>: GridItemStyle<Units = Self::Units>
where
Self: 'a;