This commit is contained in:
2025-05-29 13:41:36 +08:00
parent 48fbf95293
commit 843b87981e
3 changed files with 601 additions and 450 deletions

1035
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
[package]
name = "cells"
version = "0.1.0"
edition = "2021"
edition = "2024"
[dependencies]
eframe = "0.31"
@@ -15,4 +15,4 @@ rustfft = "6.2"
[dependencies.nac3core]
git = "https://git.m-labs.hk/M-Labs/nac3"
rev = "dfb3cc7283706ba72a094afd55d4f74461e1c575"
rev = "0e9166f9d8c35bcb1d0b717ef30c7aa7fc48dd0a"

View File

@@ -661,8 +661,9 @@ struct Cells {
static mut CELL_UI: Option<&'static mut egui::Ui> = None;
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn __nac3_cells_slider(prev: f64) -> f64 {
#[allow(static_mut_refs)]
let ui = unsafe { CELL_UI.as_mut().unwrap() };
let mut value = prev;
ui.add(egui::Slider::new(&mut value, 0.0..=100.0));
@@ -674,8 +675,9 @@ pub struct List {
length: usize,
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn __nac3_cells_plot(data: *const List) {
#[allow(static_mut_refs)]
let ui = unsafe { CELL_UI.as_mut().unwrap() };
let data_slice = unsafe { std::slice::from_raw_parts((*data).data, (*data).length) };
let points: Vec<[f64; 2]> = (0..data_slice.len())
@@ -687,7 +689,7 @@ pub extern "C" fn __nac3_cells_plot(data: *const List) {
.show(ui, |plot_ui| plot_ui.line(line));
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn __nac3_cells_fft(reals: *mut List, imags: *mut List) {
let reals_slice = unsafe { std::slice::from_raw_parts_mut((*reals).data, (*reals).length) };
let imags_slice = unsafe { std::slice::from_raw_parts_mut((*imags).data, (*imags).length) };
@@ -763,10 +765,12 @@ impl Cells {
});
match &cell.result {
Ok(bin) => unsafe {
#[allow(static_mut_refs)]
CELL_UI.replace(
std::mem::transmute::<&mut egui::Ui, &'static mut egui::Ui>(ui),
);
bin.run_fn.unwrap()();
#[allow(static_mut_refs)]
CELL_UI.take();
},
Err(msg) => {
@@ -804,7 +808,7 @@ fn main() -> eframe::Result {
})
}
#[no_mangle]
#[unsafe(no_mangle)]
pub extern "C" fn __nac3_personality(_state: u32, _exception_object: u32, _context: u32) -> u32 {
unimplemented!()
}