Add a tab bar for different views
This commit is contained in:
parent
32ab584130
commit
a599da6fbc
2 changed files with 77 additions and 3 deletions
|
|
@ -9,7 +9,13 @@ anyhow = "1.0.75"
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
either = "1.9.0"
|
either = "1.9.0"
|
||||||
iced = { version = "0.10.0", features = ["lazy"] }
|
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"
|
itertools = "0.11.0"
|
||||||
peg = "0.8.2"
|
peg = "0.8.2"
|
||||||
serde = { version = "1.0.192", features = ["derive"] }
|
serde = { version = "1.0.192", features = ["derive"] }
|
||||||
|
|
|
||||||
72
src/main.rs
72
src/main.rs
|
|
@ -9,7 +9,12 @@ use std::{
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use edit::{EditMessage, EditState, Spendings};
|
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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
type Element<'a> = iced::Element<'a, Message>;
|
type Element<'a> = iced::Element<'a, Message>;
|
||||||
|
|
@ -171,11 +176,62 @@ enum Message {
|
||||||
Load(ReportDate),
|
Load(ReportDate),
|
||||||
InitFrom(ReportDate),
|
InitFrom(ReportDate),
|
||||||
Edit(EditMessage),
|
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<M, Renderer> 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<M> {
|
||||||
|
// 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 {
|
struct Glaurung {
|
||||||
config: Config,
|
config: Config,
|
||||||
edit: EditState,
|
edit: EditState,
|
||||||
|
view: CurrentView,
|
||||||
|
|
||||||
archive: BTreeMap<ReportDate, Report>,
|
archive: BTreeMap<ReportDate, Report>,
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +247,7 @@ impl Application for Glaurung {
|
||||||
config: config.config,
|
config: config.config,
|
||||||
edit: EditState::new(config.save_file),
|
edit: EditState::new(config.save_file),
|
||||||
archive: config.save.archive,
|
archive: config.save.archive,
|
||||||
|
view: CurrentView::Edit,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.edit.load(None, config.save.current);
|
this.edit.load(None, config.save.current);
|
||||||
|
|
@ -237,13 +294,24 @@ impl Application for Glaurung {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Message::Edit(m) => self.edit.update(m),
|
Message::Edit(m) => self.edit.update(m),
|
||||||
|
Message::ChangeTab(t) => self.view = t,
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::none()
|
Command::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element {
|
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 {
|
fn theme(&self) -> iced::Theme {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue