diff --git a/include/taitank_safe.h b/include/taitank_safe.h index 054f63e..2d39019 100644 --- a/include/taitank_safe.h +++ b/include/taitank_safe.h @@ -8,6 +8,9 @@ class TaitankSafeNode { ~TaitankSafeNode(); void set_width(double width) const; void set_height(double height) const; + + void set_direction(int direction) const; + void do_layout(double parent_width, double parent_height) const; double get_left() const; double get_top() const; diff --git a/src/lib.rs b/src/lib.rs index e5fc440..c199505 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ +use cxx::UniquePtr; + #[cxx::bridge] -pub mod ffi { +mod ffi { unsafe extern "C++" { include!("taitank-safe/include/taitank_safe.h"); @@ -8,6 +10,7 @@ pub mod ffi { fn node_create() -> UniquePtr; fn set_width(self: &TaitankSafeNode, width: f64); fn set_height(self: &TaitankSafeNode, height: f64); + fn set_direction(self: &TaitankSafeNode, direction: i32); fn do_layout(self: &TaitankSafeNode, parent_width: f64, parent_height: f64); fn get_left(self: &TaitankSafeNode) -> f64; fn get_top(self: &TaitankSafeNode) -> f64; @@ -16,20 +19,47 @@ pub mod ffi { } } +struct TaitankSafeNode { + unique_ptr: UniquePtr +} + + +#[repr(i32)] +pub enum Direction { + Inherit = 0, + LTR = 1, + RTL = 2, +} + + +pub fn node_create() -> TaitankSafeNode { + TaitankSafeNode { + unique_ptr: ffi::node_create() + } +} +pub fn set_direction(node: &mut TaitankSafeNode, direction: Direction) { + match direction { + x => { + node.unique_ptr.set_direction(x as i32); + } + } +} + #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { - let node = ffi::node_create(); - node.set_width(100.0); - node.set_height(100.0); - node.do_layout(std::f64::NAN, std::f64::NAN); - - assert_eq!(node.get_left(), 0.0); - assert_eq!(node.get_top(), 0.0); - assert_eq!(node.get_width(), 100.0); - assert_eq!(node.get_height(), 100.0); + let mut node = node_create(); + node.unique_ptr.set_width(100.0); + node.unique_ptr.set_height(100.0); + set_direction(&mut node, Direction::LTR); + node.unique_ptr.do_layout(std::f64::NAN, std::f64::NAN); + + assert_eq!(node.unique_ptr.get_left(), 0.0); + assert_eq!(node.unique_ptr.get_top(), 0.0); + assert_eq!(node.unique_ptr.get_width(), 100.0); + assert_eq!(node.unique_ptr.get_height(), 100.0); } } \ No newline at end of file diff --git a/src/taitank_safe.cc b/src/taitank_safe.cc index 775a4b8..b4ebd7c 100644 --- a/src/taitank_safe.cc +++ b/src/taitank_safe.cc @@ -25,6 +25,23 @@ void TaitankSafeNode::set_height(double height) const { taitank::SetHeight(ptr, height); } +void TaitankSafeNode::set_direction(int direction) const { + switch (direction) { + case 0: { + taitank::SetDirection(ptr, taitank::TaitankDirection::DIRECTION_INHERIT); + break; + } + case 1: { + taitank::SetDirection(ptr, taitank::TaitankDirection::DIRECTION_LTR); + break; + } + case 2: { + taitank::SetDirection(ptr, taitank::TaitankDirection::DIRECTION_RTL); + break; + } + } +} + void TaitankSafeNode::do_layout(double parent_width, double parent_height) const { taitank::DoLayout(ptr, parent_width, parent_height); }