🎉 Implement boolean operations (wasm)

This commit is contained in:
Belén Albeza 2025-01-09 12:21:05 +01:00
parent 1514faca55
commit 4e5f67676c
8 changed files with 126 additions and 16 deletions

View file

@ -7,8 +7,7 @@ mod state;
mod utils;
mod view;
use crate::shapes::Kind;
use crate::shapes::Path;
use crate::shapes::{BoolType, Kind, Path};
use skia_safe as skia;
use crate::state::State;
@ -134,8 +133,26 @@ pub unsafe extern "C" fn set_shape_kind_rect() {
pub unsafe extern "C" fn set_shape_kind_path() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
let p = Path::try_from(Vec::new()).unwrap();
shape.set_kind(Kind::Path(p));
shape.set_kind(Kind::Path(Path::default()));
}
}
#[no_mangle]
pub unsafe extern "C" fn set_shape_kind_bool() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
match shape.kind() {
Kind::Bool(_, _) => {}
_ => shape.set_kind(Kind::Bool(BoolType::default(), Path::default())),
}
}
}
#[no_mangle]
pub unsafe extern "C" fn set_shape_bool_type(raw_bool_type: u8) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_bool_type(BoolType::from(raw_bool_type))
}
}