diff options
Diffstat (limited to 'schist_desktop_gui/src/gui/components/table')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/table/view_table.rs | 61 |
1 files changed, 0 insertions, 61 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 deleted file mode 100644 index f082b83..0000000 --- a/schist_desktop_gui/src/gui/components/table/view_table.rs +++ /dev/null @@ -1,61 +0,0 @@ -use std::{fmt::Debug, hash::Hash}; - -use iced::widget::{ - column, container, row, scrollable, scrollable::Direction as ScrollableDirection, -}; - -use crate::{gui::components::Text, style::SPACING_MD, traits::Viewable}; - -use super::{Message, Table, Value}; - -impl<'a, Ix> Viewable<'a, Message> for Table<Ix> -where - Ix: Clone + Debug + Eq + Hash, -{ - fn view(&'a self) -> iced::Element<'a, Message> { - let headers = row(self.cols.iter().map(|col| { - container(Text::default(&col.name)) - .width(iced::Length::Fixed(col.width)) - .into() - })) - .spacing(u32::from(SPACING_MD)); - - let rows = column(self.rows.iter().map(|row_data| { - row(self.cols.iter().map(|col| { - container( - row_data - .get(&col.index) - .map(|datum| match datum { - Value::String(text) => format_string(text), - Value::Currency(amount) => format_currency(*amount), - }) - .unwrap_or_else(|| Text::default("")), - ) - .width(iced::Length::Fixed(col.width)) - .into() - })) - .spacing(u32::from(SPACING_MD)) - .into() - })); - - scrollable(column![headers, rows].spacing(u32::from(SPACING_MD))) - .direction(ScrollableDirection::Both { - horizontal: Default::default(), - vertical: Default::default(), - }) - .into() - } -} - -fn format_string(text: &String) -> Text { - Text::default(text).weak().small().clip() -} - -fn format_currency(amount: i32) -> Text { - let text = if amount >= 0 { - format!(" {} · {} ", amount / 100, amount % 100) - } else { - format!("({} · {})", -amount / 100, -amount % 100) - }; - format_string(&text).align_right().width(iced::Length::Fill) -} |
