summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-01-25 18:18:35 +0000
committerJoe Carstairs <me@joeac.net>2026-01-26 08:31:02 +0000
commite35e6d8ba4a7685af6a24b7cd3e77ff19e5f7b80 (patch)
treecb8cbc534905c4d4dde979f1919bfead8b5d943b /schist_desktop_gui/src/gui
parent409b5bc15951001c6d16c2bcfa747fda25cb3735 (diff)
refactor bucket_navigation_entry
Diffstat (limited to 'schist_desktop_gui/src/gui')
-rw-r--r--schist_desktop_gui/src/gui/components.rs4
-rw-r--r--schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs28
-rw-r--r--schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs (renamed from schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs)12
-rw-r--r--schist_desktop_gui/src/gui/components/buckets_view.rs34
4 files changed, 58 insertions, 20 deletions
diff --git a/schist_desktop_gui/src/gui/components.rs b/schist_desktop_gui/src/gui/components.rs
index a242b0b..b0f8faf 100644
--- a/schist_desktop_gui/src/gui/components.rs
+++ b/schist_desktop_gui/src/gui/components.rs
@@ -1,5 +1,5 @@
pub mod balances_view;
-pub mod bucket_name_and_balance;
+pub mod bucket_navigation_entry;
pub mod buckets_view;
pub mod button;
pub mod navigation;
@@ -7,7 +7,7 @@ pub mod text;
pub mod transactions_view;
pub use balances_view::BalancesView;
-pub use bucket_name_and_balance::BucketNameAndBalance;
+pub use bucket_navigation_entry::BucketNavigationEntry;
pub use buckets_view::BucketsView;
pub use button::{active_button, inactive_button, panel_button};
pub use navigation::Navigation;
diff --git a/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs b/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs
new file mode 100644
index 0000000..79b0ba9
--- /dev/null
+++ b/schist_desktop_gui/src/gui/components/bucket_navigation_entry.rs
@@ -0,0 +1,28 @@
+use bucket_name_and_balance::BucketNameAndBalance;
+use iced::Element;
+use schist_models::Bucket;
+
+use crate::gui::components::navigation;
+
+mod bucket_name_and_balance;
+
+#[derive(Clone, Debug, PartialEq)]
+pub struct BucketNavigationEntry(BucketNameAndBalance);
+
+impl BucketNavigationEntry {
+ pub fn from_bucket(bucket: &Bucket) -> Self {
+ Self(BucketNameAndBalance::new(bucket))
+ }
+
+ pub fn to_string(&self) -> String {
+ self.0.bucket.name.clone()
+ }
+}
+
+impl<'a> From<&'a BucketNavigationEntry>
+ for Element<'a, navigation::Message<BucketNavigationEntry>>
+{
+ fn from(bucket_navigation_entry: &'a BucketNavigationEntry) -> Self {
+ (&bucket_navigation_entry.0).into()
+ }
+}
diff --git a/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs
index 8a5a16e..7abca57 100644
--- a/schist_desktop_gui/src/gui/components/bucket_name_and_balance.rs
+++ b/schist_desktop_gui/src/gui/components/bucket_navigation_entry/bucket_name_and_balance.rs
@@ -4,7 +4,7 @@ use iced::{
};
use schist_models::Bucket;
-use crate::gui::components::navigation;
+use crate::gui::components::{navigation, BucketNavigationEntry};
#[derive(Clone, Debug, PartialEq)]
pub struct BucketNameAndBalance {
@@ -12,12 +12,16 @@ pub struct BucketNameAndBalance {
}
impl BucketNameAndBalance {
- pub fn new(bucket: Bucket) -> Self {
- Self { bucket }
+ pub fn new(bucket: &Bucket) -> Self {
+ Self {
+ bucket: bucket.clone(),
+ }
}
}
-impl<'a> From<&'a BucketNameAndBalance> for Element<'a, navigation::Message<BucketNameAndBalance>> {
+impl<'a> From<&'a BucketNameAndBalance>
+ for Element<'a, navigation::Message<BucketNavigationEntry>>
+{
fn from(bucket_name_and_balance: &'a BucketNameAndBalance) -> Self {
let balance_style = if bucket_name_and_balance
.bucket
diff --git a/schist_desktop_gui/src/gui/components/buckets_view.rs b/schist_desktop_gui/src/gui/components/buckets_view.rs
index cbf7abd..01c91db 100644
--- a/schist_desktop_gui/src/gui/components/buckets_view.rs
+++ b/schist_desktop_gui/src/gui/components/buckets_view.rs
@@ -6,7 +6,7 @@ use iced::{
use schist_models::Bucket;
use crate::{
- gui::components::{navigation, BucketNameAndBalance, Navigation, Text},
+ gui::components::{navigation, BucketNavigationEntry, Navigation, Text},
style::SPACING_LG,
traits::{Component, Viewable},
};
@@ -14,12 +14,12 @@ use crate::{
#[derive(Clone, Debug)]
pub struct BucketsView {
greeting: String,
- navigation: Navigation<BucketNameAndBalance>,
+ navigation: Navigation<BucketNavigationEntry>,
}
#[derive(Clone, Debug)]
pub enum Message {
- NavigationMessage(navigation::Message<BucketNameAndBalance>),
+ NavigationMessage(navigation::Message<BucketNavigationEntry>),
SelectNextBucket,
SelectPrevBucket,
SetBuckets(Vec<Bucket>),
@@ -34,14 +34,17 @@ impl BucketsView {
Self {
greeting: greeting.to_owned(),
navigation: Navigation::new(
- buckets.first().cloned().map(BucketNameAndBalance::new),
- buckets.into_iter().map(BucketNameAndBalance::new).collect(),
+ buckets.first().map(BucketNavigationEntry::from_bucket),
+ buckets
+ .iter()
+ .map(BucketNavigationEntry::from_bucket)
+ .collect(),
),
}
}
- fn update_greeting(&mut self, active_bucket: &Bucket) {
- self.greeting = format!("Hello, {} bucket!", active_bucket.name);
+ fn update_greeting(&mut self, active_entry: &str) {
+ self.greeting = format!("Hello, {}!", active_entry);
}
}
@@ -68,21 +71,24 @@ impl<'a> Component<'a, Message, Action> for BucketsView {
match message {
Message::SetBuckets(buckets) => {
self.navigation.update(navigation::Message::SetOptions(
- buckets.into_iter().map(BucketNameAndBalance::new).collect(),
+ buckets
+ .iter()
+ .map(BucketNavigationEntry::from_bucket)
+ .collect(),
));
Action::None
}
Message::NavigationMessage(message) => match self.navigation.update(message) {
- navigation::Action::SelectOption(bucket) => {
- self.update_greeting(&bucket.bucket);
+ navigation::Action::SelectOption(bucket_navigation_entry) => {
+ self.update_greeting(&bucket_navigation_entry.to_string());
Action::None
}
navigation::Action::None => Action::None,
},
Message::SelectNextBucket => {
match self.navigation.update(navigation::Message::SelectNext) {
- navigation::Action::SelectOption(bucket) => {
- self.update_greeting(&bucket.bucket);
+ navigation::Action::SelectOption(bucket_navigation_entry) => {
+ self.update_greeting(&bucket_navigation_entry.to_string());
Action::None
}
navigation::Action::None => Action::None,
@@ -90,8 +96,8 @@ impl<'a> Component<'a, Message, Action> for BucketsView {
}
Message::SelectPrevBucket => {
match self.navigation.update(navigation::Message::SelectPrev) {
- navigation::Action::SelectOption(bucket) => {
- self.update_greeting(&bucket.bucket);
+ navigation::Action::SelectOption(bucket_navigation_entry) => {
+ self.update_greeting(&bucket_navigation_entry.to_string());
Action::None
}
navigation::Action::None => Action::None,