From 13d6f003d4cb7ba6fdf6528ff8880f134851f4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Bourdeauducq?= Date: Thu, 12 Sep 2024 23:30:34 +0800 Subject: [PATCH] add plot function --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + src/main.rs | 14 ++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f1b4792..44062a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,6 +686,7 @@ version = "0.1.0" dependencies = [ "eframe", "egui_extras", + "egui_plot", "libloading 0.8.5", "nac3core", "parking_lot", @@ -1135,6 +1136,17 @@ dependencies = [ "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]] name = "either" version = "1.13.0" diff --git a/Cargo.toml b/Cargo.toml index e1cb467..0562f56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" [dependencies] eframe = "0.28" egui_extras = { version = "0.28", features = ["syntect"]} +egui_plot = "0.28" parking_lot = "0.12" tempfile = "3.12" libloading = "0.8" diff --git a/src/main.rs b/src/main.rs index 665ab17..53b4d37 100644 --- a/src/main.rs +++ b/src/main.rs @@ -499,6 +499,20 @@ pub extern "C" fn __nac3_cells_slider(prev: f64) -> f64 { 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 { fn new() -> Self { Self {