diff --git a/ctaffy/src/style.rs b/ctaffy/src/style.rs index 3e8279af2..1b2911356 100644 --- a/ctaffy/src/style.rs +++ b/ctaffy/src/style.rs @@ -2,7 +2,7 @@ pub use taffy::style::Style as TaffyStyle; use super::{ - GridPlacement, GridPlacementResult, ReturnCode, StyleValue, StyleValueResult, StyleValueUnit, TaffyFFIResult, + GridPlacement, GridPlacementResult, ReturnCode, StyleValue, StyleValueResult, StyleValueUnit, TaffyFFIResult, TaffyEdge, }; use std::ffi::c_void; use taffy::geometry::Rect; @@ -79,19 +79,32 @@ pub unsafe extern "C" fn TaffyStyle_SetMarginTop(raw_style: *mut TaffyStyle, val /// Function to set all the value of margin #[no_mangle] -pub unsafe extern "C" fn TaffyStyle_SetMarginTrbl( +pub unsafe extern "C" fn TaffyStyle_SetMargin( raw_style: *mut TaffyStyle, - top: StyleValue, - right: StyleValue, - bottom: StyleValue, - left: StyleValue, + edge: TaffyEdge, + value: StyleValue, ) -> ReturnCode { + let value = try_from_value!(value); with_style_mut!(raw_style, style, { - style.margin = Rect { - top: try_from_value!(top), - right: try_from_value!(right), - bottom: try_from_value!(bottom), - left: try_from_value!(left), + match edge { + TaffyEdge::Top => style.margin.top = value, + TaffyEdge::Bottom => style.margin.bottom = value, + TaffyEdge::Left => style.margin.left = value, + TaffyEdge::Right => style.margin.right = value, + TaffyEdge::Vertical => { + style.margin.top = value; + style.margin.bottom = value; + }, + TaffyEdge::Horizontal => { + style.margin.left = value; + style.margin.right = value; + }, + TaffyEdge::All => { + style.margin.top = value; + style.margin.bottom = value; + style.margin.left = value; + style.margin.right = value; + }, }; }) } diff --git a/ctaffy/src/value.rs b/ctaffy/src/value.rs index 40eaac850..16a7f8833 100644 --- a/ctaffy/src/value.rs +++ b/ctaffy/src/value.rs @@ -4,6 +4,25 @@ use taffy::prelude as core; use super::ReturnCode; +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[repr(C)] +pub enum TaffyEdge { + /// The top edge of the box + Top, + /// The bottom edge of the box + Bottom, + /// The left edge of the box + Left, + /// The right edge of the box + Right, + /// Both the top and bottom edges of the box + Vertical, + /// Both the left and right edges of the box + Horizontal, + /// All four edges of the box + All, +} + #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[repr(C)] pub enum StyleValueUnit {