summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2025-08-25 18:29:50 +0100
committerJoe Carstairs <me@joeac.net>2025-08-25 18:29:50 +0100
commitf4a9ff3471db5c0bd3e68b6ee517fd6887138a85 (patch)
treede6f9fbf036ee9c39e9fecdeddfec62c145b8204 /schist_desktop_gui/src/gui/components
parent86487b8ff6e691f2b261a93733df8f4cc5dc7320 (diff)
refactor balances_view
Diffstat (limited to 'schist_desktop_gui/src/gui/components')
-rw-r--r--schist_desktop_gui/src/gui/components/balances_view.rs26
-rw-r--r--schist_desktop_gui/src/gui/components/balances_view/update_balances_view.rs60
-rw-r--r--schist_desktop_gui/src/gui/components/balances_view/view_balances_view.rs47
3 files changed, 66 insertions, 67 deletions
diff --git a/schist_desktop_gui/src/gui/components/balances_view.rs b/schist_desktop_gui/src/gui/components/balances_view.rs
index 3ca37be..a1c8db3 100644
--- a/schist_desktop_gui/src/gui/components/balances_view.rs
+++ b/schist_desktop_gui/src/gui/components/balances_view.rs
@@ -3,19 +3,13 @@ mod update_balances_view;
mod view_balances_view;
mod view_group_names;
-use self::{
- update_balances_view::update_balances_view, view_balances_view::view_balances_view,
- view_group_names::view_group_names,
-};
+use self::view_group_names::view_group_names;
use schist_models::Bucket;
-use crate::{
- gui::components::{
- balances_view::make_balances_view_greeting::make_balances_view_greeting, navigation,
- Navigation, Text,
- },
- traits::{Component, Viewable},
+use crate::gui::components::{
+ balances_view::make_balances_view_greeting::make_balances_view_greeting, navigation,
+ Navigation, Text,
};
#[derive(Clone, Debug)]
@@ -49,15 +43,3 @@ impl BalancesView {
}
}
}
-
-impl<'a> Viewable<'a, Message> for BalancesView {
- fn view(&'a self) -> iced::Element<'a, Message> {
- view_balances_view(self)
- }
-}
-
-impl<'a> Component<'a, Message, Action> for BalancesView {
- fn update(&mut self, message: Message) -> Action {
- update_balances_view(self, message)
- }
-}
diff --git a/schist_desktop_gui/src/gui/components/balances_view/update_balances_view.rs b/schist_desktop_gui/src/gui/components/balances_view/update_balances_view.rs
index e7b32c3..1dd5c6f 100644
--- a/schist_desktop_gui/src/gui/components/balances_view/update_balances_view.rs
+++ b/schist_desktop_gui/src/gui/components/balances_view/update_balances_view.rs
@@ -7,42 +7,57 @@ use crate::{
traits::Component,
};
-pub fn update_balances_view(balances_view: &mut BalancesView, message: Message) -> Action {
- match message {
- Message::NavigationMessage(message) => update_navigation(balances_view, message),
- Message::SetBuckets(buckets) => set_buckets(balances_view, buckets),
- Message::SelectNextBucket => select_next_bucket(balances_view),
- Message::SelectPrevBucket => select_prev_bucket(balances_view),
+impl<'a> Component<'a, Message, Action> for BalancesView {
+ fn update(&mut self, message: Message) -> Action {
+ match message {
+ Message::NavigationMessage(message) => {
+ update_navigation(self, message);
+ Action::None
+ }
+
+ Message::SetBuckets(buckets) => {
+ set_buckets(self, buckets);
+ Action::None
+ }
+
+ Message::SelectNextBucket => {
+ select_next_bucket(self);
+ Action::None
+ }
+
+ Message::SelectPrevBucket => {
+ select_prev_bucket(self);
+ Action::None
+ }
+ }
}
}
-fn select_prev_bucket(balances_view: &mut BalancesView) -> Action {
+fn select_prev_bucket(balances_view: &mut BalancesView) -> () {
match balances_view
.navigation
.update(navigation::Message::SelectPrev)
{
navigation::Action::SelectOption(option) => {
balances_view.greeting = make_balances_view_greeting(Some(option));
- Action::None
}
- navigation::Action::None => Action::None,
- }
+ navigation::Action::None => {}
+ };
}
-fn select_next_bucket(balances_view: &mut BalancesView) -> Action {
+fn select_next_bucket(balances_view: &mut BalancesView) -> () {
match balances_view
.navigation
.update(navigation::Message::SelectNext)
{
navigation::Action::SelectOption(option) => {
balances_view.greeting = make_balances_view_greeting(Some(option));
- Action::None
}
- navigation::Action::None => Action::None,
- }
+ navigation::Action::None => {}
+ };
}
-fn set_buckets(balances_view: &mut BalancesView, buckets: Vec<schist_models::Bucket>) -> Action {
+fn set_buckets(balances_view: &mut BalancesView, buckets: Vec<schist_models::Bucket>) -> () {
balances_view.buckets = buckets.clone();
match balances_view
.navigation
@@ -50,23 +65,18 @@ fn set_buckets(balances_view: &mut BalancesView, buckets: Vec<schist_models::Buc
{
navigation::Action::SelectOption(option) => {
balances_view.greeting = make_balances_view_greeting(Some(option));
- Action::None
}
- navigation::Action::None => Action::None,
- }
+ navigation::Action::None => {}
+ };
}
-fn update_navigation(
- balances_view: &mut BalancesView,
- message: navigation::Message<Text>,
-) -> Action {
+fn update_navigation(balances_view: &mut BalancesView, message: navigation::Message<Text>) -> () {
match balances_view.navigation.update(message) {
navigation::Action::SelectOption(group_name) => {
balances_view.greeting = make_balances_view_greeting(Some(group_name));
- Action::None
}
- navigation::Action::None => Action::None,
- }
+ navigation::Action::None => {}
+ };
}
#[cfg(test)]
diff --git a/schist_desktop_gui/src/gui/components/balances_view/view_balances_view.rs b/schist_desktop_gui/src/gui/components/balances_view/view_balances_view.rs
index 6a64508..22f22b6 100644
--- a/schist_desktop_gui/src/gui/components/balances_view/view_balances_view.rs
+++ b/schist_desktop_gui/src/gui/components/balances_view/view_balances_view.rs
@@ -1,23 +1,30 @@
-use iced::widget::{column, row, Container};
-use iced::{alignment, Element, Length};
+use iced::{
+ alignment,
+ widget::{column, row, Container},
+ Length,
+};
-use crate::gui::components::Text;
-use crate::gui::components::{balances_view::Message, BalancesView};
-use crate::style::SPACING_LG;
-use crate::traits::Viewable;
+use crate::{
+ gui::components::{balances_view::Message, BalancesView, Text},
+ style::SPACING_LG,
+ traits::Viewable,
+};
-pub fn view_balances_view<'a>(balances_view: &'a BalancesView) -> Element<'a, Message> {
- let navigation = balances_view
- .navigation
- .view()
- .map(Message::NavigationMessage);
- let main_content = column![Text::default(&balances_view.greeting).as_element()];
- row![
- Container::new(navigation).width(Length::FillPortion(1)),
- Container::new(main_content).width(Length::FillPortion(3)),
- ]
- .align_y(alignment::Vertical::Center)
- .height(Length::Fill)
- .spacing(SPACING_LG)
- .into()
+impl<'a> Viewable<'a, Message> for BalancesView {
+ fn view(&'a self) -> iced::Element<'a, Message> {
+ let balances_view: &'a BalancesView = self;
+ let navigation = balances_view
+ .navigation
+ .view()
+ .map(Message::NavigationMessage);
+ let main_content = column![Text::default(&balances_view.greeting).as_element()];
+ row![
+ Container::new(navigation).width(Length::FillPortion(1)),
+ Container::new(main_content).width(Length::FillPortion(3)),
+ ]
+ .align_y(alignment::Vertical::Center)
+ .height(Length::Fill)
+ .spacing(SPACING_LG)
+ .into()
+ }
}