use iced::{ widget::{ scrollable::{self, Scrollbar}, table, table::column, Scrollable, }, Element, }; use crate::{gui::components::Text, traits::Viewable}; use super::{Message, TransactionRow, TransactionsTable}; impl<'a> Viewable<'a, Message> for TransactionsTable { fn view(&'a self) -> Element<'a, Message> { let columns = [ column( Text::default("Date").width(iced::Length::Fixed(128.0)), view_date_cell, ), column( Text::default("Bucket").width(iced::Length::Fixed(128.0)), view_bucket_cell, ), column( Text::default("Payee").width(iced::Length::Fixed(256.0)), view_payee_cell, ), column( Text::default("Quantity") .width(iced::Length::Fixed(96.0)) .align_right(), view_quantity_cell, ), column( Text::default("Balance") .width(iced::Length::Fixed(96.0)) .align_right(), view_balance_cell, ), ]; let rows = self .active_account .as_ref() .map_or_else(Vec::default, |active_account| { self.transaction_rows_by_account_id .get(&active_account.id) .cloned() .unwrap_or_else(Vec::default) }); let table = Scrollable::new(table(columns, rows)).direction(scrollable::Direction::Both { horizontal: Scrollbar::default(), vertical: Scrollbar::default(), }); table.into() } } fn view_date_cell(row: TransactionRow) -> Text { Text::default(row.date.format("%e %b %Y").as_str()) .width(iced::Length::Fixed(128.0)) .small() .clip() } fn view_bucket_cell(row: TransactionRow) -> Text { Text::default(&row.bucket) .style(row.bucket_font_style) .width(iced::Length::Fixed(128.0)) .small() .clip() } fn view_payee_cell(row: TransactionRow) -> Text { Text::default(&row.payee) .style(row.payee_font_style) .width(iced::Length::Fixed(256.0)) .small() .clip() } fn view_quantity_cell(row: TransactionRow) -> Text { Text::currency(row.amount) .width(iced::Length::Fixed(96.0)) .small() .clip() .align_right() } fn view_balance_cell(row: TransactionRow) -> Text { Text::currency(row.balance) .width(iced::Length::Fixed(96.0)) .small() .clip() .align_right() }