add slider GUI element

This commit is contained in:
Sébastien Bourdeauducq 2024-09-12 22:53:01 +08:00
parent d0ed143579
commit 12e1d4d4c2
1 changed files with 22 additions and 1 deletions

View File

@ -489,6 +489,16 @@ struct Cells {
cells: Vec<Cell>, cells: Vec<Cell>,
} }
static mut CELL_UI: Option<&'static mut egui::Ui> = None;
#[no_mangle]
pub extern "C" fn __nac3_cells_slider(prev: f64) -> f64 {
let ui = unsafe { CELL_UI.as_mut().unwrap() };
let mut value = prev;
ui.add(egui::Slider::new(&mut value, 0.0..=100.0));
value
}
impl Cells { impl Cells {
fn new() -> Self { fn new() -> Self {
Self { Self {
@ -541,7 +551,18 @@ impl Cells {
}); });
match &cell.result { match &cell.result {
Ok(bin) => { Ok(bin) => {
ui.label(format!("{}", unsafe { bin.run_fn.unwrap()() })); let result = {
unsafe {
CELL_UI.replace(std::mem::transmute::<
&mut egui::Ui,
&'static mut egui::Ui,
>(ui))
};
let result = unsafe { bin.run_fn.unwrap()() };
unsafe { CELL_UI.take() };
result
};
ui.label(format!("{}", result));
} }
Err(msg) => { Err(msg) => {
if !msg.is_empty() { if !msg.is_empty() {