Add outputs sections
This commit is contained in:
parent
fd57d4644f
commit
017137dc33
1 changed files with 24 additions and 8 deletions
32
src/main.rs
32
src/main.rs
|
|
@ -524,6 +524,7 @@ where
|
||||||
enum Message {
|
enum Message {
|
||||||
Event(Event),
|
Event(Event),
|
||||||
AddRecurring(String, f64),
|
AddRecurring(String, f64),
|
||||||
|
AddSaving(String, f64),
|
||||||
FontLoaded(Result<(), font::Error>),
|
FontLoaded(Result<(), font::Error>),
|
||||||
AddVariable(String),
|
AddVariable(String),
|
||||||
EditVariable(String, String),
|
EditVariable(String, String),
|
||||||
|
|
@ -535,6 +536,7 @@ struct Glaurung {
|
||||||
config: Config,
|
config: Config,
|
||||||
recurring: BTreeMap<String, f64>,
|
recurring: BTreeMap<String, f64>,
|
||||||
variable: BTreeMap<String, (String, Option<f64>)>,
|
variable: BTreeMap<String, (String, Option<f64>)>,
|
||||||
|
savings: BTreeMap<String, f64>,
|
||||||
save_file: PathBuf,
|
save_file: PathBuf,
|
||||||
earnings_1: f64,
|
earnings_1: f64,
|
||||||
earnings_2: f64,
|
earnings_2: f64,
|
||||||
|
|
@ -545,6 +547,8 @@ struct SaveFile {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
recurring: BTreeMap<String, f64>,
|
recurring: BTreeMap<String, f64>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
savings: BTreeMap<String, f64>,
|
||||||
|
#[serde(default)]
|
||||||
variable: HashMap<String, String>,
|
variable: HashMap<String, String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
earnings_1: f64,
|
earnings_1: f64,
|
||||||
|
|
@ -570,6 +574,7 @@ impl Application for Glaurung {
|
||||||
Self {
|
Self {
|
||||||
config: config.config,
|
config: config.config,
|
||||||
recurring: config.save.recurring,
|
recurring: config.save.recurring,
|
||||||
|
savings: config.save.savings,
|
||||||
variable: config
|
variable: config
|
||||||
.save
|
.save
|
||||||
.variable
|
.variable
|
||||||
|
|
@ -602,6 +607,9 @@ impl Application for Glaurung {
|
||||||
Message::AddRecurring(name, value) => {
|
Message::AddRecurring(name, value) => {
|
||||||
self.recurring.insert(name, value);
|
self.recurring.insert(name, value);
|
||||||
}
|
}
|
||||||
|
Message::AddSaving(name, value) => {
|
||||||
|
self.savings.insert(name, value);
|
||||||
|
}
|
||||||
Message::FontLoaded(r) => r.expect("could not load font"),
|
Message::FontLoaded(r) => r.expect("could not load font"),
|
||||||
Message::Event(ev) => {
|
Message::Event(ev) => {
|
||||||
if let Event::Window(window::Event::CloseRequested) = ev {
|
if let Event::Window(window::Event::CloseRequested) = ev {
|
||||||
|
|
@ -615,6 +623,7 @@ impl Application for Glaurung {
|
||||||
serde_json::to_writer(
|
serde_json::to_writer(
|
||||||
save_file,
|
save_file,
|
||||||
&SaveFile {
|
&SaveFile {
|
||||||
|
savings: std::mem::take(&mut self.savings),
|
||||||
recurring: std::mem::take(&mut self.recurring),
|
recurring: std::mem::take(&mut self.recurring),
|
||||||
variable: std::mem::take(&mut self.variable)
|
variable: std::mem::take(&mut self.variable)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
@ -652,6 +661,12 @@ impl Application for Glaurung {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element {
|
fn view(&self) -> Element {
|
||||||
|
let total_spendings = self
|
||||||
|
.recurring
|
||||||
|
.values()
|
||||||
|
.chain(self.variable.values().flat_map(|(_, f)| f))
|
||||||
|
.sum::<f64>();
|
||||||
|
|
||||||
column![
|
column![
|
||||||
text("Spendings").size(TEXT_H1),
|
text("Spendings").size(TEXT_H1),
|
||||||
component(FixedAmounts {
|
component(FixedAmounts {
|
||||||
|
|
@ -673,14 +688,7 @@ impl Application for Glaurung {
|
||||||
let def = rule::StyleSheet::appearance(theme, &theme::Rule::Default);
|
let def = rule::StyleSheet::appearance(theme, &theme::Rule::Default);
|
||||||
rule::Appearance { width: 3, ..def }
|
rule::Appearance { width: 3, ..def }
|
||||||
}),
|
}),
|
||||||
text(&format!(
|
text(&format!("Total spendings: {total_spendings} €",)).size(TEXT_EMPH2),
|
||||||
"Total spendings: {} €",
|
|
||||||
self.recurring
|
|
||||||
.values()
|
|
||||||
.chain(self.variable.values().flat_map(|(_, f)| f))
|
|
||||||
.sum::<f64>()
|
|
||||||
))
|
|
||||||
.size(TEXT_EMPH2),
|
|
||||||
text("Earnings").size(TEXT_H1),
|
text("Earnings").size(TEXT_H1),
|
||||||
row![
|
row![
|
||||||
text(&self.config.person_1).size(TEXT_EMPH1),
|
text(&self.config.person_1).size(TEXT_EMPH1),
|
||||||
|
|
@ -705,6 +713,14 @@ impl Application for Glaurung {
|
||||||
self.earnings_1 + self.earnings_2,
|
self.earnings_1 + self.earnings_2,
|
||||||
))
|
))
|
||||||
.size(TEXT_EMPH2),
|
.size(TEXT_EMPH2),
|
||||||
|
text("Outputs").size(TEXT_H1),
|
||||||
|
text(&format!("Main account: {total_spendings} €")).size(TEXT_EMPH2),
|
||||||
|
component(FixedAmounts {
|
||||||
|
items: &self.savings,
|
||||||
|
title: "Savings",
|
||||||
|
add_label: "Add a saving output",
|
||||||
|
on_add: Message::AddSaving,
|
||||||
|
}),
|
||||||
]
|
]
|
||||||
.max_width(500)
|
.max_width(500)
|
||||||
.padding(5)
|
.padding(5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue