Skip to content

Commit

Permalink
Replace trbl function with function with dynamic edge parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Sep 22, 2023
1 parent bee1596 commit f34e7f1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
35 changes: 24 additions & 11 deletions ctaffy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},
};
})
}
Expand Down
19 changes: 19 additions & 0 deletions ctaffy/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f34e7f1

Please sign in to comment.