add plot function

This commit is contained in:
Sébastien Bourdeauducq 2024-09-12 23:30:34 +08:00
parent 12e1d4d4c2
commit 13d6f003d4
3 changed files with 27 additions and 0 deletions

12
Cargo.lock generated
View File

@ -686,6 +686,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"eframe", "eframe",
"egui_extras", "egui_extras",
"egui_plot",
"libloading 0.8.5", "libloading 0.8.5",
"nac3core", "nac3core",
"parking_lot", "parking_lot",
@ -1135,6 +1136,17 @@ dependencies = [
"winit", "winit",
] ]
[[package]]
name = "egui_plot"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7acc4fe778c41b91d57e04c1a2cf5765b3dc977f9f8384d2bb2eb4254855365"
dependencies = [
"ahash",
"egui",
"emath",
]
[[package]] [[package]]
name = "either" name = "either"
version = "1.13.0" version = "1.13.0"

View File

@ -6,6 +6,7 @@ edition = "2021"
[dependencies] [dependencies]
eframe = "0.28" eframe = "0.28"
egui_extras = { version = "0.28", features = ["syntect"]} egui_extras = { version = "0.28", features = ["syntect"]}
egui_plot = "0.28"
parking_lot = "0.12" parking_lot = "0.12"
tempfile = "3.12" tempfile = "3.12"
libloading = "0.8" libloading = "0.8"

View File

@ -499,6 +499,20 @@ pub extern "C" fn __nac3_cells_slider(prev: f64) -> f64 {
value value
} }
pub struct List {
data: *mut f64,
length: usize,
}
#[no_mangle]
pub extern "C" fn __nac3_cells_plot(data: *const List) {
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()).map(|i| [i as f64, data_slice[i]]).collect();
let line = egui_plot::Line::new(points);
egui_plot::Plot::new("my_plot").view_aspect(2.0).show(ui, |plot_ui| plot_ui.line(line));
}
impl Cells { impl Cells {
fn new() -> Self { fn new() -> Self {
Self { Self {