Skip to content

Commit

Permalink
Upgrade taffy (content-box + traitified style)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Jul 16, 2024
1 parent 57f9f5b commit 525ed5e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ style_config = { git = "https://github.com/dioxuslabs/stylo", rev = "10767f4" }
style_traits = { git = "https://github.com/dioxuslabs/stylo", rev = "10767f4" } # 2024-05-15 + dioxus patches
selectors = { git = "https://github.com/dioxuslabs/stylo", rev = "10767f4" } # 2024-05-15 + dioxus patches
html5ever = "0.27" # needs to match stylo markup5ever version
taffy = { git = "https://github.com/dioxuslabs/taffy", rev = "9651a18b7da88204741018545edd13eda8fb2b53" }
taffy = { git = "https://github.com/dioxuslabs/taffy", rev = "0ce2f3eef52826852811363a87ef28ecc38e3d55" }
parley = { git = "https://github.com/nicoburns/parley", rev = "482d0fbd59eceaa68cc879e0102a7a9a87636a0d" }
dioxus = { git = "https://github.com/dioxuslabs/dioxus", rev = "a3aa6ae771a2d0a4d8cb6055c41efc0193b817ef"}
dioxus-ssr = { git = "https://github.com/dioxuslabs/dioxus", rev = "a3aa6ae771a2d0a4d8cb6055c41efc0193b817ef" }
Expand Down
59 changes: 58 additions & 1 deletion packages/dom/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ impl TraversePartialTree for Document {
impl TraverseTree for Document {}

impl LayoutPartialTree for Document {
fn get_style(&self, node_id: NodeId) -> &Style {
type CoreContainerStyle<'a> = &'a taffy::Style where Self : 'a;
type CacheMut<'b> = &'b mut Cache where Self: 'b;

fn get_core_container_style(&self, node_id: NodeId) -> &Style {
&self.node_from_id(node_id).style
}

Expand Down Expand Up @@ -212,6 +215,60 @@ impl LayoutPartialTree for Document {
}
}

impl taffy::LayoutBlockContainer for Document {
type BlockContainerStyle<'a> = &'a Style
where
Self: 'a;

type BlockItemStyle<'a> = &'a Style
where
Self: 'a;

fn get_block_container_style(&self, node_id: NodeId) -> Self::BlockContainerStyle<'_> {
self.get_core_container_style(node_id)
}

fn get_block_child_style(&self, child_node_id: NodeId) -> Self::BlockItemStyle<'_> {
self.get_core_container_style(child_node_id)
}
}

impl taffy::LayoutFlexboxContainer for Document {
type FlexboxContainerStyle<'a> = &'a Style
where
Self: 'a;

type FlexboxItemStyle<'a> = &'a Style
where
Self: 'a;

fn get_flexbox_container_style(&self, node_id: NodeId) -> Self::FlexboxContainerStyle<'_> {
self.get_core_container_style(node_id)
}

fn get_flexbox_child_style(&self, child_node_id: NodeId) -> Self::FlexboxItemStyle<'_> {
self.get_core_container_style(child_node_id)
}
}

impl taffy::LayoutGridContainer for Document {
type GridContainerStyle<'a> = &'a Style
where
Self: 'a;

type GridItemStyle<'a> = &'a Style
where
Self: 'a;

fn get_grid_container_style(&self, node_id: NodeId) -> Self::GridContainerStyle<'_> {
self.get_core_container_style(node_id)
}

fn get_grid_child_style(&self, child_node_id: NodeId) -> Self::GridItemStyle<'_> {
self.get_core_container_style(child_node_id)
}
}

impl Document {
fn compute_inline_layout(
&mut self,
Expand Down
3 changes: 2 additions & 1 deletion packages/dom/src/stylo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl crate::document::Document {
max_height,
aspect_ratio,

// box_sizing,
box_sizing,
// z_index,
// order,
column_gap,
Expand Down Expand Up @@ -156,6 +156,7 @@ impl crate::document::Document {

let display = stylo_to_taffy::display(*stylo_display);
node.style = Style {
box_sizing: stylo_to_taffy::box_sizing(*box_sizing),
display,
position,
overflow: taffy::Point {
Expand Down
8 changes: 8 additions & 0 deletions packages/dom/src/stylo_to_taffy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod stylo {
pub(crate) use style::computed_values::grid_auto_flow::T as GridAutoFlow;
pub(crate) use style::properties::longhands::aspect_ratio::computed_value::T as AspectRatio;
pub(crate) use style::properties::longhands::position::computed_value::T as Position;
pub(crate) use style::properties::generated::longhands::box_sizing::computed_value::T as BoxSizing;
pub(crate) use style::properties::style_structs::{Margin, Padding};
pub(crate) use style::values::computed::GridLine;
pub(crate) use style::values::computed::GridTemplateComponent;
Expand Down Expand Up @@ -104,6 +105,13 @@ pub(crate) fn border(
}
}

pub (crate) fn box_sizing(input: stylo::BoxSizing) -> taffy::BoxSizing {
match input {
stylo::BoxSizing::BorderBox => taffy::BoxSizing::BorderBox,
stylo::BoxSizing::ContentBox => taffy::BoxSizing::ContentBox,
}
}

pub(crate) fn display(input: stylo::Display) -> taffy::Display {
let mut display = match input.inside() {
stylo::DisplayInside::None => taffy::Display::None,
Expand Down

0 comments on commit 525ed5e

Please sign in to comment.