Skip to content

Commit

Permalink
Module rename / reorganisation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Aug 4, 2024
1 parent 05a51c9 commit fda03d4
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 143 deletions.
106 changes: 55 additions & 51 deletions taffy_stylo/src/arc.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
use crate::{stylo, t2s};
use crate::convert;
use servo_arc::Arc;
use style::properties::generated::ComputedValues;

pub struct TaffyStyloStyle(pub Arc<stylo::ComputedValues>);
pub struct TaffyStyloStyle(pub Arc<ComputedValues>);

impl From<Arc<stylo::ComputedValues>> for TaffyStyloStyle {
fn from(value: Arc<stylo::ComputedValues>) -> Self {
impl From<Arc<ComputedValues>> for TaffyStyloStyle {
fn from(value: Arc<ComputedValues>) -> Self {
Self(Arc::clone(&value))
}
}

impl taffy::CoreStyle for TaffyStyloStyle {
#[inline]
fn box_generation_mode(&self) -> taffy::BoxGenerationMode {
t2s::box_generation_mode(self.0.get_box().display)
convert::box_generation_mode(self.0.get_box().display)
}

#[inline]
fn is_block(&self) -> bool {
t2s::is_block(self.0.get_box().display)
convert::is_block(self.0.get_box().display)
}

#[inline]
fn box_sizing(&self) -> taffy::BoxSizing {
t2s::box_sizing(self.0.get_position().box_sizing)
convert::box_sizing(self.0.get_position().box_sizing)
}

#[inline]
fn overflow(&self) -> taffy::Point<taffy::Overflow> {
let box_styles = self.0.get_box();
taffy::Point { x: t2s::overflow(box_styles.overflow_x), y: t2s::overflow(box_styles.overflow_y) }
taffy::Point { x: convert::overflow(box_styles.overflow_x), y: convert::overflow(box_styles.overflow_y) }
}

#[inline]
Expand All @@ -38,68 +39,71 @@ impl taffy::CoreStyle for TaffyStyloStyle {

#[inline]
fn position(&self) -> taffy::Position {
t2s::position(self.0.get_box().position)
convert::position(self.0.get_box().position)
}

#[inline]
fn inset(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
let position_styles = self.0.get_position();
taffy::Rect {
left: t2s::length_percentage_auto(&position_styles.left),
right: t2s::length_percentage_auto(&position_styles.right),
top: t2s::length_percentage_auto(&position_styles.top),
bottom: t2s::length_percentage_auto(&position_styles.bottom),
left: convert::length_percentage_auto(&position_styles.left),
right: convert::length_percentage_auto(&position_styles.right),
top: convert::length_percentage_auto(&position_styles.top),
bottom: convert::length_percentage_auto(&position_styles.bottom),
}
}

#[inline]
fn size(&self) -> taffy::Size<taffy::Dimension> {
let position_styles = self.0.get_position();
taffy::Size { width: t2s::dimension(&position_styles.width), height: t2s::dimension(&position_styles.height) }
taffy::Size {
width: convert::dimension(&position_styles.width),
height: convert::dimension(&position_styles.height),
}
}

#[inline]
fn min_size(&self) -> taffy::Size<taffy::Dimension> {
let position_styles = self.0.get_position();
taffy::Size {
width: t2s::dimension(&position_styles.min_width),
height: t2s::dimension(&position_styles.min_height),
width: convert::dimension(&position_styles.min_width),
height: convert::dimension(&position_styles.min_height),
}
}

#[inline]
fn max_size(&self) -> taffy::Size<taffy::Dimension> {
let position_styles = self.0.get_position();
taffy::Size {
width: t2s::max_size_dimension(&position_styles.max_width),
height: t2s::max_size_dimension(&position_styles.max_height),
width: convert::max_size_dimension(&position_styles.max_width),
height: convert::max_size_dimension(&position_styles.max_height),
}
}

#[inline]
fn aspect_ratio(&self) -> Option<f32> {
t2s::aspect_ratio(self.0.get_position().aspect_ratio)
convert::aspect_ratio(self.0.get_position().aspect_ratio)
}

#[inline]
fn margin(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
let margin_styles = self.0.get_margin();
taffy::Rect {
left: t2s::length_percentage_auto(&margin_styles.margin_left),
right: t2s::length_percentage_auto(&margin_styles.margin_right),
top: t2s::length_percentage_auto(&margin_styles.margin_top),
bottom: t2s::length_percentage_auto(&margin_styles.margin_bottom),
left: convert::length_percentage_auto(&margin_styles.margin_left),
right: convert::length_percentage_auto(&margin_styles.margin_right),
top: convert::length_percentage_auto(&margin_styles.margin_top),
bottom: convert::length_percentage_auto(&margin_styles.margin_bottom),
}
}

#[inline]
fn padding(&self) -> taffy::Rect<taffy::LengthPercentage> {
let padding_styles = self.0.get_padding();
taffy::Rect {
left: t2s::length_percentage(&padding_styles.padding_left.0),
right: t2s::length_percentage(&padding_styles.padding_right.0),
top: t2s::length_percentage(&padding_styles.padding_top.0),
bottom: t2s::length_percentage(&padding_styles.padding_bottom.0),
left: convert::length_percentage(&padding_styles.padding_left.0),
right: convert::length_percentage(&padding_styles.padding_right.0),
top: convert::length_percentage(&padding_styles.padding_top.0),
bottom: convert::length_percentage(&padding_styles.padding_bottom.0),
}
}

Expand All @@ -118,40 +122,40 @@ impl taffy::CoreStyle for TaffyStyloStyle {
impl taffy::FlexboxContainerStyle for TaffyStyloStyle {
#[inline]
fn flex_direction(&self) -> taffy::FlexDirection {
t2s::flex_direction(self.0.get_position().flex_direction)
convert::flex_direction(self.0.get_position().flex_direction)
}

#[inline]
fn flex_wrap(&self) -> taffy::FlexWrap {
t2s::flex_wrap(self.0.get_position().flex_wrap)
convert::flex_wrap(self.0.get_position().flex_wrap)
}

#[inline]
fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
let position_styles = self.0.get_position();
taffy::Size { width: t2s::gap(&position_styles.column_gap), height: t2s::gap(&position_styles.row_gap) }
taffy::Size { width: convert::gap(&position_styles.column_gap), height: convert::gap(&position_styles.row_gap) }
}

#[inline]
fn align_content(&self) -> Option<taffy::AlignContent> {
t2s::content_alignment(self.0.get_position().align_content.0)
convert::content_alignment(self.0.get_position().align_content.0)
}

#[inline]
fn align_items(&self) -> Option<taffy::AlignItems> {
t2s::item_alignment(self.0.get_position().align_items.0)
convert::item_alignment(self.0.get_position().align_items.0)
}

#[inline]
fn justify_content(&self) -> Option<taffy::JustifyContent> {
t2s::content_alignment(self.0.get_position().justify_content.0)
convert::content_alignment(self.0.get_position().justify_content.0)
}
}

impl taffy::FlexboxItemStyle for TaffyStyloStyle {
#[inline]
fn flex_basis(&self) -> taffy::Dimension {
t2s::flex_basis(&self.0.get_position().flex_basis)
convert::flex_basis(&self.0.get_position().flex_basis)
}

#[inline]
Expand All @@ -166,7 +170,7 @@ impl taffy::FlexboxItemStyle for TaffyStyloStyle {

#[inline]
fn align_self(&self) -> Option<taffy::AlignSelf> {
t2s::item_alignment(self.0.get_position().align_self.0 .0)
convert::item_alignment(self.0.get_position().align_self.0 .0)
}
}

Expand All @@ -176,53 +180,53 @@ impl taffy::GridContainerStyle for TaffyStyloStyle {

#[inline]
fn grid_template_rows(&self) -> Self::TemplateTrackList<'_> {
t2s::grid_template_tracks(&self.0.get_position().grid_template_rows)
convert::grid_template_tracks(&self.0.get_position().grid_template_rows)
}

#[inline]
fn grid_template_columns(&self) -> Self::TemplateTrackList<'_> {
t2s::grid_template_tracks(&self.0.get_position().grid_template_columns)
convert::grid_template_tracks(&self.0.get_position().grid_template_columns)
}

#[inline]
fn grid_auto_rows(&self) -> Self::AutoTrackList<'_> {
t2s::grid_auto_tracks(&self.0.get_position().grid_auto_rows)
convert::grid_auto_tracks(&self.0.get_position().grid_auto_rows)
}

#[inline]
fn grid_auto_columns(&self) -> Self::AutoTrackList<'_> {
t2s::grid_auto_tracks(&self.0.get_position().grid_auto_columns)
convert::grid_auto_tracks(&self.0.get_position().grid_auto_columns)
}

#[inline]
fn grid_auto_flow(&self) -> taffy::GridAutoFlow {
t2s::grid_auto_flow(self.0.get_position().grid_auto_flow)
convert::grid_auto_flow(self.0.get_position().grid_auto_flow)
}

#[inline]
fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
let position_styles = self.0.get_position();
taffy::Size { width: t2s::gap(&position_styles.column_gap), height: t2s::gap(&position_styles.row_gap) }
taffy::Size { width: convert::gap(&position_styles.column_gap), height: convert::gap(&position_styles.row_gap) }
}

#[inline]
fn align_content(&self) -> Option<taffy::AlignContent> {
t2s::content_alignment(self.0.get_position().align_content.0)
convert::content_alignment(self.0.get_position().align_content.0)
}

#[inline]
fn justify_content(&self) -> Option<taffy::JustifyContent> {
t2s::content_alignment(self.0.get_position().justify_content.0)
convert::content_alignment(self.0.get_position().justify_content.0)
}

#[inline]
fn align_items(&self) -> Option<taffy::AlignItems> {
t2s::item_alignment(self.0.get_position().align_items.0)
convert::item_alignment(self.0.get_position().align_items.0)
}

#[inline]
fn justify_items(&self) -> Option<taffy::AlignItems> {
t2s::item_alignment(self.0.get_position().justify_items.computed.0)
convert::item_alignment(self.0.get_position().justify_items.computed.0)
}
}

Expand All @@ -231,27 +235,27 @@ impl taffy::GridItemStyle for TaffyStyloStyle {
fn grid_row(&self) -> taffy::Line<taffy::GridPlacement> {
let position_styles = self.0.get_position();
taffy::Line {
start: t2s::grid_line(&position_styles.grid_row_start),
end: t2s::grid_line(&position_styles.grid_row_end),
start: convert::grid_line(&position_styles.grid_row_start),
end: convert::grid_line(&position_styles.grid_row_end),
}
}

#[inline]
fn grid_column(&self) -> taffy::Line<taffy::GridPlacement> {
let position_styles = self.0.get_position();
taffy::Line {
start: t2s::grid_line(&position_styles.grid_column_start),
end: t2s::grid_line(&position_styles.grid_column_end),
start: convert::grid_line(&position_styles.grid_column_start),
end: convert::grid_line(&position_styles.grid_column_end),
}
}

#[inline]
fn align_self(&self) -> Option<taffy::AlignSelf> {
t2s::item_alignment(self.0.get_position().align_self.0 .0)
convert::item_alignment(self.0.get_position().align_self.0 .0)
}

#[inline]
fn justify_self(&self) -> Option<taffy::AlignSelf> {
t2s::item_alignment(self.0.get_position().justify_self.0 .0)
convert::item_alignment(self.0.get_position().justify_self.0 .0)
}
}
Loading

0 comments on commit fda03d4

Please sign in to comment.