diff options
| -rw-r--r-- | schist_desktop_gui/src/gui/components/table/view_table.rs | 2 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/components/text.rs | 64 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/components/transactions_view.rs | 2 |
3 files changed, 53 insertions, 15 deletions
diff --git a/schist_desktop_gui/src/gui/components/table/view_table.rs b/schist_desktop_gui/src/gui/components/table/view_table.rs index 725c5ff..f082b83 100644 --- a/schist_desktop_gui/src/gui/components/table/view_table.rs +++ b/schist_desktop_gui/src/gui/components/table/view_table.rs @@ -48,7 +48,7 @@ where } fn format_string(text: &String) -> Text { - Text::default(text).weak().small() + Text::default(text).weak().small().clip() } fn format_currency(amount: i32) -> Text { diff --git a/schist_desktop_gui/src/gui/components/text.rs b/schist_desktop_gui/src/gui/components/text.rs index 36a6a13..7a685c1 100644 --- a/schist_desktop_gui/src/gui/components/text.rs +++ b/schist_desktop_gui/src/gui/components/text.rs @@ -1,5 +1,7 @@ use std::borrow::Borrow; +use iced::widget::container; + use crate::{impl_focusable, style::*}; #[derive(Clone, Debug, PartialEq)] @@ -7,6 +9,7 @@ pub struct Text { pub content: String, align: Alignment, colour: Option<Colour>, + overflow_strategy: OverflowStrategy, size: Option<Size>, strength: Option<Strength>, width: iced::Length, @@ -27,6 +30,12 @@ enum Colour { } #[derive(Clone, Debug, PartialEq)] +enum OverflowStrategy { + Grow, + Clip, +} + +#[derive(Clone, Debug, PartialEq)] enum Strength { Base, Weak, @@ -45,6 +54,7 @@ impl Text { align: Alignment::Left, content: String::from(content), colour: Some(Colour::Primary), + overflow_strategy: OverflowStrategy::Grow, size: Some(Size::Base), strength: Some(Strength::Base), is_focused: false, @@ -57,6 +67,7 @@ impl Text { align: Alignment::Left, content: String::from(content), colour: None, + overflow_strategy: OverflowStrategy::Grow, size: None, strength: None, width: iced::Length::Shrink, @@ -64,7 +75,10 @@ impl Text { } } - pub fn as_element<'a, Message>(self) -> iced::Element<'a, Message> { + pub fn as_element<'a, Message>(self) -> iced::Element<'a, Message> + where + Message: 'a, + { <Self as Into<iced::Element<'a, Message>>>::into(self) } @@ -120,15 +134,28 @@ impl Text { ..self.clone() } } + + pub fn clip(&self) -> Self { + Self { + overflow_strategy: OverflowStrategy::Clip, + ..self.clone() + } + } } -impl<'a, Message> From<Text> for iced::Element<'a, Message> { +impl<'a, Message> From<Text> for iced::Element<'a, Message> +where + Message: 'a, +{ fn from(text: Text) -> Self { text_as_element(text) } } -impl<'a, Message> From<&'a Text> for iced::Element<'a, Message> { +impl<'a, Message> From<&'a Text> for iced::Element<'a, Message> +where + Message: 'a, +{ fn from(text: &'a Text) -> Self { text_as_element(text) } @@ -137,23 +164,27 @@ impl<'a, Message> From<&'a Text> for iced::Element<'a, Message> { fn text_as_element<'a, T, Message>(text: T) -> iced::Element<'a, Message> where T: Borrow<Text> + 'a, + Message: 'a, { - iced::widget::text(text.borrow().content.clone()) + let overflow_strategy = &text.borrow().overflow_strategy.clone(); + + let text_elem: iced::widget::Text = iced::widget::text(text.borrow().content.clone()) .size(match text.borrow().size { - Some(Size::VSmall) => TEXT_SIZE_V_SM, - Some(Size::Small) => TEXT_SIZE_SM, - Some(Size::Base) | None => TEXT_SIZE_BASE, + Some(Size::VSmall) => u32::from(TEXT_SIZE_V_SM), + Some(Size::Small) => u32::from(TEXT_SIZE_SM), + Some(Size::Base) | None => u32::from(TEXT_SIZE_BASE), }) .align_x(match &text.borrow().align { Alignment::Left => iced::alignment::Horizontal::Left, Alignment::Right => iced::alignment::Horizontal::Right, }) + .wrapping(match overflow_strategy { + OverflowStrategy::Grow => iced::widget::text::Wrapping::default(), + OverflowStrategy::Clip => iced::widget::text::Wrapping::None, + }) .width(text.borrow().width) .style(move |theme: &iced::Theme| iced::widget::text::Style { - color: match ( - &text.borrow().borrow().colour, - &text.borrow().borrow().strength, - ) { + color: match (&text.borrow().colour, &text.borrow().strength) { (Some(Colour::Danger), Some(Strength::Base) | None) => { Some(theme.extended_palette().danger.base.text) } @@ -174,8 +205,15 @@ where } (None, _) => None, }, - }) - .into() + }); + + match overflow_strategy { + OverflowStrategy::Grow => text_elem.into(), + OverflowStrategy::Clip => container::<'a, Message, _, _>(text_elem) + .height(iced::Length::Shrink) + .clip(true) + .into(), + } } impl_focusable!(Text); diff --git a/schist_desktop_gui/src/gui/components/transactions_view.rs b/schist_desktop_gui/src/gui/components/transactions_view.rs index e78a142..51877cf 100644 --- a/schist_desktop_gui/src/gui/components/transactions_view.rs +++ b/schist_desktop_gui/src/gui/components/transactions_view.rs @@ -60,7 +60,7 @@ impl TransactionsView { cols: vec![ table::Column::new(0, "Date"), table::Column::new(1, "Bucket"), - table::Column::new(2, "Payee").mul_width(1.5), + table::Column::new(2, "Payee").mul_width(2.0), table::Column::new(3, "Quantity").mul_width(0.67), table::Column::new(4, "Balance").mul_width(0.67), ], |
