🎉 Render plain text

* 🎉 Serialize text content (wasm)

* ♻️ Refactor functions in main to wasm module

* 🎉 Stub rendering of paragraph text (wasm)

* 📎 Clean up commented code
This commit is contained in:
Belén Albeza 2025-03-04 11:54:52 +01:00 committed by GitHub
parent 9e5de82967
commit aa468e2153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 256 additions and 9 deletions

View file

@ -0,0 +1,37 @@
use crate::mem;
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() {
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() {
let res = shape.add_text_paragraph();
if let Err(err) = res {
eprintln!("{}", err);
}
}
}
#[no_mangle]
pub extern "C" fn add_text_leaf() {
let bytes = mem::bytes();
let text = unsafe {
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() {
let res = shape.add_text_leaf(&text);
if let Err(err) = res {
eprintln!("{}", err);
}
}
}