diff options
| -rw-r--r-- | Cargo.lock | 55 | ||||
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/main.rs | 63 | ||||
| -rw-r--r-- | src/ui/mod.rs | 4 | ||||
| -rw-r--r-- | src/ui/pane.rs | 18 |
5 files changed, 123 insertions, 19 deletions
@@ -870,6 +870,12 @@ dependencies = [ ] [[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] name = "hermit-abi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1025,6 +1031,7 @@ dependencies = [ "iced_runtime", "iced_style", "num-traits", + "ouroboros", "thiserror", "unicode-segmentation", ] @@ -1608,6 +1615,30 @@ dependencies = [ ] [[package]] +name = "ouroboros" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2ba07320d39dfea882faa70554b4bd342a5f273ed59ba7c1c6b4c840492c954" +dependencies = [ + "aliasable", + "ouroboros_macro", + "static_assertions", +] + +[[package]] +name = "ouroboros_macro" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4c6225c69b4ca778c0aea097321a64c421cf4577b331c61b229267edabb6f8" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.48", +] + +[[package]] name = "owned_ttf_parser" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1797,6 +1828,30 @@ dependencies = [ ] [[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] name = "proc-macro2" version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] -iced = { version = "0.10.0", features = ["canvas", "advanced"] } +iced = { version = "0.10.0", features = ["canvas", "advanced", "lazy"] } diff --git a/src/main.rs b/src/main.rs index d2effe6..b21585f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,14 @@ pub mod math; pub mod ui; use function_cache::FunctionCache; -use iced::executor; -use iced::widget::column; -use iced::widget::text_input; -use iced::widget::{canvas, container}; +use iced::{executor, Renderer}; +use iced::widget::{canvas, container, pane_grid, responsive, text, text_input, PaneGrid}; use iced::{Application, Command, Element, Length, Settings, Theme}; use math::expression_function::ExpressionFunction; use std::sync::Mutex; use ui::graph::GraphCanvas; use ui::Message; +use ui::pane::{Pane, PaneKind}; pub fn main() -> iced::Result { Graph::run(Settings { @@ -20,8 +19,8 @@ pub fn main() -> iced::Result { }) } -#[derive(Default)] struct Graph { + panes: pane_grid::State<Pane>, input_state: String, graph_canvas: GraphCanvas, } @@ -33,12 +32,18 @@ impl Application for Graph { type Flags = (); fn new(_flags: ()) -> (Self, Command<Message>) { + let (mut panes, pane) = pane_grid::State::new(Pane::new(PaneKind::FunctionPane)); + panes.split( + pane_grid::Axis::Vertical, + &pane, + Pane::new(PaneKind::GraphPane), + ); let default_func = "f(x) = x^2".to_string(); ( Graph { graph_canvas: GraphCanvas::new(&default_func), input_state: default_func, - ..Default::default() + panes, }, Command::none(), ) @@ -64,25 +69,47 @@ impl Application for Graph { Message::UpdateScreen => { self.graph_canvas.clear(); } + Message::Resized(pane_grid::ResizeEvent { split, ratio }) => { + self.panes.resize(&split, ratio); + } } Command::none() } fn view(&self) -> Element<Message> { - let input = text_input("x", &self.input_state) - .on_input(Message::InputChanged) - .on_submit(Message::UpdateFunction) - .padding(15) - .size(30); - let canvas = canvas(&self.graph_canvas) - .width(Length::Fill) - .height(Length::Fill); + let pane_grid = PaneGrid::new(&self.panes, |_id, pane, _| { + pane_grid::Content::new(responsive(move |_size| { + let child : Element<'_, Message, Renderer> = match pane.kind { + PaneKind::GraphPane => { + canvas(&self.graph_canvas) + .width(Length::Fill) + .height(Length::Fill).into() + } + PaneKind::FunctionPane => { + text_input("x", &self.input_state) + .on_input(Message::InputChanged) + .on_submit(Message::UpdateFunction) + .padding(15) + .size(30).into() + }, + _ => text("").into(), + }; - let container = container(canvas) + container(child) + .width(Length::Fill) + .height(Length::Fill) + .into() + })) + }) + .width(Length::Fill) + .height(Length::Fill) + .spacing(10) + .on_resize(10, Message::Resized); + + container(pane_grid) .width(Length::Fill) .height(Length::Fill) - .padding(20); - - column![input, container].into() + .padding(10) + .into() } } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 1e7fffe..b7c11fb 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,8 +1,12 @@ +use iced::widget::pane_grid::ResizeEvent; + pub mod graph; +pub mod pane; #[derive(Debug, Clone)] pub enum Message { InputChanged(String), UpdateFunction, UpdateScreen, + Resized(ResizeEvent) } diff --git a/src/ui/pane.rs b/src/ui/pane.rs new file mode 100644 index 0000000..86149d4 --- /dev/null +++ b/src/ui/pane.rs @@ -0,0 +1,18 @@ +#[derive(Debug, Clone, Default)] +pub enum PaneKind { + #[default] + EmptyPane, + FunctionPane, + GraphPane, +} + +#[derive(Clone, Default, Debug)] +pub struct Pane { + pub kind: PaneKind, +} + +impl Pane { + pub fn new(kind: PaneKind) -> Self { + Self { kind } + } +} |