Skip to content

Commit

Permalink
feat(print): add support of print and hello print case pass
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Nov 16, 2024
1 parent d6c767f commit 857c8dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 45 deletions.
26 changes: 26 additions & 0 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use taitank_safe::*;
fn main() {
let mut root = node_create();
set_align_items(&mut root, FlexAlign::FlexAlignCenter);
set_width(&mut root, 200.0);
set_height(&mut root, 200.0);

let mut root_child0 = node_create();
set_flex_direction(&mut root_child0, FlexDirection::FlexDirectionRow);
set_flex_wrap(&mut root_child0, FlexWrapNode::FlexWrap);
insert_child(&mut root, &mut root_child0, 0);

let mut root_child0_child0 = node_create();
set_width(&mut root_child0_child0, 150.0);
set_height(&mut root_child0_child0, 80.0);
insert_child(&mut root_child0, &mut root_child0_child0, 0);

let mut root_child0_child1 = node_create();
set_width(&mut root_child0_child1, 80.0);
set_height(&mut root_child0_child1, 80.0);
insert_child(&mut root_child0, &mut root_child0_child1, 1);

layout!(&mut root);

println!("{:?}", root);
}
1 change: 1 addition & 0 deletions include/safe.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ double get_width(std::unique_ptr<TaitankSafeNode> & node);
double get_height(std::unique_ptr<TaitankSafeNode> & node);
double get_left(std::unique_ptr<TaitankSafeNode> & node);
double get_top(std::unique_ptr<TaitankSafeNode> & node);
void print(std::unique_ptr<TaitankSafeNode> const & node);
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ mod safe;

use cxx::UniquePtr;
use safe::ffi;
use std::fmt::{Debug, Formatter, Result};

pub struct TaitankSafeNode {
unique_ptr: UniquePtr<ffi::TaitankSafeNode>,
}

impl Debug for TaitankSafeNode {
fn fmt(&self, f: &mut Formatter) -> Result {
Ok(ffi::print(&self.unique_ptr))
}
}

#[repr(i32)]
pub enum Direction {
Inherit = 0,
Expand Down
49 changes: 4 additions & 45 deletions src/safe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,48 +310,7 @@ double get_left(std::unique_ptr<TaitankSafeNode> & node) {
double get_top(std::unique_ptr<TaitankSafeNode> & node) {
return taitank::GetTop(node->ptr);
}
//
//void TaitankSafeNode::set_width(double width) const {
// taitank::SetWidth(ptr, width);
//}
//
//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);
//}
//
//double TaitankSafeNode::get_left() const {
// return taitank::GetLeft(ptr);
//}
//
//double TaitankSafeNode::get_top() const {
// return taitank::GetTop(ptr);
//}
//
//double TaitankSafeNode::get_width() const {
// return taitank::GetWidth(ptr);
//}
//
//double TaitankSafeNode::get_height() const {
// return taitank::GetHeight(ptr);
//}

void print(std::unique_ptr<TaitankSafeNode> const & node) {
return taitank::Print(node->ptr);
}
1 change: 1 addition & 0 deletions src/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ pub mod ffi {
fn get_height(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn get_left(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn get_top(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn print(node: &UniquePtr<TaitankSafeNode>);
}
}

0 comments on commit 857c8dd

Please sign in to comment.