Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
# We only run `cargo build` (not `cargo test`) so as to avoid requiring dev-dependencies to build with the MSRV
# version. Building is likely sufficient as runtime errors varying between rust versions is very unlikely.
build-features-msrv:
name: "MSRV Build [Rust 1.65]"
name: "MSRV Build [Rust 1.71]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.65
toolchain: 1.71
- run: cargo build

build-features-debug:
Expand Down Expand Up @@ -106,6 +106,15 @@ jobs:
- run: cargo build --features serde
- run: cargo test --tests --features serde

test-features-default-with-parse-faster:
name: "Test Suite [default + parse_faster]"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- run: cargo build --features parse_faster
- run: cargo test --tests --features parse_faster

test-features-default-except-content-size:
name: "Test Suite [default except content_size]"
runs-on: ubuntu-latest
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Nico Burns <nico@nicoburns.com>",
]
edition = "2021"
rust-version = "1.65"
rust-version = "1.71"
include = ["src/**/*", "examples/**/*", "Cargo.toml", "README.md"]
description = "A flexible UI layout library "
repository = "https://github.com/DioxusLabs/taffy"
Expand All @@ -21,6 +21,7 @@ document-features = { version = "0.2.7", optional = true }
serde = { version = "1.0", default-features = false, optional = true, features = ["serde_derive"] }
slotmap = { version = "1.0.6", default-features = false, optional = true }
grid = { version = "1.0.0", default-features = false, optional = true }
cssparser = { version = "0.37.0", default-features = false, optional = true }

[package.metadata.docs.rs]
# To test all the documentation related features, run:
Expand All @@ -42,6 +43,8 @@ default = [
"calc",
"content_size",
"detailed_layout_info",
"parse",
"parse_faster"
]
#! ## Feature Flags
#!
Expand Down Expand Up @@ -73,6 +76,10 @@ taffy_tree = ["dep:slotmap"]

## Add [`serde`] derives to Style structs
serde = ["dep:serde"]
## Implement `FromStr` trait for Taffy style types
parse = ["dep:cssparser"]
## Enable the `parse` feature with proc-macro dependent optimisations
parse_faster = ["parse", "cssparser/fast_match_byte"]
## Allow Taffy to depend on the [`Rust Standard Library`](std)
std = ["grid?/std", "serde?/std", "slotmap?/std"]
## Allow Taffy to depend on the alloc library
Expand Down
4 changes: 3 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ allow = [
"Apache-2.0",
"Zlib",
"ISC",
"BSD-3-Clause"
"BSD-3-Clause",
"Unicode-3.0",
"MPL-2.0",
]

[bans]
Expand Down
2 changes: 1 addition & 1 deletion scripts/gentest/test_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TrackSizingParser {
}

parseSingleItem() {
return this.parseItem();
return this._parseItem();
}

_parseItemList(separator, terminator = null) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ pub use crate::tree::TaffyTree;
#[doc(inline)]
pub use crate::util::print_tree;

#[cfg(feature = "parse")]
pub use parse::{ParseError, ParseResult};

pub use crate::compute::*;
pub use crate::geometry::*;
pub use crate::style::*;
Expand Down
24 changes: 24 additions & 0 deletions src/style/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ pub enum AlignItems {
/// Stretch to fill the container
Stretch,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(AlignItems,
"start" => Start,
"end" => End,
"flex-start" => FlexStart,
"flex-end" => FlexEnd,
"center" => Center,
"baseline" => Baseline,
"stretch" => Stretch,
);

/// Used to control how child nodes are aligned.
/// Does not apply to Flexbox, and will be ignored if specified on a flex container
/// For Grid it controls alignment in the inline axis
Expand Down Expand Up @@ -89,6 +101,18 @@ pub enum AlignContent {
SpaceAround,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(AlignContent,
"start" => Start,
"end" => End,
"flex-start" => FlexStart,
"flex-end" => FlexEnd,
"center" => Center,
"stretch" => Stretch,
"space-between" => SpaceBetween,
"space-evenly" => SpaceEvenly,
"space-around" => SpaceAround,
);
/// Sets the distribution of space between and around content items
/// For Flexbox it controls alignment in the main axis
/// For Grid it controls alignment in the inline axis
Expand Down
18 changes: 18 additions & 0 deletions src/style/available_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ use crate::{
Size,
};

#[cfg(feature = "parse")]
use crate::util::parse::{from_str_from_css, parse_css_str_entirely, CssParseResult, FromCss, Parser, Token};

/// The amount of space available to a node in a given axis
/// <https://www.w3.org/TR/css-sizing-3/#available>
#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -32,6 +35,21 @@ impl FromLength for AvailableSpace {
}
}

#[cfg(feature = "parse")]
impl FromCss for AvailableSpace {
fn from_css<'i>(parser: &mut Parser<'i, '_>) -> CssParseResult<'i, Self> {
match parser.next()?.clone() {
Token::Number { value, .. } if value >= 0.0 => Ok(Self::Definite(value)),
Token::Dimension { value, .. } if value >= 0.0 => Ok(Self::Definite(value)),
Token::Ident(ident) if ident == "max-content" => Ok(Self::MaxContent),
Token::Ident(ident) if ident == "min-content" => Ok(Self::MinContent),
token => Err(parser.new_unexpected_token_error(token))?,
}
}
}
#[cfg(feature = "parse")]
from_str_from_css!(AvailableSpace);

impl AvailableSpace {
/// Returns true for definite values, else false
pub const fn is_definite(self) -> bool {
Expand Down
8 changes: 8 additions & 0 deletions src/style/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ pub enum TextAlign {
/// Corresponds to `-webkit-center` or `-moz-center` in browsers
LegacyCenter,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(TextAlign,
"auto" => Auto,
"-webkit-left" => LegacyLeft,
"-webkit-right" => LegacyRight,
"-webkit-center" => LegacyCenter,
);
44 changes: 44 additions & 0 deletions src/style/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use super::CompactLength;
use crate::geometry::Rect;
use crate::style_helpers::{FromLength, FromPercent, TaffyAuto, TaffyZero};
#[cfg(feature = "parse")]
use crate::util::parse::{from_str_from_css, parse_css_str_entirely, CssParseResult, FromCss, Parser, Token};

/// A unit of linear measurement
///
Expand All @@ -22,6 +24,20 @@ impl FromPercent for LengthPercentage {
Self::percent(value.into())
}
}

#[cfg(feature = "parse")]
impl FromCss for LengthPercentage {
fn from_css<'i>(parser: &mut Parser<'i, '_>) -> CssParseResult<'i, Self> {
match parser.next()?.clone() {
Token::Percentage { unit_value, .. } => Ok(Self::percent(unit_value)),
Token::Dimension { unit, value, .. } if unit == "px" => Ok(Self::length(value)),
token => Err(parser.new_unexpected_token_error(token))?,
}
}
}
#[cfg(feature = "parse")]
from_str_from_css!(LengthPercentage);

impl LengthPercentage {
/// An absolute length in some abstract units. Users of Taffy may define what they correspond
/// to in their application (pixels, logical pixels, mm, etc) as they see fit.
Expand Down Expand Up @@ -106,6 +122,20 @@ impl From<LengthPercentage> for LengthPercentageAuto {
}
}

#[cfg(feature = "parse")]
impl FromCss for LengthPercentageAuto {
fn from_css<'i>(parser: &mut Parser<'i, '_>) -> CssParseResult<'i, Self> {
match parser.next()?.clone() {
Token::Percentage { unit_value, .. } => Ok(Self::percent(unit_value)),
Token::Dimension { unit, value, .. } if unit == "px" => Ok(Self::length(value)),
Token::Ident(ident) if ident == "auto" => Ok(Self::auto()),
token => Err(parser.new_unexpected_token_error(token))?,
}
}
}
#[cfg(feature = "parse")]
from_str_from_css!(LengthPercentageAuto);

impl LengthPercentageAuto {
/// An absolute length in some abstract units. Users of Taffy may define what they correspond
/// to in their application (pixels, logical pixels, mm, etc) as they see fit.
Expand Down Expand Up @@ -224,6 +254,20 @@ impl From<LengthPercentageAuto> for Dimension {
}
}

#[cfg(feature = "parse")]
impl FromCss for Dimension {
fn from_css<'i>(parser: &mut Parser<'i, '_>) -> CssParseResult<'i, Self> {
match parser.next()?.clone() {
Token::Percentage { unit_value, .. } => Ok(Self::percent(unit_value)),
Token::Dimension { unit, value, .. } if unit == "px" => Ok(Self::length(value)),
Token::Ident(ident) if ident == "auto" => Ok(Self::auto()),
token => Err(parser.new_unexpected_token_error(token))?,
}
}
}
#[cfg(feature = "parse")]
from_str_from_css!(Dimension);

impl Dimension {
/// An absolute length in some abstract units. Users of Taffy may define what they correspond
/// to in their application (pixels, logical pixels, mm, etc) as they see fit.
Expand Down
15 changes: 15 additions & 0 deletions src/style/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ pub enum FlexWrap {
WrapReverse,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(FlexWrap,
"nowrap" => NoWrap,
"wrap" => Wrap,
"wrap-reverse" => WrapReverse,
);

/// The direction of the flexbox layout main axis.
///
/// There are always two perpendicular layout axes: main (or primary) and cross (or secondary).
Expand Down Expand Up @@ -118,6 +125,14 @@ pub enum FlexDirection {
ColumnReverse,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(FlexDirection,
"row" => Row,
"column" => Column,
"row-reverse" => RowReverse,
"column-reverse" => ColumnReverse,
);

impl FlexDirection {
#[inline]
/// Is the direction [`FlexDirection::Row`] or [`FlexDirection::RowReverse`]?
Expand Down
15 changes: 15 additions & 0 deletions src/style/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub enum Float {
None,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(Float,
"left" => Left,
"right" => Right,
"none" => None,
);

/// Whether a box that is definitely floated is floated to the left
/// of to the right.
///
Expand Down Expand Up @@ -63,3 +70,11 @@ pub enum Clear {
#[default]
None,
}

#[cfg(feature = "parse")]
crate::util::parse::impl_parse_for_keyword_enum!(Clear,
"left" => Left,
"right" => Right,
"both" => Both,
"none" => None,
);
Loading
Loading