🔧 Use with_state and with_current_state macros allowing static_mut_refs only on STATE

This commit is contained in:
elenatorro 2025-03-07 15:24:04 +01:00
parent a361e0b990
commit 0dbf00a767
2 changed files with 31 additions and 23 deletions

View file

@ -1,23 +1,22 @@
use crate::mem;
use crate::with_current_shape;
use crate::STATE;
#[no_mangle]
pub extern "C" fn clear_shape_text() {
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
with_current_shape!(state, |shape: &mut Shape| {
shape.clear_text();
}
});
}
#[no_mangle]
pub extern "C" fn add_text_paragraph() {
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
with_current_shape!(state, |shape: &mut Shape| {
let res = shape.add_text_paragraph();
if let Err(err) = res {
eprintln!("{}", err);
}
}
});
}
#[no_mangle]
@ -27,11 +26,10 @@ pub extern "C" fn add_text_leaf() {
String::from_utf8_unchecked(bytes) // TODO: handle this error
};
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() {
with_current_shape!(state, |shape: &mut Shape| {
let res = shape.add_text_leaf(&text);
if let Err(err) = res {
eprintln!("{}", err);
}
}
});
}