diff --git a/Cargo.toml b/Cargo.toml index 1f853a0..de68f1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,13 @@ anyhow = "1.0.75" directories = "5.0.1" either = "1.9.0" iced = { version = "0.10.0", features = ["lazy"] } -iced_aw = { version = "0.7.0", default-features = false, features = ["modal", "card", "number_input", "selection_list"] } +iced_aw = { version = "0.7.0", default-features = false, features = [ + "modal", + "card", + "number_input", + "selection_list", + "tab_bar", +] } itertools = "0.11.0" peg = "0.8.2" serde = { version = "1.0.192", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 50d39d1..7ba0a81 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,12 @@ use std::{ use anyhow::anyhow; use directories::ProjectDirs; use edit::{EditMessage, EditState, Spendings}; -use iced::{font, subscription, window, Application, Command, Event, Settings, Theme}; +use iced::{ + font, subscription, + widget::{column, text}, + window, Application, Command, Event, Settings, Theme, +}; +use iced_aw::{TabBar, TabBarStyles, TabLabel}; use serde::{Deserialize, Serialize}; type Element<'a> = iced::Element<'a, Message>; @@ -171,11 +176,62 @@ enum Message { Load(ReportDate), InitFrom(ReportDate), Edit(EditMessage), + ChangeTab(CurrentView), +} + +// enum CompareLoad { +// Current, +// Report(ReportDate), +// } +// +// enum CompareSide { +// Left, +// Right, +// } +// +// struct Compare<'a, F> { +// left: Option<&'a dyn Spendings>, +// right: Option<&'a dyn Spendings>, +// on_load: F, +// } +// +// #[derive(Default)] +// struct CompareState {} +// +// enum CompareMsg { +// LoadLeft(CompareLoad), +// LoadRight(CompareLoad), +// } +// +// impl<'a, M, F> iced::widget::Component for Compare<'a, F> +// where +// F: FnMut(CompareSide, CompareLoad) -> M, +// { +// type State = CompareState; +// type Event = CompareMsg; +// +// fn update(&mut self, _state: &mut Self::State, event: Self::Event) -> Option { +// match event { +// CompareMsg::LoadLeft(d) => Some((self.on_load)(CompareSide::Left, d)), +// CompareMsg::LoadRight(d) => Some((self.on_load)(CompareSide::Right, d)), +// } +// } +// +// fn view(&self, _state: &Self::State) -> iced_aw::Element<'_, Self::Event, Renderer> { +// text("todo").into() +// } +// } + +#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)] +enum CurrentView { + Edit, + Compare, } struct Glaurung { config: Config, edit: EditState, + view: CurrentView, archive: BTreeMap, } @@ -191,6 +247,7 @@ impl Application for Glaurung { config: config.config, edit: EditState::new(config.save_file), archive: config.save.archive, + view: CurrentView::Edit, }; this.edit.load(None, config.save.current); @@ -237,13 +294,24 @@ impl Application for Glaurung { } } Message::Edit(m) => self.edit.update(m), + Message::ChangeTab(t) => self.view = t, } Command::none() } fn view(&self) -> Element { - self.edit.view(&self.archive, &self.config) + let bar = TabBar::new(Message::ChangeTab) + .push(CurrentView::Edit, TabLabel::Text("Edit".into())) + .push(CurrentView::Compare, TabLabel::Text("Compare".into())) + .set_active_tab(&self.view) + .style(TabBarStyles::Dark); + let content = match self.view { + CurrentView::Edit => self.edit.view(&self.archive, &self.config), + CurrentView::Compare => text("todo").into(), + }; + + column![bar, content].into() } fn theme(&self) -> iced::Theme {