Skip to content

Commit

Permalink
feat(mutable): make mutable function mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
meloalright committed Nov 12, 2024
1 parent faaa199 commit c8c6e31
Show file tree
Hide file tree
Showing 7 changed files with 518 additions and 508 deletions.
3 changes: 1 addition & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::process::Command;

fn main() {

Command::new("git")
.args(["submodule", "init"])
.status()
Expand All @@ -27,4 +26,4 @@ fn main() {
println!("cargo:rerun-if-changed=src/main.rs");
println!("cargo:rerun-if-changed=src/safe.cc");
println!("cargo:rerun-if-changed=include/safe.h");
}
}
28 changes: 14 additions & 14 deletions include/safe.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class TaitankSafeNode {
};

std::unique_ptr<TaitankSafeNode> node_create();
void set_width(const std::unique_ptr<TaitankSafeNode> & node, double width);
void set_height(const std::unique_ptr<TaitankSafeNode> & node, double width);
void set_direction(const std::unique_ptr<TaitankSafeNode> & node, int direction);
void set_flex(const std::unique_ptr<TaitankSafeNode> & node, double flex);
void set_flex_grow(const std::unique_ptr<TaitankSafeNode> & node, double flex_grow);
void set_flex_shrink(const std::unique_ptr<TaitankSafeNode> & node, double flex_shrink);
void set_flex_basis(const std::unique_ptr<TaitankSafeNode> & node, double flex_basis);
void set_flex_direction(const std::unique_ptr<TaitankSafeNode> & node, int direction);
void insert_child(const std::unique_ptr<TaitankSafeNode> & node, const std::unique_ptr<TaitankSafeNode> & child, int index);
void do_layout(const std::unique_ptr<TaitankSafeNode> & node, double parent_width, double parent_height, int direction);
double get_width(const std::unique_ptr<TaitankSafeNode> & node);
double get_height(const std::unique_ptr<TaitankSafeNode> & node);
double get_left(const std::unique_ptr<TaitankSafeNode> & node);
double get_top(const std::unique_ptr<TaitankSafeNode> & node);
void set_width(std::unique_ptr<TaitankSafeNode> & node, double width);
void set_height(std::unique_ptr<TaitankSafeNode> & node, double width);
void set_direction(std::unique_ptr<TaitankSafeNode> & node, int direction);
void set_flex(std::unique_ptr<TaitankSafeNode> & node, double flex);
void set_flex_grow(std::unique_ptr<TaitankSafeNode> & node, double flex_grow);
void set_flex_shrink(std::unique_ptr<TaitankSafeNode> & node, double flex_shrink);
void set_flex_basis(std::unique_ptr<TaitankSafeNode> & node, double flex_basis);
void set_flex_direction(std::unique_ptr<TaitankSafeNode> & node, int direction);
void insert_child(std::unique_ptr<TaitankSafeNode> & node, std::unique_ptr<TaitankSafeNode> & child, int index);
void do_layout(std::unique_ptr<TaitankSafeNode> & node, double parent_width, double parent_height, int direction);
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);
77 changes: 42 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
mod safe;
pub mod macros;
mod safe;

use safe::ffi;
use cxx::UniquePtr;

use safe::ffi;

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


#[repr(i32)]
pub enum Direction {
Inherit = 0,
Expand All @@ -25,51 +23,60 @@ pub enum FlexDirection {
FlexDirectionColumnReverse,
}


pub fn node_create() -> TaitankSafeNode {
TaitankSafeNode {
unique_ptr: ffi::node_create()
unique_ptr: ffi::node_create(),
}
}
pub fn set_width(node: &TaitankSafeNode, width: f64) {
ffi::set_width(&node.unique_ptr, width);
pub fn set_width(node: &mut TaitankSafeNode, width: f64) {
ffi::set_width(&mut node.unique_ptr, width);
}
pub fn set_height(node: &TaitankSafeNode, height: f64) {
ffi::set_height(&node.unique_ptr, height);
pub fn set_height(node: &mut TaitankSafeNode, height: f64) {
ffi::set_height(&mut node.unique_ptr, height);
}
pub fn set_direction(node: &TaitankSafeNode, direction: Direction) {
ffi::set_direction(&node.unique_ptr, direction as i32);
pub fn set_direction(node: &mut TaitankSafeNode, direction: Direction) {
ffi::set_direction(&mut node.unique_ptr, direction as i32);
}
pub fn set_flex(node: &TaitankSafeNode, flex: f64) {
ffi::set_flex(&node.unique_ptr, flex);
pub fn set_flex(node: &mut TaitankSafeNode, flex: f64) {
ffi::set_flex(&mut node.unique_ptr, flex);
}
pub fn set_flex_grow(node: &TaitankSafeNode, flex_grow: f64) {
ffi::set_flex_grow(&node.unique_ptr, flex_grow);
pub fn set_flex_grow(node: &mut TaitankSafeNode, flex_grow: f64) {
ffi::set_flex_grow(&mut node.unique_ptr, flex_grow);
}
pub fn set_flex_shrink(node: &TaitankSafeNode, flex_shrink: f64) {
ffi::set_flex_shrink(&node.unique_ptr, flex_shrink);
pub fn set_flex_shrink(node: &mut TaitankSafeNode, flex_shrink: f64) {
ffi::set_flex_shrink(&mut node.unique_ptr, flex_shrink);
}
pub fn set_flex_basis(node: &TaitankSafeNode, flex_basis: f64) {
ffi::set_flex_basis(&node.unique_ptr, flex_basis);
pub fn set_flex_basis(node: &mut TaitankSafeNode, flex_basis: f64) {
ffi::set_flex_basis(&mut node.unique_ptr, flex_basis);
}
pub fn set_flex_direction(node: &TaitankSafeNode, flex_direction: FlexDirection) {
ffi::set_flex_direction(&node.unique_ptr, flex_direction as i32);
pub fn set_flex_direction(node: &mut TaitankSafeNode, flex_direction: FlexDirection) {
ffi::set_flex_direction(&mut node.unique_ptr, flex_direction as i32);
}
pub fn insert_child(node: &TaitankSafeNode, child: &TaitankSafeNode, index: i32) {
ffi::insert_child(&node.unique_ptr, &child.unique_ptr, index);
pub fn insert_child(node: &mut TaitankSafeNode, child: &mut TaitankSafeNode, index: i32) {
ffi::insert_child(&mut node.unique_ptr, &mut child.unique_ptr, index);
}
pub fn do_layout(node: &TaitankSafeNode, parent_width: f64, parent_height: f64, direction: Direction) {
ffi::do_layout(&node.unique_ptr, parent_width, parent_height, direction as i32);
pub fn do_layout(
node: &mut TaitankSafeNode,
parent_width: f64,
parent_height: f64,
direction: Direction,
) {
ffi::do_layout(
&mut node.unique_ptr,
parent_width,
parent_height,
direction as i32,
);
}
pub fn get_width(node: &TaitankSafeNode) -> f64 {
ffi::get_width(&node.unique_ptr)
pub fn get_width(node: &mut TaitankSafeNode) -> f64 {
ffi::get_width(&mut node.unique_ptr)
}
pub fn get_height(node: &TaitankSafeNode) -> f64 {
ffi::get_height(&node.unique_ptr)
pub fn get_height(node: &mut TaitankSafeNode) -> f64 {
ffi::get_height(&mut node.unique_ptr)
}
pub fn get_left(node: &TaitankSafeNode) -> f64 {
ffi::get_left(&node.unique_ptr)
pub fn get_left(node: &mut TaitankSafeNode) -> f64 {
ffi::get_left(&mut node.unique_ptr)
}
pub fn get_top(node: &TaitankSafeNode) -> f64 {
ffi::get_top(&node.unique_ptr)
pub fn get_top(node: &mut TaitankSafeNode) -> f64 {
ffi::get_top(&mut node.unique_ptr)
}
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ macro_rules! layout {
($a:expr) => {
do_layout($a, std::f64::NAN, std::f64::NAN, Direction::LTR)
};
}
}
28 changes: 14 additions & 14 deletions src/safe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ std::unique_ptr<TaitankSafeNode> node_create() {
return std::unique_ptr<TaitankSafeNode>(new TaitankSafeNode());
}

void set_width(const std::unique_ptr<TaitankSafeNode> & node, double width) {
void set_width(std::unique_ptr<TaitankSafeNode> & node, double width) {
taitank::SetWidth(node->ptr, width);
}

void set_height(const std::unique_ptr<TaitankSafeNode> & node, double height) {
void set_height(std::unique_ptr<TaitankSafeNode> & node, double height) {
taitank::SetHeight(node->ptr, height);
}

void set_direction(const std::unique_ptr<TaitankSafeNode> & node, int direction) {
void set_direction(std::unique_ptr<TaitankSafeNode> & node, int direction) {
switch (direction) {
case 0: {
taitank::SetDirection(node->ptr, taitank::TaitankDirection::DIRECTION_INHERIT);
Expand All @@ -41,23 +41,23 @@ void set_direction(const std::unique_ptr<TaitankSafeNode> & node, int direction)
}
}

void set_flex(const std::unique_ptr<TaitankSafeNode> & node, double flex) {
void set_flex(std::unique_ptr<TaitankSafeNode> & node, double flex) {
taitank::SetFlex(node->ptr, flex);
}

void set_flex_grow(const std::unique_ptr<TaitankSafeNode> & node, double flex_grow) {
void set_flex_grow(std::unique_ptr<TaitankSafeNode> & node, double flex_grow) {
taitank::SetFlexGrow(node->ptr, flex_grow);
}

void set_flex_shrink(const std::unique_ptr<TaitankSafeNode> & node, double flex_shrink) {
void set_flex_shrink(std::unique_ptr<TaitankSafeNode> & node, double flex_shrink) {
taitank::SetFlexShrink(node->ptr, flex_shrink);
}

void set_flex_basis(const std::unique_ptr<TaitankSafeNode> & node, double flex_basis) {
void set_flex_basis(std::unique_ptr<TaitankSafeNode> & node, double flex_basis) {
taitank::SetFlexBasis(node->ptr, flex_basis);
}

void set_flex_direction(const std::unique_ptr<TaitankSafeNode> & node, int flex_direction) {
void set_flex_direction(std::unique_ptr<TaitankSafeNode> & node, int flex_direction) {
switch (flex_direction) {
case 0: {
taitank::SetFlexDirection(node->ptr, taitank::FlexDirection::FLEX_DIRECTION_ROW);
Expand All @@ -78,11 +78,11 @@ void set_flex_direction(const std::unique_ptr<TaitankSafeNode> & node, int flex_
}
}

void insert_child(const std::unique_ptr<TaitankSafeNode> & node, const std::unique_ptr<TaitankSafeNode> & child, int index) {
void insert_child(std::unique_ptr<TaitankSafeNode> & node, std::unique_ptr<TaitankSafeNode> & child, int index) {
taitank::InsertChild(node->ptr, child->ptr, index);
}

void do_layout(const std::unique_ptr<TaitankSafeNode> & node, double parent_width, double parent_height, int direction) {
void do_layout(std::unique_ptr<TaitankSafeNode> & node, double parent_width, double parent_height, int direction) {
switch (direction) {
case 0: {
taitank::DoLayout(node->ptr, parent_width, parent_height, taitank::TaitankDirection::DIRECTION_INHERIT);
Expand All @@ -99,19 +99,19 @@ void do_layout(const std::unique_ptr<TaitankSafeNode> & node, double parent_widt
}
}

double get_width(const std::unique_ptr<TaitankSafeNode> & node) {
double get_width(std::unique_ptr<TaitankSafeNode> & node) {
return taitank::GetWidth(node->ptr);
}

double get_height(const std::unique_ptr<TaitankSafeNode> & node) {
double get_height(std::unique_ptr<TaitankSafeNode> & node) {
return taitank::GetHeight(node->ptr);
}

double get_left(const std::unique_ptr<TaitankSafeNode> & node) {
double get_left(std::unique_ptr<TaitankSafeNode> & node) {
return taitank::GetLeft(node->ptr);
}

double get_top(const std::unique_ptr<TaitankSafeNode> & node) {
double get_top(std::unique_ptr<TaitankSafeNode> & node) {
return taitank::GetTop(node->ptr);
}
//
Expand Down
38 changes: 23 additions & 15 deletions src/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,28 @@ pub mod ffi {

type TaitankSafeNode;
fn node_create() -> UniquePtr<TaitankSafeNode>;
fn set_width(node: &UniquePtr<TaitankSafeNode>, width: f64);
fn set_height(node: &UniquePtr<TaitankSafeNode>, height: f64);
fn set_direction(node: &UniquePtr<TaitankSafeNode>, direction: i32);
fn set_flex(node: &UniquePtr<TaitankSafeNode>, flex: f64);
fn set_flex_grow(node: &UniquePtr<TaitankSafeNode>, flex_grow: f64);
fn set_flex_shrink(node: &UniquePtr<TaitankSafeNode>, flex_shrink: f64);
fn set_flex_basis(node: &UniquePtr<TaitankSafeNode>, flex_basis: f64);
fn set_flex_direction(node: &UniquePtr<TaitankSafeNode>, flex_direction: i32);
fn insert_child(node: &UniquePtr<TaitankSafeNode>, child: &UniquePtr<TaitankSafeNode>, index: i32);
fn do_layout(node: &UniquePtr<TaitankSafeNode>, parent_width: f64, parent_height: f64, direction: i32);
fn get_width(node: &UniquePtr<TaitankSafeNode>) -> f64;
fn get_height(node: &UniquePtr<TaitankSafeNode>) -> f64;
fn get_left(node: &UniquePtr<TaitankSafeNode>) -> f64;
fn get_top(node: &UniquePtr<TaitankSafeNode>) -> f64;
fn set_width(node: &mut UniquePtr<TaitankSafeNode>, width: f64);
fn set_height(node: &mut UniquePtr<TaitankSafeNode>, height: f64);
fn set_direction(node: &mut UniquePtr<TaitankSafeNode>, direction: i32);
fn set_flex(node: &mut UniquePtr<TaitankSafeNode>, flex: f64);
fn set_flex_grow(node: &mut UniquePtr<TaitankSafeNode>, flex_grow: f64);
fn set_flex_shrink(node: &mut UniquePtr<TaitankSafeNode>, flex_shrink: f64);
fn set_flex_basis(node: &mut UniquePtr<TaitankSafeNode>, flex_basis: f64);
fn set_flex_direction(node: &mut UniquePtr<TaitankSafeNode>, flex_direction: i32);
fn insert_child(
node: &mut UniquePtr<TaitankSafeNode>,
child: &mut UniquePtr<TaitankSafeNode>,
index: i32,
);
fn do_layout(
node: &mut UniquePtr<TaitankSafeNode>,
parent_width: f64,
parent_height: f64,
direction: i32,
);
fn get_width(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn get_height(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn get_left(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
fn get_top(node: &mut UniquePtr<TaitankSafeNode>) -> f64;
}
}

Loading

0 comments on commit c8c6e31

Please sign in to comment.