From 96d304338717d50a7365b431ccb357942b414ea7 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sun, 21 Jan 2024 21:32:06 +0100 Subject: set darktheme and fix text overflow in canvas --- src/main.rs | 8 +++++++- src/ui/graph.rs | 17 +++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index a00d137..5565edb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,6 +37,7 @@ impl Application for Graph { &pane, Pane::new(PaneKind::GraphPane), ); + ( Graph { graph_canvas: GraphCanvas::new(), @@ -73,6 +74,7 @@ impl Application for Graph { self.graph_canvas.clear(); } Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { + self.graph_canvas.clear(); self.panes.resize(&split, ratio); } } @@ -95,7 +97,7 @@ impl Application for Graph { text_input("f(x) = x^2", f) .on_input(move |s| Message::InputChanged(s, i)) .on_submit(Message::UpdateFunction(i)), - button("R").on_press(Message::RemoveFunction(i)) + button("-").on_press(Message::RemoveFunction(i)) ].padding(5) ); } @@ -126,4 +128,8 @@ impl Application for Graph { .padding(10) .into() } + + fn theme(&self) -> Self::Theme { + Theme::Dark + } } diff --git a/src/ui/graph.rs b/src/ui/graph.rs index d02b587..198c020 100644 --- a/src/ui/graph.rs +++ b/src/ui/graph.rs @@ -36,7 +36,8 @@ impl GraphCanvas { pub fn push(&mut self, f: &str) { if let Ok(f) = ExpressionFunction::from_string(f.to_string(), self.ctx.operations()) { - self.ctx.set_function(f.name(), std::sync::Arc::new(f.clone())); + self.ctx + .set_function(f.name(), std::sync::Arc::new(f.clone())); self.funcs.lock().unwrap().push(Some(FunctionCache::new(f))); } else { self.funcs.lock().unwrap().push(None); @@ -50,12 +51,12 @@ impl GraphCanvas { } if let Ok(f) = ExpressionFunction::from_string(f.to_string(), self.ctx.operations()) { - self.ctx.set_function(f.name(), std::sync::Arc::new(f.clone())); + self.ctx + .set_function(f.name(), std::sync::Arc::new(f.clone())); vf[i] = Some(FunctionCache::new(f)); } else { vf[i] = None; } - } } @@ -80,12 +81,12 @@ pub struct GraphState { impl GraphState { fn view_rectangle(&self, frame: &Frame, step: usize) -> Rectangle { let s = Size::new( - self.map_to_step((frame.width() / self.scale) * step as f32 + 10.0, step), - self.map_to_step((frame.height() / self.scale) * step as f32 + 10.0, step), + self.map_to_step((frame.width() / self.scale) + 2.0 * step as f32, step), + self.map_to_step((frame.height() / self.scale) + 2.0 * step as f32, step), ); let p = Point::new( - self.map_to_step(-self.center.x / self.scale - s.width / 2.0, step), - self.map_to_step(-self.center.y / self.scale - s.height / 2.0, step), + self.map_to_step(-self.center.x / self.scale - s.width / 2.0 - step as f32, step), + self.map_to_step(-self.center.y / self.scale - s.height / 2.0 - step as f32, step), ); Rectangle::new(p, s) } @@ -191,7 +192,7 @@ impl canvas::Program for GraphCanvas { ); frame.with_save(|frame| { - for x in (rect.x as i64..x_end).step_by(step) { + for x in (rect.x as i64 + 2 * step as i64..x_end).step_by(step) { let p = Point::new(x as f32, 0.0); frame.fill(&Path::circle(p, 10.0 / state.scale), zcolor); frame.fill_text(Text { -- cgit v1.2.3-70-g09d2