Skip to content

Commit a6b3d09

Browse files
committed
Implement Save/SaveAs distinction and prompting user for saves
1 parent 59eacc6 commit a6b3d09

15 files changed

Lines changed: 354 additions & 108 deletions

File tree

Cargo.lock

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rust_graph"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
edition = "2024"
55
authors = ["Vedran Maric <valinion@gmail.com>"]
66
description = "Graphing calculator with f32 support."

evalexpr/src/flat_node/variable_inlining.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,13 +1008,17 @@ pub fn setup_jump_offsets<F: EvalexprFloat>(node: &mut FlatNode<F>) {
10081008
for i in 0..node.ops.len() {
10091009
match &node.ops[i] {
10101010
FlatOperator::JumpIfFalse { id, .. } | FlatOperator::Jump { id, .. } => {
1011-
let pos = node.ops[i..]
1011+
let Some( pos) = node.ops[i..]
10121012
.iter()
10131013
.position(|op| match op {
10141014
FlatOperator::Label { id: other_id } => id == other_id,
10151015
_ => false,
1016-
})
1017-
.unwrap();
1016+
})else{
1017+
println!("No label {id} found for jump at {i}");
1018+
println!("{node:?}");
1019+
panic!()
1020+
1021+
};
10181022
match &mut node.ops[i] {
10191023
FlatOperator::JumpIfFalse { offset, .. } | FlatOperator::Jump { offset, .. } => {
10201024
*offset = Some(NonZeroU32::new(pos as u32).unwrap());

src/color.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
44

55
use crate::entry::ColorEntryType;
66

7-
87
pub struct ProcessedColors<T: EvalexprFloat> {
98
pub colors: Vec<(u64, ProcessedColor<T>)>,
109
}

src/custom_rendering/mesh_renderer.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::sync::Arc;
2-
use send_wrapper::SendWrapper;
32
use core::cell::RefCell;
43
use core::num::NonZeroU64;
4+
use send_wrapper::SendWrapper;
55

66
use eframe::egui::{self, Mesh, Rect};
77
use eframe::egui_wgpu::wgpu::util::DeviceExt as _;
@@ -111,7 +111,7 @@ pub fn init_mesh_renderer(cc: &eframe::CreationContext) -> Option<()> {
111111
index_capacity: 0,
112112
vertex_count: 0,
113113
index_count: 0,
114-
index_scratch: Vec::with_capacity(1024),
114+
index_scratch: Vec::with_capacity(1024),
115115
}),
116116
}));
117117

@@ -123,12 +123,12 @@ struct BufferState {
123123
vertex_capacity: usize,
124124
vertex_count: usize,
125125

126-
index_buffer: Option<wgpu::Buffer>,
127-
index_capacity: usize,
128-
index_count: usize,
126+
index_buffer: Option<wgpu::Buffer>,
127+
index_capacity: usize,
128+
index_count: usize,
129129

130-
/// used for offseting current mesh indices
131-
index_scratch: Vec<u32>,
130+
/// used for offseting current mesh indices
131+
index_scratch: Vec<u32>,
132132
}
133133

134134
struct MeshRenderResources {
@@ -153,9 +153,8 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
153153
egui_encoder: &mut wgpu::CommandEncoder, resources: &mut egui_wgpu::CallbackResources,
154154
) -> Vec<wgpu::CommandBuffer> {
155155
let mesh_resources: &mut SendWrapper<MeshRenderResources> = resources.get_mut().unwrap();
156-
let mesh_resources: &mut MeshRenderResources = mesh_resources;
157-
let state = &mut mesh_resources.state.borrow_mut();
158-
156+
let mesh_resources: &mut MeshRenderResources = mesh_resources;
157+
let state = &mut mesh_resources.state.borrow_mut();
159158

160159
if state.index_count == 0 {
161160
// uniform is always be the same within one frame, so we only need to update it the first time.
@@ -221,7 +220,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
221220
state.index_capacity = new_capacity;
222221
}
223222

224-
// write vertices
223+
// write vertices
225224
let vertex_offset = (state.vertex_count * size_of::<egui::epaint::Vertex>()) as u64;
226225
queue.write_buffer(
227226
state.vertex_buffer.as_ref().unwrap(),
@@ -231,10 +230,10 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
231230

232231
// we have to adjust indices by the current vertex offset
233232
let base_vertex = state.vertex_count as u32;
234-
state.index_scratch.clear();
235-
for idx in self.mesh.indices.iter() {
236-
state.index_scratch.push(*idx + base_vertex);
237-
}
233+
state.index_scratch.clear();
234+
for idx in self.mesh.indices.iter() {
235+
state.index_scratch.push(*idx + base_vertex);
236+
}
238237
let index_offset = (state.index_count * size_of::<u32>()) as u64;
239238
queue.write_buffer(
240239
state.index_buffer.as_ref().unwrap(),
@@ -253,7 +252,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
253252
callback_resources: &egui_wgpu::CallbackResources,
254253
) {
255254
let mesh_resources: &SendWrapper<MeshRenderResources> = callback_resources.get().unwrap();
256-
let mesh_resources :&MeshRenderResources = mesh_resources;
255+
let mesh_resources: &MeshRenderResources = mesh_resources;
257256
let state = &mut mesh_resources.state.borrow_mut();
258257

259258
// we draw everything in the first pain callback
@@ -270,7 +269,7 @@ impl egui_wgpu::CallbackTrait for MeshCallback {
270269
render_pass.set_index_buffer(index_buffer.slice(..), wgpu::IndexFormat::Uint32);
271270
render_pass.draw_indexed(0..(state.index_count as u32), 0, 0..1);
272271

273-
// reset counts back to 0, so we only draw in the first callback
272+
// reset counts back to 0, so we only draw in the first callback
274273
state.vertex_count = 0;
275274
state.index_count = 0;
276275
}

src/graph_ui.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ impl<T: EvalexprFloat> GraphState<T> {
6767
// TODO: very inefficient converting to json and back
6868
let mut ser_output = Vec::with_capacity(1024);
6969
persistence::serialize_graph_state_to_json(&mut ser_output, self)?;
70-
persistence::deserialize_graph_state_from_json(name, &ser_output)
70+
let mut graph_state = persistence::deserialize_graph_state_from_json(&ser_output)?;
71+
graph_state.name = name; // ensure name is preserved
72+
Ok(graph_state)
7173
}
7274
}
7375

src/graph_ui/plot_elements_scheduler.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::time::Duration;
2-
use std::{sync::mpsc, time::Instant};
2+
use std::sync::mpsc;
3+
use std::time::Instant;
34

45
use rayon::iter::{IntoParallelIterator, ParallelIterator};
56

@@ -16,9 +17,9 @@ struct FinishedWork {
1617
}
1718
pub type ExecutionResult = Result<(u64, RawPlotElements), (u64, String)>;
1819
pub struct PlotElementsScheduler {
19-
scheduled: bool,
20-
deferred: Option<ScheduledWork>,
21-
average: (Duration, usize),
20+
scheduled: bool,
21+
deferred: Option<ScheduledWork>,
22+
average: (Duration, usize),
2223
latest_received: Option<Instant>,
2324

2425
sx: mpsc::SyncSender<FinishedWork>,

0 commit comments

Comments
 (0)