diff --git a/Cargo.lock b/Cargo.lock index 1c4501a..161966d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -114,12 +114,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aliasable" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd" - [[package]] name = "allocator-api2" version = "0.2.16" @@ -1710,7 +1704,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6368dbd2c6685fb84fc6e6a4749917ddc98905793fd06341c7e11a2504f2724" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro2 0.4.30", "quote 0.6.13", "syn 0.15.44", @@ -3257,12 +3251,6 @@ dependencies = [ "unicode-segmentation", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "hermit-abi" version = "0.1.19" @@ -3610,8 +3598,7 @@ dependencies = [ [[package]] name = "iced_aw" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "129deba9897243dd59c2038e2267a691e392c94e569680066ee63b1164429490" +source = "git+https://github.com/yeastplume/iced_aw.git?branch=table_widget#b698515cc0bd7f712a2b53061e49f11befe9cc16" dependencies = [ "cfg-if 1.0.0", "iced", @@ -3754,7 +3741,6 @@ dependencies = [ "iced_runtime", "iced_style", "num-traits 0.2.18", - "ouroboros", "thiserror", "unicode-segmentation", ] @@ -3997,15 +3983,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.4.8" @@ -5121,31 +5098,6 @@ dependencies = [ "num-traits 0.2.18", ] -[[package]] -name = "ouroboros" -version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b7be5a8a3462b752f4be3ff2b2bf2f7f1d00834902e46be2a4d68b87b0573c" -dependencies = [ - "aliasable", - "ouroboros_macro", - "static_assertions", -] - -[[package]] -name = "ouroboros_macro" -version = "0.18.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b645dcde5f119c2c454a92d0dfa271a2a3b205da92e4292a68ead4bdbfde1f33" -dependencies = [ - "heck 0.4.1", - "itertools 0.12.1", - "proc-macro2 1.0.79", - "proc-macro2-diagnostics", - "quote 1.0.35", - "syn 2.0.57", -] - [[package]] name = "owned_ttf_parser" version = "0.20.0" @@ -5692,19 +5644,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proc-macro2-diagnostics" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af066a9c399a26e020ada66a034357a868728e72cd426f3adcd35f80d88d88c8" -dependencies = [ - "proc-macro2 1.0.79", - "quote 1.0.35", - "syn 2.0.57", - "version_check", - "yansi", -] - [[package]] name = "profiling" version = "1.0.15" @@ -7039,7 +6978,7 @@ version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro-error", "proc-macro2 1.0.79", "quote 1.0.35", @@ -7064,7 +7003,7 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro2 1.0.79", "quote 1.0.35", "syn 1.0.109", @@ -7076,7 +7015,7 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec" dependencies = [ - "heck 0.3.3", + "heck", "proc-macro2 1.0.79", "quote 1.0.35", "syn 1.0.109", @@ -7203,8 +7142,8 @@ checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6" dependencies = [ "anyhow", "cfg-expr", - "heck 0.3.3", - "itertools 0.10.5", + "heck", + "itertools", "pkg-config", "strum 0.21.0", "strum_macros 0.21.1", @@ -8872,12 +8811,6 @@ dependencies = [ "linked-hash-map", ] -[[package]] -name = "yansi" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" - [[package]] name = "yazi" version = "0.1.6" diff --git a/Cargo.toml b/Cargo.toml index 641f9cd..bd47478 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ iced_futures = { version = "0.12", features = ["async-std"] } iced_style = {version = "0.12"} iced_renderer = { version = "0.12" } iced_core = { version = "0.12" } -iced_aw = { version = "0.8", default-features = false, features = ["card", "modal"]} +#iced_aw = { path = "../iced_aw", default-features = false, features = ["card", "modal", "table"]} +iced_aw = { git = "https://github.com/yeastplume/iced_aw.git", branch = "table_widget", default-features = false, features = ["card", "modal", "table"]} plotters-iced = "0.10.0" plotters="0.3" diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 4e79570..7c67d75 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -102,7 +102,8 @@ iced_core = { version = "0.12" } iced_style = "0.12" iced_graphics = { version = "0.12" } iced_renderer = { version = "0.12", features = ["wgpu"] } -iced_aw = { version = "0.8", default-features = false, features = ["card", "modal"]} +#iced_aw = { path = "../../../iced_aw", default-features = false, features = ["card", "modal", "table"]} +iced_aw = { git = "https://github.com/yeastplume/iced_aw.git", branch = "table_widget", default-features = false, features = ["card", "modal", "table"]} [dev-dependencies] tempfile = "3.2.0" diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index fc743ad..7832090 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -9,12 +9,10 @@ pub mod fs; pub mod logger; pub mod network; pub mod node; -pub mod style; pub mod theme; #[cfg(feature = "wgpu")] pub mod utility; pub mod wallet; -pub mod widget; #[macro_use] extern crate lazy_static; diff --git a/crates/core/src/style/header.rs b/crates/core/src/style/header.rs deleted file mode 100644 index 1ca682f..0000000 --- a/crates/core/src/style/header.rs +++ /dev/null @@ -1,58 +0,0 @@ -use crate::theme::Theme; -use iced_core::{Background, Color}; - -/// The appearance of a header. -#[derive(Debug, Clone, Copy)] -pub struct Appearance { - pub text_color: Option, - pub background: Option, - pub border_radius: f32, - pub border_width: f32, - pub border_color: Color, - pub offset_left: f32, - pub offset_right: f32, -} - -/// A set of rules that dictate the style of a header. -pub trait StyleSheet { - type Style: std::default::Default + Copy; - - /// Produces the style of a header. - fn appearance(&self, style: &Self::Style) -> Appearance; - - /// Produces the a hovered appearance for header. - fn hovered(&self, style: &Self::Style) -> Appearance; -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub enum HeaderStyle { - #[default] - Default, -} - -impl StyleSheet for Theme { - type Style = HeaderStyle; - - fn appearance(&self, style: &Self::Style) -> Appearance { - match style { - HeaderStyle::Default => Appearance { - //text_color: Some(self.palette.bright.surface), - text_color: None, - background: Some(Background::Color(self.palette.normal.primary)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_right: 0.0, - offset_left: 0.0, - }, - } - } - - fn hovered(&self, style: &Self::Style) -> Appearance { - let appearance = self.appearance(style); - Appearance { - background: None, - ..appearance - } - } -} diff --git a/crates/core/src/style/mod.rs b/crates/core/src/style/mod.rs deleted file mode 100644 index 91ed81f..0000000 --- a/crates/core/src/style/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod header; -pub mod table_row; diff --git a/crates/core/src/style/table_row.rs b/crates/core/src/style/table_row.rs deleted file mode 100644 index b3843c2..0000000 --- a/crates/core/src/style/table_row.rs +++ /dev/null @@ -1,135 +0,0 @@ -use crate::theme::Theme; -use iced::{Background, Color}; - -/// The appearance of a table row. -#[derive(Debug, Clone, Copy, Default)] -pub struct Appearance { - pub text_color: Option, - pub background: Option, - pub border_radius: f32, - pub border_width: f32, - pub border_color: Color, - pub offset_left: f32, - pub offset_right: f32, -} - -/// A set of rules that dictate the style of a table row. -pub trait StyleSheet { - type Style: std::default::Default + Copy; - - /// Produces the default appearance of a table row. - fn appearance(&self, style: &Self::Style) -> Appearance; - - /// Produces the hovered appearance table row. - fn hovered(&self, style: &Self::Style) -> Appearance; -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] -pub enum TableRowStyle { - #[default] - Default, - TableRowAlternate, - TableRowHighlife, - TableRowLowlife, - TableRowSelected, -} - -impl StyleSheet for Theme { - type Style = TableRowStyle; - - fn appearance(&self, style: &Self::Style) -> Appearance { - match style { - TableRowStyle::Default => Appearance { - text_color: Some(self.palette.bright.primary), - background: Some(Background::Color(self.palette.normal.primary)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - // offset_left: 10.0, - // offset_right: 25.0, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowAlternate => Appearance { - text_color: Some(self.palette.bright.primary), - background: Some(Background::Color(Color { - a: 0.50, - ..self.palette.normal.primary - })), - ..Appearance::default() - }, - TableRowStyle::TableRowHighlife => Appearance { - text_color: Some(self.palette.bright.primary), - background: Some(Background::Color(Color { - a: 0.30, - ..self.palette.normal.primary - })), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowLowlife => Appearance { - text_color: Some(self.palette.bright.primary), - background: Some(Background::Color(Color::TRANSPARENT)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - TableRowStyle::TableRowSelected => Appearance { - text_color: Some(self.palette.bright.primary), - background: Some(Background::Color(self.palette.normal.primary)), - border_radius: 0.0, - border_width: 0.0, - border_color: Color::TRANSPARENT, - offset_left: 0.0, - offset_right: 0.0, - }, - } - } - - fn hovered(&self, style: &Self::Style) -> Appearance { - let appearance = self.appearance(style); - - match style { - TableRowStyle::Default => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowAlternate => Appearance { - background: Some(Background::Color(Color { - a: 0.25, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowHighlife => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowLowlife => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - TableRowStyle::TableRowSelected => Appearance { - background: Some(Background::Color(Color { - a: 0.60, - ..self.palette.normal.primary - })), - ..appearance - }, - } - } -} diff --git a/crates/core/src/theme/mod.rs b/crates/core/src/theme/mod.rs index 3ef03b4..88b2c63 100644 --- a/crates/core/src/theme/mod.rs +++ b/crates/core/src/theme/mod.rs @@ -20,6 +20,8 @@ pub mod modal; pub mod picklist; pub mod radio; pub mod scrollable; +pub mod table_header; +pub mod table_row; pub mod text; pub mod text_input; @@ -31,6 +33,8 @@ pub use modal::ModalStyle; pub use picklist::PickListStyle; pub use radio::RadioStyle; pub use scrollable::ScrollableStyle; +pub use table_header::TableHeaderStyle; +pub use table_row::TableRowStyle; pub use text_input::TextInputStyle; pub async fn load_user_themes() -> Vec { @@ -57,11 +61,10 @@ pub type Scrollable<'a, Message> = iced::widget::Scrollable<'a, Message, Theme, pub type PickList<'a, T, L, V, Message> = iced::widget::PickList<'a, T, L, V, Message, Theme, Renderer>; pub type Radio = iced::widget::Radio; -pub type Card<'a, Message> = iced_aw::native::Card<'a, Message, Theme, Renderer>; +pub type Card<'a, Message> = iced_aw::Card<'a, Message, Theme, Renderer>; pub type Modal<'a, Message, Theme, Renderer> = iced_aw::modal::Modal<'a, Message, Theme, Renderer>; -pub type Header<'a, Message, Theme> = crate::widget::header::Header<'a, Message, Theme, Renderer>; -pub type TableRow<'a, Message, Theme> = - crate::widget::table_row::TableRow<'a, Message, Theme, Renderer>; +pub type TableHeader<'a, Message, Theme> = iced_aw::TableHeader<'a, Message, Theme, Renderer>; +pub type TableRow<'a, Message, Theme> = iced_aw::TableRow<'a, Message, Theme, Renderer>; #[derive(Debug, Clone, Copy, Default, Deserialize, Serialize)] pub struct BaseColors { diff --git a/crates/core/src/theme/table_row.rs b/crates/core/src/theme/table_row.rs index 170223e..9da3c94 100644 --- a/crates/core/src/theme/table_row.rs +++ b/crates/core/src/theme/table_row.rs @@ -32,10 +32,10 @@ impl table::TableRowStyleSheet for Theme { }, cell: RowOrCellAppearance { text_color: palette.normal.primary, - background: Some(Background::Color(palette.base.foreground)), + background: None, border_radius: 0.0.into(), - border_width: 1.0, - border_color: Color::BLACK, + border_width: 0.0, + border_color: Color::TRANSPARENT, offset_left: 0.0, offset_right: 0.0, }, @@ -51,10 +51,7 @@ impl table::TableRowStyleSheet for Theme { }, cell: RowOrCellAppearance { text_color: palette.normal.primary, - background: Some(Background::Color(Color { - a: 0.50, - ..palette.normal.primary - })), + background: None, ..RowOrCellAppearance::default() }, }, @@ -73,10 +70,7 @@ impl table::TableRowStyleSheet for Theme { }, cell: RowOrCellAppearance { text_color: palette.normal.primary, - background: Some(Background::Color(Color { - a: 0.30, - ..palette.base.foreground - })), + background: None, border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, @@ -96,7 +90,7 @@ impl table::TableRowStyleSheet for Theme { }, cell: RowOrCellAppearance { text_color: palette.normal.primary, - background: Some(Background::Color(Color::TRANSPARENT)), + background: None, border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, @@ -116,7 +110,7 @@ impl table::TableRowStyleSheet for Theme { }, cell: RowOrCellAppearance { text_color: palette.normal.primary, - background: Some(Background::Color(palette.normal.primary)), + background: None, border_radius: 0.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, @@ -139,10 +133,7 @@ impl table::TableRowStyleSheet for Theme { ..self.appearance(style, row_id).row }, cell: RowOrCellAppearance { - background: Some(Background::Color(Color { - a: 0.60, - ..palette.normal.primary - })), + background: None, ..self.appearance(style, row_id).cell }, }, @@ -155,10 +146,7 @@ impl table::TableRowStyleSheet for Theme { ..self.appearance(style, row_id).row }, cell: RowOrCellAppearance { - background: Some(Background::Color(Color { - a: 0.25, - ..palette.normal.primary - })), + background: None, ..self.appearance(style, row_id).cell }, }, @@ -171,10 +159,7 @@ impl table::TableRowStyleSheet for Theme { ..self.appearance(style, row_id).row }, cell: RowOrCellAppearance { - background: Some(Background::Color(Color { - a: 0.60, - ..palette.normal.primary - })), + background: None, ..self.appearance(style, row_id).cell }, }, @@ -187,10 +172,7 @@ impl table::TableRowStyleSheet for Theme { ..self.appearance(style, row_id).row }, cell: RowOrCellAppearance { - background: Some(Background::Color(Color { - a: 0.60, - ..palette.normal.primary - })), + background: None, ..self.appearance(style, row_id).cell }, }, @@ -203,10 +185,7 @@ impl table::TableRowStyleSheet for Theme { ..self.appearance(style, row_id).row }, cell: RowOrCellAppearance { - background: Some(Background::Color(Color { - a: 0.60, - ..palette.normal.primary - })), + background: None, ..self.appearance(style, row_id).cell }, }, diff --git a/crates/core/src/widget/header.rs b/crates/core/src/widget/header.rs deleted file mode 100644 index fc46729..0000000 --- a/crates/core/src/widget/header.rs +++ /dev/null @@ -1,394 +0,0 @@ -#![allow(clippy::type_complexity)] -use crate::style::header::StyleSheet; -use iced::advanced::renderer; -use iced_core::{ - event, layout, mouse, - widget::{self, Tree}, - Alignment, Clipboard, Element, Event, Layout, Length, Padding, Rectangle, Shell, Widget, -}; - -use iced::{widget::space::Space, Size}; - -mod state; -pub use state::State; - -pub struct Header<'a, Message, Theme, Renderer = iced::Renderer> -where - Renderer: renderer::Renderer, - Theme: StyleSheet, - Message: Clone, -{ - spacing: u16, - width: Length, - height: Length, - state: State, - leeway: u16, - on_resize: Option<(u16, Box Message + 'a>)>, - children: Vec>, - left_margin: bool, - right_margin: bool, - names: Vec, - style: ::Style, -} - -impl<'a, Message, Theme, Renderer> Header<'a, Message, Theme, Renderer> -where - Renderer: renderer::Renderer, - Theme: StyleSheet, - Message: Clone, -{ - pub fn new( - state: State, - headers: Vec<(String, Element<'a, Message, Theme, Renderer>)>, - left_margin: Option, - right_margin: Option, - ) -> Self - where - Theme: iced_style::container::StyleSheet, - Renderer: 'a + iced_core::Renderer, - Message: 'a, - { - let mut names = vec![]; - let mut left = false; - let mut right = false; - - let mut children = vec![]; - - if let Some(margin) = left_margin { - children.push(Space::with_width(margin).into()); - left = true; - } - - for (key, container) in headers { - names.push(key); - - // add container to children - children.push(container.into()); - } - - if let Some(margin) = right_margin { - children.push(Space::with_width(margin).into()); - right = true; - } - - Self { - spacing: 0, - width: Length::Fill, - height: Length::Fill, - leeway: 0, - state, - on_resize: None, - children, - left_margin: left, - right_margin: right, - names, - style: Default::default(), - } - } - - pub fn spacing(mut self, units: u16) -> Self { - self.spacing = units; - self - } - - pub fn width(mut self, width: Length) -> Self { - self.width = width; - self - } - - pub fn height(mut self, height: Length) -> Self { - self.height = height; - self - } - - pub fn on_resize(mut self, leeway: u16, f: F) -> Self - where - F: 'a + Fn(ResizeEvent) -> Message, - { - self.leeway = leeway; - self.on_resize = Some((leeway, Box::new(f))); - self - } - - fn trigger_resize( - &self, - left_name: String, - left_width: u16, - right_name: String, - right_width: u16, - shell: &mut Shell<'_, Message>, - ) { - if let Some((_, on_resize)) = &self.on_resize { - //TODO: Update - shell.publish(on_resize(ResizeEvent::ResizeColumn { - left_name, - left_width, - right_name, - right_width, - })); - } - } - - fn trigger_finished(&self, shell: &mut Shell<'_, Message>) { - if let Some((_, on_resize)) = &self.on_resize { - shell.publish(on_resize(ResizeEvent::Finished)); - } - } -} - -impl<'a, Message, Theme, Renderer> Widget - for Header<'a, Message, Theme, Renderer> -where - Renderer: renderer::Renderer, - Theme: StyleSheet, - Message: Clone, -{ - fn children(&self) -> Vec { - self.children.iter().map(Tree::new).collect() - } - - fn diff(&self, tree: &mut Tree) { - tree.diff_children(&self.children); - } - - fn size(&self) -> Size { - Size { - width: self.width, - height: self.height, - } - } - - fn layout( - &self, - tree: &mut Tree, - renderer: &Renderer, - limits: &layout::Limits, - ) -> layout::Node { - let limits = limits.width(self.width).height(self.height); - let mut trees = self.children(); - - layout::flex::resolve( - layout::flex::Axis::Horizontal, - renderer, - &limits, - self.width, - self.height, - Padding::ZERO, - self.spacing as f32, - Alignment::Start, - &self.children, - &mut trees, - ) - } - - fn on_event( - &mut self, - tree: &mut Tree, - event: Event, - layout: Layout<'_>, - cursor: mouse::Cursor, - renderer: &Renderer, - clipboard: &mut dyn Clipboard, - shell: &mut Shell<'_, Message>, - viewport: &Rectangle, - ) -> event::Status { - let cursor_position = cursor.position().unwrap_or_default(); - let in_bounds = layout.bounds().contains(cursor_position); - - if self.state.resizing || in_bounds { - let child_len = self.children.len(); - let start_offset = if self.left_margin { 1 } else { 0 }; - let end_offset = if self.right_margin { 1 } else { 0 }; - - let dividers = self - .children - .iter() - .enumerate() - .zip(layout.children()) - .filter_map(|((idx, _), layout)| { - if idx >= start_offset && idx < (child_len - 1 - end_offset) { - Some((idx, layout.position().x + layout.bounds().width)) - } else { - None - } - }) - .collect::>(); - - if self.on_resize.is_some() { - if !self.state.resizing { - self.state.resize_hovering = false; - } - - for (idx, divider) in dividers.iter() { - if cursor_position.x > (divider - self.leeway as f32) - && cursor_position.x < (divider + self.leeway as f32) - { - if !self.state.resize_hovering { - self.state.resizing_idx = *idx; - } - - self.state.resize_hovering = true; - } - } - } - - match event { - Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { - if self.state.resize_hovering { - self.state.resizing = true; - self.state.starting_cursor_pos = Some(cursor_position); - self.state.starting_left_width = layout - .children() - .nth(self.state.resizing_idx) - .unwrap() - .bounds() - .width; - self.state.starting_right_width = layout - .children() - .nth(self.state.resizing_idx + 1) - .unwrap() - .bounds() - .width; - return event::Status::Captured; - } - } - Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) => { - if self.state.resizing { - self.state.resizing = false; - self.state.starting_cursor_pos.take(); - // TODO: UPDATE - //shell.publish(messages); - return event::Status::Captured; - } - } - Event::Mouse(mouse::Event::CursorMoved { position }) => { - if self.state.resizing { - let delta = position.x - self.state.starting_cursor_pos.unwrap().x; - - let left_width = self.state.starting_left_width; - let right_width = self.state.starting_right_width; - - let max_width = left_width + right_width - 30.0; - - let left_width = (left_width + delta).max(30.0).min(max_width) as u16; - let left_name = &self.names[self.state.resizing_idx - start_offset]; - let right_width = (right_width - delta).max(30.0).min(max_width) as u16; - let right_name = &self.names[self.state.resizing_idx + 1 - start_offset]; - - self.trigger_resize( - left_name.clone(), - left_width, - right_name.clone(), - right_width, - shell, - ); - return event::Status::Captured; - } - } - _ => {} - } - } else { - self.state.resize_hovering = false; - } - - self.children - .iter_mut() - .zip(&mut tree.children) - .zip(layout.children()) - .map(|((child, state), layout)| { - child.as_widget_mut().on_event( - state, - event.clone(), - layout, - cursor, - renderer, - clipboard, - shell, - viewport, - ) - }) - .fold(event::Status::Ignored, event::Status::merge) - } - - fn draw( - &self, - tree: &Tree, - renderer: &mut Renderer, - theme: &Theme, - style: &iced_core::renderer::Style, - layout: Layout<'_>, - cursor: mouse::Cursor, - viewport: &Rectangle, - ) { - for ((child, state), layout) in self - .children - .iter() - .zip(&tree.children) - .zip(layout.children()) - { - child - .as_widget() - .draw(state, renderer, theme, style, layout, cursor, viewport); - } - } - - fn mouse_interaction( - &self, - tree: &Tree, - layout: Layout<'_>, - cursor: mouse::Cursor, - viewport: &Rectangle, - renderer: &Renderer, - ) -> mouse::Interaction { - let bounds = layout.bounds(); - let cursor_position = cursor.position().unwrap_or_default(); - let is_mouse_over = bounds.contains(cursor_position); - - if is_mouse_over { - mouse::Interaction::Pointer - } else { - mouse::Interaction::default() - } - } - - /*fn hash_layout(&self, state: &mut Hasher) { - use std::hash::Hash; - - struct Marker; - std::any::TypeId::of::().hash(state); - - self.width.hash(state); - self.height.hash(state); - self.spacing.hash(state); - self.left_margin.hash(state); - self.right_margin.hash(state); - self.leeway.hash(state); - - for child in &self.children { - child.hash_layout(state); - } - }*/ -} - -impl<'a, Message, Theme> From> - for Element<'a, Message, Theme, iced::Renderer> -where - //Renderer: 'a + renderer::Renderer, - Theme: 'a + StyleSheet + iced::widget::container::StyleSheet + widget::text::StyleSheet, - Message: 'a + Clone, -{ - fn from(header: Header<'a, Message, Theme>) -> Self { - Element::new(header) - } -} - -#[derive(Debug, Clone)] -pub enum ResizeEvent { - ResizeColumn { - left_name: String, - left_width: u16, - right_name: String, - right_width: u16, - }, - Finished, -} diff --git a/crates/core/src/widget/header/state.rs b/crates/core/src/widget/header/state.rs deleted file mode 100644 index 4fdc052..0000000 --- a/crates/core/src/widget/header/state.rs +++ /dev/null @@ -1,11 +0,0 @@ -use iced_core::Point; - -#[derive(Clone, Debug, Default)] -pub struct State { - pub resize_hovering: bool, - pub resizing: bool, - pub starting_cursor_pos: Option, - pub starting_left_width: f32, - pub starting_right_width: f32, - pub resizing_idx: usize, -} diff --git a/crates/core/src/widget/mod.rs b/crates/core/src/widget/mod.rs deleted file mode 100644 index 91ed81f..0000000 --- a/crates/core/src/widget/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod header; -pub mod table_row; diff --git a/crates/core/src/widget/table_row.rs b/crates/core/src/widget/table_row.rs deleted file mode 100644 index 751fad2..0000000 --- a/crates/core/src/widget/table_row.rs +++ /dev/null @@ -1,371 +0,0 @@ -#![allow(clippy::type_complexity)] -use crate::style::table_row::StyleSheet; -use iced_core::{ - event, layout, mouse, overlay, renderer, widget, widget::Tree, Alignment, Clipboard, Element, - Event, Layout, Length, Padding, Point, Rectangle, Shell, Widget, -}; - -use iced::{Border, Size}; - -#[allow(missing_debug_implementations)] -pub struct TableRow<'a, Message, Theme, Renderer = iced::Renderer> -where - Renderer: 'a + iced_core::Renderer, - Theme: StyleSheet, - Message: 'a, -{ - padding: Padding, - width: Length, - height: Length, - max_width: u32, - max_height: u32, - inner_row_height: u32, - horizontal_alignment: Alignment, - vertical_alignment: Alignment, - style: ::Style, - content: Element<'a, Message, Theme, Renderer>, - on_press: Option Message + 'a>>, -} - -impl<'a, Message, Theme, Renderer> TableRow<'a, Message, Theme, Renderer> -where - Renderer: 'a + iced_core::Renderer, - Theme: StyleSheet, - Message: 'a, -{ - /// Creates an empty [`TableRow`]. - pub fn new(content: T) -> Self - where - T: Into>, - { - TableRow { - padding: Padding::ZERO, - width: Length::Shrink, - height: Length::Shrink, - max_width: u32::MAX, - max_height: u32::MAX, - inner_row_height: u32::MAX, - horizontal_alignment: Alignment::Start, - vertical_alignment: Alignment::Start, - style: Default::default(), - content: content.into(), - on_press: None, - } - } - - pub fn width(mut self, width: Length) -> Self { - self.width = width; - self - } - - /// Sets the style of the [`TableRow`]. - pub fn style(mut self, style: S) -> Self - where - S: Into<::Style>, - { - self.style = style.into(); - self - } - - /// Sets the height of the [`TableRow`]. - pub fn height(mut self, height: Length) -> Self { - self.height = height; - self - } - - /// Sets the maximum width of the [`TableRow`]. - pub fn max_width(mut self, max_width: u32) -> Self { - self.max_width = max_width; - self - } - - /// Sets the maximum height of the [`TableRow`] in pixels. - pub fn max_height(mut self, max_height: u32) -> Self { - self.max_height = max_height; - self - } - - /// Sets the height of the area that will be used to define the event capture area of [`TableRow`] in pixels. - pub fn inner_row_height(mut self, inner_row_height: u32) -> Self { - self.inner_row_height = inner_row_height; - self - } - - /// Sets the content alignment for the horizontal axis of the [`TableRow`]. - pub fn align_x(mut self, alignment: Alignment) -> Self { - self.horizontal_alignment = alignment; - self - } - - /// Sets the content alignment for the vertical axis of the [`TableRow`]. - pub fn align_y(mut self, alignment: Alignment) -> Self { - self.vertical_alignment = alignment; - self - } - - /// Centers the contents in the horizontal axis of the [`TableRow`]. - pub fn center_x(mut self) -> Self { - self.horizontal_alignment = Alignment::Center; - self - } - - /// Centers the contents in the vertical axis of the [`TableRow`]. - pub fn center_y(mut self) -> Self { - self.vertical_alignment = Alignment::Center; - self - } - - /// Sets the message that will be produced when the [`TableRow`] is pressed. - pub fn on_press(mut self, f: T) -> Self - where - T: 'a + Fn(Event) -> Message, - { - self.on_press = Some(Box::new(f)); - self - } - - pub fn padding(mut self, p: Padding) -> Self { - self.padding = p; - self - } -} - -impl<'a, Message, Theme, Renderer> Widget - for TableRow<'a, Message, Theme, Renderer> -where - Renderer: 'a + iced_core::Renderer, - Theme: StyleSheet, - Message: 'a, -{ - fn size(&self) -> Size { - Size { - width: self.width, - height: self.height, - } - } - - fn layout( - &self, - tree: &mut Tree, - renderer: &Renderer, - limits: &layout::Limits, - ) -> layout::Node { - let limits = limits - .loose() - .width(self.width) - .height(self.height) - .shrink(self.padding); - - let mut content = self - .content - .as_widget() - .layout(tree, renderer, &limits.loose()); - let size = limits.resolve(self.width, self.height, content.size()); - - // TODO: MODIFIED COORDINATES, CHECK - content = content.move_to(Point::new( - self.padding.top as f32, - self.padding.left as f32, - )); - content = content.align(self.horizontal_alignment, self.vertical_alignment, size); - - layout::Node::with_children(size.expand(self.padding), vec![content]) - } - - fn draw( - &self, - _tree: &Tree, - renderer: &mut Renderer, - theme: &Theme, - style: &renderer::Style, - layout: Layout<'_>, - cursor: mouse::Cursor, - viewport: &Rectangle, - ) { - let cursor_position = cursor.position().unwrap_or_default(); - let bounds = layout.bounds(); - let mut custom_bounds = layout.bounds(); - let tree = Tree::new(&self.content); - - // inner_row_height set? - if self.inner_row_height != u32::MAX { - custom_bounds.height = self.inner_row_height as f32; - } - - let is_mouse_over = custom_bounds.contains(cursor_position); - let content_layout = layout.children().next().unwrap(); - - let appearance = if is_mouse_over { - theme.hovered(&self.style) - } else { - theme.appearance(&self.style) - }; - - let background = iced_core::renderer::Quad { - bounds: Rectangle { - x: bounds.x + appearance.offset_left as f32, - y: bounds.y, - width: bounds.width - appearance.offset_right as f32, - height: custom_bounds.height, - }, - border: Border { - width: appearance.border_width, - color: appearance.border_color, - radius: appearance.border_radius.into(), - }, - shadow: Default::default(), - }; - - renderer.fill_quad( - background.into(), - appearance.background.unwrap(), //.unwrap_or(Background::Color(Color::TRANSPARENT)), - ); - - self.content.as_widget().draw( - &tree, - renderer, - theme, - style, - content_layout, - cursor, - viewport, - ); - } - - fn mouse_interaction( - &self, - _tree: &Tree, - layout: Layout<'_>, - cursor: mouse::Cursor, - viewport: &Rectangle, - renderer: &Renderer, - ) -> mouse::Interaction { - let cursor_position = cursor.position().unwrap_or_default(); - let bounds = layout.bounds(); - let is_mouse_over = bounds.contains(cursor_position); - - let mut mouse_interaction = if is_mouse_over { - mouse::Interaction::Pointer - } else { - mouse::Interaction::default() - }; - - let children = layout.children(); - - for layout in children { - let is_mouse_over = layout.bounds().contains(cursor_position); - let new_mouse_interaction = if is_mouse_over { - mouse::Interaction::Pointer - } else { - mouse::Interaction::default() - }; - - if new_mouse_interaction > mouse_interaction { - mouse_interaction = new_mouse_interaction; - } - } - - mouse_interaction - } - - /*fn hash_layout(&self, state: &mut Hasher) { - struct Marker; - std::any::TypeId::of::().hash(state); - - self.padding.hash(state); - self.width.hash(state); - self.height.hash(state); - self.max_width.hash(state); - self.max_height.hash(state); - self.inner_row_height.hash(state); - - self.content.hash_layout(state); - }*/ - - fn on_event( - &mut self, - _tree: &mut Tree, - event: Event, - layout: Layout<'_>, - cursor: mouse::Cursor, - renderer: &Renderer, - clipboard: &mut dyn Clipboard, - shell: &mut Shell<'_, Message>, - viewport: &Rectangle, - ) -> event::Status { - let cursor_position = cursor.position().unwrap_or_default(); - let mut tree = Tree::new(&self.content); - let status_from_content = self.content.as_widget_mut().on_event( - &mut tree, - event.clone(), - layout.children().next().unwrap(), - cursor, - renderer, - clipboard, - shell, - viewport, - ); - match status_from_content { - event::Status::Ignored => { - if let Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) = event { - if let Some(on_press) = &self.on_press { - let mut bounds = layout.bounds(); - - // was inner row height set? - if self.inner_row_height != u32::MAX { - //We can face issues if the row is expanded, so we manage it by having a reduced bounds area to check for pointer - bounds.height = self.inner_row_height as f32; - } - - if bounds.contains(cursor_position) { - shell.publish(on_press(event)); - } - } - } - status_from_content - } - _ => status_from_content, - } - } - - fn overlay<'b>( - &'b mut self, - tree: &'b mut Tree, - layout: Layout<'_>, - renderer: &Renderer, - cursor: iced_core::Vector, // Change the type of the `cursor` parameter - ) -> Option> { - self.content.as_widget_mut().overlay( - tree, - layout.children().next().unwrap(), - renderer, - cursor, - ) - } -} - -/*impl<'a, Message, Theme: 'a, Renderer> From> - for Element<'a, Message, Theme, Renderer> -where - Renderer: 'a + iced_core::Renderer, - Theme: StyleSheet + iced::widget::container::StyleSheet + widget::text::StyleSheet, - Message: 'a, -{ - fn from( - table_row: TableRow<'a, Message, Theme, Renderer>, - ) -> Self { - Element::new(table_row) - } -}*/ - -impl<'a, Message, Theme, Renderer> From> - for Element<'a, Message, Theme, Renderer> -where - Message: 'a, - Theme: 'a + StyleSheet, - Renderer: iced_core::Renderer + 'a, -{ - fn from(column: TableRow<'a, Message, Theme, Renderer>) -> Self { - Self::new(column) - } -} diff --git a/src/gui/element/wallet/operation/action_menu.rs b/src/gui/element/wallet/operation/action_menu.rs index 29132ae..d5d3aba 100644 --- a/src/gui/element/wallet/operation/action_menu.rs +++ b/src/gui/element/wallet/operation/action_menu.rs @@ -21,8 +21,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{node::amount_to_hr_string, theme::ColorPalette}, diff --git a/src/gui/element/wallet/operation/apply_tx.rs b/src/gui/element/wallet/operation/apply_tx.rs index 8a22710..a62d2e2 100644 --- a/src/gui/element/wallet/operation/apply_tx.rs +++ b/src/gui/element/wallet/operation/apply_tx.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, wallet::{Slate, Slatepack, TxLogEntry, TxLogEntryType}, @@ -23,8 +22,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{node::amount_to_hr_string, theme::ColorPalette}, diff --git a/src/gui/element/wallet/operation/apply_tx_confirm.rs b/src/gui/element/wallet/operation/apply_tx_confirm.rs index eeffaca..23b9618 100644 --- a/src/gui/element/wallet/operation/apply_tx_confirm.rs +++ b/src/gui/element/wallet/operation/apply_tx_confirm.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::{Config, TxMethod}, wallet::{ @@ -27,8 +26,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{parse_abs_tx_amount_fee, StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{node::amount_to_hr_string, theme::ColorPalette}, diff --git a/src/gui/element/wallet/operation/chart.rs b/src/gui/element/wallet/operation/chart.rs index 70451e8..2599e0d 100644 --- a/src/gui/element/wallet/operation/chart.rs +++ b/src/gui/element/wallet/operation/chart.rs @@ -4,8 +4,7 @@ extern crate plotters; use crate::gui::{element::DEFAULT_PADDING, Message}; use chrono::{DateTime, Utc}; use grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, Theme, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, Theme, }; use iced::{ alignment::{Horizontal, Vertical}, diff --git a/src/gui/element/wallet/operation/create_tx.rs b/src/gui/element/wallet/operation/create_tx.rs index 4f56804..35bfe5e 100644 --- a/src/gui/element/wallet/operation/create_tx.rs +++ b/src/gui/element/wallet/operation/create_tx.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, error::GrinWalletInterfaceError, @@ -25,8 +24,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{InitTxArgs, Slate, StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{ diff --git a/src/gui/element/wallet/operation/create_tx_contracts.rs b/src/gui/element/wallet/operation/create_tx_contracts.rs index 0d756dc..384dc6d 100644 --- a/src/gui/element/wallet/operation/create_tx_contracts.rs +++ b/src/gui/element/wallet/operation/create_tx_contracts.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, error::GrinWalletInterfaceError, @@ -28,8 +27,8 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Radio, Row, Scrollable, TableRow, - Text, TextInput, + Button, Column, Container, Element, PickList, Radio, Row, Scrollable, TableRow, Text, + TextInput, }, grin_gui_core::wallet::{InitTxArgs, Slate, StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{ diff --git a/src/gui/element/wallet/operation/home.rs b/src/gui/element/wallet/operation/home.rs index eb35e21..4ba098d 100644 --- a/src/gui/element/wallet/operation/home.rs +++ b/src/gui/element/wallet/operation/home.rs @@ -9,7 +9,6 @@ use chrono::{DateTime, DurationRound, TimeZone, Utc}; use grin_gui_core::error::GrinWalletInterfaceError; use grin_gui_core::node::SyncStatus; use grin_gui_core::wallet::SlatepackAddress; -use grin_gui_core::widget::header; use grin_gui_core::{ config::{Config, Currency}, wallet::{InvoiceProof, RetrieveTxQueryArgs, TxLogEntry, TxLogEntryType}, @@ -38,8 +37,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{ @@ -574,8 +572,6 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont let close_wallet_label_container = Container::new(Text::new(localized_string("close")).size(SMALLER_FONT_SIZE)) - .height(Length::Fixed(14.0)) - .width(Length::Fixed(30.0)) .center_y() .center_x(); @@ -584,12 +580,12 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont .on_press(Interaction::WalletOperationHomeViewInteraction( LocalViewInteraction::Back, )) - .padding(2) + .width(Length::Shrink) .into(); let subtitle_row = Row::new() .push(subtitle_container) - .push(Space::with_width(Length::Fixed(2.0))) + .push(Space::with_width(Length::Fixed(10.0))) .push(close_wallet_button.map(Message::Interaction)); let address_label = Text::new(format!( @@ -631,22 +627,20 @@ pub fn data_container<'a>(config: &'a Config, state: &'a StateContainer) -> Cont let copy_address_label_container = Container::new(Text::new(localized_string("copy-to-clipboard")).size(SMALLER_FONT_SIZE)) - .height(Length::Fixed(14.0)) - .width(Length::Fixed(30.0)) .center_y() .center_x(); let copy_address_button: Element = Button::new(copy_address_label_container) .style(grin_gui_core::theme::ButtonStyle::Bordered) .on_press(Interaction::WriteToClipboard(copied_address_value)) - .padding(2) + .width(Length::Shrink) .into(); let address_row = Row::new() .push(address_label_container) - .push(Space::with_width(Length::Fixed(2.0))) + .push(Space::with_width(Length::Fixed(10.0))) .push(address_container) - .push(Space::with_width(Length::Fixed(2.0))) + .push(Space::with_width(Length::Fixed(10.0))) .push(copy_address_button.map(Message::Interaction)); let title_container = Container::new( diff --git a/src/gui/element/wallet/operation/tx_detail.rs b/src/gui/element/wallet/operation/tx_detail.rs index 928590f..fae185d 100644 --- a/src/gui/element/wallet/operation/tx_detail.rs +++ b/src/gui/element/wallet/operation/tx_detail.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, error::GrinWalletInterfaceError, @@ -25,8 +24,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{InitTxArgs, Slate, StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{ diff --git a/src/gui/element/wallet/operation/tx_list.rs b/src/gui/element/wallet/operation/tx_list.rs index 50ec83a..2693416 100644 --- a/src/gui/element/wallet/operation/tx_list.rs +++ b/src/gui/element/wallet/operation/tx_list.rs @@ -1,5 +1,6 @@ use grin_gui_core::config::TxMethod; use iced_core::Widget; +use iced_renderer::graphics::text::cosmic_text::rustybuzz::ttf_parser::ankr::Table; use std::borrow::Borrow; use { @@ -8,19 +9,18 @@ use { crate::localization::localized_string, crate::Result, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, + Button, Column, Container, Element, PickList, Row, Scrollable, TableHeaderStyle, Text, Theme, }, - grin_gui_core::widget::header, grin_gui_core::{ config::Config, node::amount_to_hr_string, - style::header::HeaderStyle, - theme::{ButtonStyle, ColorPalette, ContainerStyle}, + theme::{ButtonStyle, ColorPalette, ContainerStyle, TableHeader, TableRow, TableRowStyle}, wallet::{TxLogEntry, TxLogEntryType}, }, iced::widget::{button, pick_list, scrollable, text_input, Space}, iced::{alignment, Alignment, Command, Length}, + iced_aw::TableHeaderState, serde::{Deserialize, Serialize}, std::collections::HashMap, strfmt::strfmt, @@ -243,7 +243,7 @@ impl std::fmt::Display for TxListResultSize { } pub struct HeaderState { - pub state: header::State, + pub state: TableHeaderState, pub previous_column_key: Option, pub previous_sort_direction: Option, pub columns: Vec, @@ -275,28 +275,28 @@ impl Default for HeaderState { ColumnState { key: ColumnKey::NetDifference, // btn_state: Default::default(), - width: Length::Fixed(110.0), + width: Length::FillPortion(1), hidden: false, order: 1, }, ColumnState { key: ColumnKey::CreationTime, // btn_state: Default::default(), - width: Length::Fixed(110.0), + width: Length::FillPortion(2), hidden: false, order: 2, }, ColumnState { key: ColumnKey::Status, // btn_state: Default::default(), - width: Length::Fixed(300.0), + width: Length::FillPortion(1), hidden: false, order: 3, }, ColumnState { key: ColumnKey::ConfirmationTime, // btn_state: Default::default(), - width: Length::Fixed(110.0), + width: Length::FillPortion(2), hidden: true, order: 4, }, @@ -603,7 +603,7 @@ pub struct TxListColumnState { } pub struct TxListHeaderState { - state: header::State, + state: TableHeaderState, previous_column_key: Option, previous_sort_direction: Option, columns: Vec, @@ -891,11 +891,11 @@ fn row_title( pub fn titles_row_header<'a>( tx_list: &TxList, - header_state: &'a header::State, + header_state: &'a TableHeaderState, column_state: &'a [ColumnState], previous_column_key: Option, previous_sort_direction: Option, -) -> Header<'a, Message, Theme> { +) -> TableHeader<'a, Message, Theme> { // A row containing titles above the addon rows. let mut row_titles = vec![]; @@ -944,7 +944,7 @@ pub fn titles_row_header<'a>( } } - Header::new( + TableHeader::new( header_state.clone(), row_titles .into_iter() @@ -955,8 +955,7 @@ pub fn titles_row_header<'a>( None, None, ) - .spacing(1) - .height(Length::Fixed(25.0)) + .width(Length::Fill) /* .on_resize(3, |event| { //TODO //Message::Interaction(Interaction::ResizeColumn(Mode::Catalog, event)) @@ -983,7 +982,7 @@ pub fn data_row_container<'a, 'b>( pending_confirmation: &Option, node_synched: bool, ) -> Container<'a, Message> { - let default_height = Length::Fixed(26.0); + let default_height = Length::Fixed(40.0); let mut default_row_height = 26; let mut row_containers = vec![]; @@ -1020,57 +1019,8 @@ pub fn data_row_container<'a, 'b>( ) ) }; - //TODO this will show the latest status - // Unconfirmed - Created time - // Confirmed - let status = create_tx_display_status(&tx_log_entry_wrap.tx); - - /*let version = tx - .version() - .map(str::to_string) - .unwrap_or_else(|| "-".to_string()); - let release_package = addon_cloned.relevant_release_package(global_release_channel);*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Title && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let title = Text::new(addon.title()).size(DEFAULT_FONT_SIZE); - - let mut title_row = Row::new().push(title).spacing(5).align_items(Align::Center); - - if addon.release_channel != ReleaseChannel::Default { - let release_channel = - Container::new(Text::new(addon.release_channel.to_string()).size(10)) - .style(style::ChannelBadge) - .padding(3); - - title_row = title_row.push(release_channel); - } - - let mut title_container = Container::new(title_row) - .padding(5) - .height(default_height) - .width(*width) - .center_y(); - if is_addon_expanded && matches!(expand_type, ExpandType::Details(_)) { - title_container = - title_container.style(style::SelectedBrightForegroundContainer); - } else { - title_container = - title_container.style(grin_gui_core::theme::container::Container::HoverableBrightForeground); - } - row_containers.push((idx, title_container)); - }*/ + let status = create_tx_display_status(&tx_log_entry_wrap.tx); if let Some((idx, width)) = column_config .iter() @@ -1087,10 +1037,7 @@ pub fn data_row_container<'a, 'b>( let display_id = Text::new(id.clone()).size(DEFAULT_FONT_SIZE); let id_container = Container::new(display_id) - .padding(5) - .height(default_height) .width(*width) - .center_y() .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, id_container)); @@ -1111,10 +1058,7 @@ pub fn data_row_container<'a, 'b>( let display_creation_time = Text::new(creation_time).size(DEFAULT_FONT_SIZE); let display_creation_time_container = Container::new(display_creation_time) - .padding(5) - .height(default_height) .width(*width) - .center_y() .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, display_creation_time_container)); @@ -1135,10 +1079,7 @@ pub fn data_row_container<'a, 'b>( let display_confirmation_time = Text::new(confirmation_time).size(DEFAULT_FONT_SIZE); let display_confirmation_time_container = Container::new(display_confirmation_time) - .padding(5) - .height(default_height) .width(*width) - .center_y() .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, display_confirmation_time_container)); @@ -1156,13 +1097,12 @@ pub fn data_row_container<'a, 'b>( }) .next() { - let display_net_difference = Text::new(net_diff).size(DEFAULT_FONT_SIZE); + let display_net_difference = Text::new(net_diff) + .size(DEFAULT_FONT_SIZE) + .size(DEFAULT_FONT_SIZE); let display_net_difference_container = Container::new(display_net_difference) - .padding(5) - .height(default_height) .width(*width) - .center_y() .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, display_net_difference_container)); @@ -1180,61 +1120,17 @@ pub fn data_row_container<'a, 'b>( }) .next() { - let display_status = Text::new(status).size(DEFAULT_FONT_SIZE); + let display_status = Text::new(status) + .size(DEFAULT_FONT_SIZE) + .vertical_alignment(alignment::Vertical::Center); let display_status_container = Container::new(display_status) - .padding(5) - .height(default_height) .width(*width) - .center_y() .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, display_status_container)); } - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Type && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let display_type = if let Some(package) = &release_package { - package.version.clone() - } else { - String::from("-") - }; - let remote_version = Text::new(remote_version).size(DEFAULT_FONT_SIZE); - - let mut remote_version_button = - Button::new(&mut addon.remote_version_btn_state, remote_version) - .style(grin_gui_core::theme::button::Button::NormalText); - - if changelog_url.is_some() { - remote_version_button = - remote_version_button.on_press(Interaction::Expand(ExpandType::Changelog { - addon: addon_cloned.clone(), - changelog: None, - })); - } - - let remote_version_button: Element = remote_version_button.into(); - - let remote_version_container = - Container::new(remote_version_button.map(Message::Interaction)) - .height(default_height) - .width(*width) - .center_y() - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, remote_version_container)); - }*/ - if let Some((idx, width)) = column_config .iter() .enumerate() @@ -1249,271 +1145,42 @@ pub fn data_row_container<'a, 'b>( { let display_tx_type = Text::new(tx_type.clone()).size(SMALLER_FONT_SIZE); let display_tx_type_container = Container::new(display_tx_type) - .height(default_height) .width(*width) - .center_y() - .padding(5) .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); row_containers.push((idx, display_tx_type_container)); } - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Author && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let author = Text::new(author.as_deref().unwrap_or("-")).size(DEFAULT_FONT_SIZE); - let author_container = Container::new(author) - .height(default_height) - .width(*width) - .center_y() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, author_container)); - }*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::GameVersion && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let game_version = - Text::new(game_version.as_deref().unwrap_or("-")).size(DEFAULT_FONT_SIZE); - let game_version_container = Container::new(game_version) - .height(default_height) - .width(*width) - .center_y() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, game_version_container)); - }*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::DateReleased && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let release_date_text: String = if let Some(package) = &release_package { - let f = localized_timeago_formatter(); - let now = Local::now(); - - if let Some(time) = package.date_time.as_ref() { - f.convert_chrono(*time, now) - } else { - "".to_string() - } - } else { - "-".to_string() - }; - let release_date_text = Text::new(release_date_text).size(DEFAULT_FONT_SIZE); - let game_version_container = Container::new(release_date_text) - .height(default_height) - .width(*width) - .center_y() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, game_version_container)); - }*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Source && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let source_text = - repository_kind.map_or_else(|| localized_string("unknown"), |a| a.to_string()); - let source = Text::new(source_text).size(DEFAULT_FONT_SIZE); - let source_container = Container::new(source) - .height(default_height) - .width(*width) - .center_y() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, source_container)); - }*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Summary && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let text = addon_cloned.notes().unwrap_or("-"); - let summary = Text::new(text).size(DEFAULT_FONT_SIZE); - let container = Container::new(summary) - .height(default_height) - .width(*width) - .center_y() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground); - - row_containers.push((idx, container)); - }*/ - - /*if let Some((idx, width)) = column_config - .iter() - .enumerate() - .filter_map(|(idx, (key, width, hidden))| { - if *key == ColumnKey::Status && !hidden { - Some((idx, width)) - } else { - None - } - }) - .next() - { - let update_button_container = match &addon.state { - AddonState::Idle => Container::new(Text::new("".to_string()).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .style(grin_gui_core::theme::container::Container::HoverableForeground), - AddonState::Completed => { - Container::new(Text::new(localized_string("completed")).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Error(message) => { - Container::new(Text::new(message).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Updatable | AddonState::Retry => { - let id = addon.primary_folder_id.clone(); - - let text = match addon.state { - AddonState::Updatable => localized_string("update"), - AddonState::Retry => localized_string("retry"), - _ => "".to_owned(), - }; - - let update_wrapper = Container::new(Text::new(text).size(DEFAULT_FONT_SIZE)) - .width(*width) - .center_x() - .align_x(Align::Center); - let update_button: Element = - Button::new(&mut addon.update_btn_state, update_wrapper) - .width(Length::FillPortion(1)) - .style(style::SecondaryButton) - .on_press(Interaction::Update(id)) - .into(); - - Container::new(update_button.map(Message::Interaction)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .style(grin_gui_core::theme::container::Container::HoverableBrightForeground) - } - AddonState::Downloading => { - Container::new(Text::new(localized_string("downloading")).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Unpacking => { - Container::new(Text::new(localized_string("unpacking")).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Fingerprint => { - Container::new(Text::new(localized_string("hashing")).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Ignored => { - Container::new(Text::new(localized_string("ignored")).size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground) - } - AddonState::Unknown => Container::new(Text::new("").size(DEFAULT_FONT_SIZE)) - .height(default_height) - .width(*width) - .center_y() - .center_x() - .padding(5) - .style(grin_gui_core::theme::container::Container::HoverableForeground), - }; - - row_containers.push((idx, update_button_container)); - }*/ - let left_spacer = Space::new(Length::Fixed(DEFAULT_PADDING), Length::Fixed(0.0)); let right_spacer = Space::new(Length::Fixed(DEFAULT_PADDING + 5.0), Length::Fixed(0.0)); //let mut row = Row::new().push(left_spacer).spacing(1); - let mut row = Row::new().spacing(1); + let mut table_row_content = vec![]; // Sort columns and push them into row row_containers.sort_by(|a, b| a.0.cmp(&b.0)); - for (_, elem) in row_containers.into_iter() { - row = row.push(elem); + + for (_, mut elem) in row_containers.into_iter() { + table_row_content.push(elem); } - row = row.push(right_spacer); + let tx_cloned_for_closure = tx_cloned_for_row.clone(); + let mut table_row = TableRow::new(table_row_content, 0) + .width(Length::Fill) + .padding(3.0.into()) + .on_press(move |_| { + Message::Interaction(Interaction::WalletOperationTxListInteraction( + LocalViewInteraction::Expand(ExpandType::Details(tx_cloned_for_closure.clone())), + )) + }); + + if is_odd == Some(true) { + table_row = table_row.style(TableRowStyle::TableRowLowlight) + } else { + table_row = table_row.style(TableRowStyle::TableRowHighlight) + } - let mut tx_column = Column::new().push(row); + let mut tx_column = Column::new().push(table_row); let mut action_button_row = Row::new(); if is_tx_expanded { @@ -1647,7 +1314,12 @@ pub fn data_row_container<'a, 'b>( .style(grin_gui_core::theme::ButtonStyle::Primary) .on_press(Interaction::WalletOperationHomeViewInteraction( super::home::LocalViewInteraction::ReloadTxSlate( - tx_cloned_for_row.tx.tx_slate_id.unwrap().to_string(), + tx_cloned_for_row + .clone() + .tx + .tx_slate_id + .unwrap() + .to_string(), ), )) .into(); @@ -1887,26 +1559,10 @@ pub fn data_row_container<'a, 'b>( } } - let mut table_row = TableRow::new(tx_column) - .width(Length::Fill) - .inner_row_height(default_row_height) - .on_press(move |_| { - Message::Interaction(Interaction::WalletOperationTxListInteraction( - LocalViewInteraction::Expand(ExpandType::Details(tx_cloned_for_row.clone())), - )) - }); - - if is_odd == Some(true) { - table_row = - table_row.style(grin_gui_core::style::table_row::TableRowStyle::TableRowAlternate) - } else { - table_row = table_row.style(grin_gui_core::style::table_row::TableRowStyle::Default) - } - // Due to what feels like an iced-rs bug, don't put buttons within the actual row as they appear // to clear their state between the press down and up event if included within the row itself // Some kind of fix to the table row widget might rectify this - let mut return_column = Column::new().push(table_row).push(action_button_row); + let mut return_column = Column::new().push(tx_column).push(action_button_row); if is_tx_expanded { return_column = return_column.push(Space::new( diff --git a/src/gui/element/wallet/operation/tx_list_display.rs b/src/gui/element/wallet/operation/tx_list_display.rs index 11f1b28..f5620b0 100644 --- a/src/gui/element/wallet/operation/tx_list_display.rs +++ b/src/gui/element/wallet/operation/tx_list_display.rs @@ -2,7 +2,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; use chrono::DurationRound; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, wallet::{TxLogEntry, TxLogEntryType}, @@ -23,8 +22,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableRow, Text, TextInput, }, grin_gui_core::wallet::{ InitTxArgs, RetrieveTxQueryArgs, RetrieveTxQuerySortOrder, Slate, StatusMessage, @@ -241,7 +239,7 @@ pub fn data_container<'a>( state: &'a StateContainer, ) -> Container<'a, Message> { let button_height = Length::Fixed(BUTTON_HEIGHT); - let button_width = Length::Fixed(BUTTON_WIDTH); + let button_width = Length::Shrink; let title = Text::new(localized_string("tx-list")).size(DEFAULT_HEADER_FONT_SIZE); let title_container = Container::new(title) diff --git a/src/gui/element/wallet/operation/tx_proof.rs b/src/gui/element/wallet/operation/tx_proof.rs index 7b73eb1..3ebd94f 100644 --- a/src/gui/element/wallet/operation/tx_proof.rs +++ b/src/gui/element/wallet/operation/tx_proof.rs @@ -1,7 +1,6 @@ use super::tx_list::{self, ExpandType}; use crate::log_error; use async_std::prelude::FutureExt; -use grin_gui_core::widget::header; use grin_gui_core::{ config::Config, error::GrinWalletInterfaceError, @@ -25,8 +24,7 @@ use { crate::Result, anyhow::Context, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, Text, TextInput, }, grin_gui_core::wallet::{InitTxArgs, Slate, StatusMessage, WalletInfo, WalletInterface}, grin_gui_core::{ diff --git a/src/gui/element/wallet/setup/wallet_list.rs b/src/gui/element/wallet/setup/wallet_list.rs index bd2facb..32db3ef 100644 --- a/src/gui/element/wallet/setup/wallet_list.rs +++ b/src/gui/element/wallet/setup/wallet_list.rs @@ -8,8 +8,8 @@ use { anyhow::Context, grin_gui_core::config::Config, grin_gui_core::theme::{ - Button, Column, Container, Element, Header, PickList, Row, Scrollable, TableRow, Text, - TextInput, + Button, Column, Container, Element, PickList, Row, Scrollable, TableHeader, TableRow, + TableRowStyle, Text, TextInput, }, grin_gui_core::{ theme::ColorPalette, @@ -22,7 +22,6 @@ use { std::sync::{Arc, RwLock}, }; -use grin_gui_core::widget::table_row; use isahc::head; use crate::gui::element::DEFAULT_SUB_HEADER_FONT_SIZE; @@ -262,11 +261,13 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain let wallet_name = Text::new(w.display_name.clone()).size(DEFAULT_FONT_SIZE); let chain_name = Text::new(w.chain_type.shortname()).size(DEFAULT_FONT_SIZE); - /*let mut wallet_name_container = Container::new(wallet_name) - .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); + let mut wallet_name_container = Container::new(wallet_name) + .style(grin_gui_core::theme::ContainerStyle::HoverableForeground) + .width(Length::FillPortion(1)); let mut wallet_chain_container = Container::new(chain_name) - .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); + .style(grin_gui_core::theme::ContainerStyle::HoverableForeground) + .width(Length::FillPortion(1)); let tld_string = match &w.tld { Some(path_buf) => path_buf.display().to_string(), @@ -275,7 +276,8 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain let wallet_directory = Text::new(tld_string).size(DEFAULT_FONT_SIZE); let mut wallet_directory_container = Container::new(wallet_directory) - .style(grin_gui_core::theme::ContainerStyle::HoverableForeground); + .style(grin_gui_core::theme::ContainerStyle::HoverableForeground) + .width(Length::FillPortion(3)); if selected_wallet { wallet_name_container = wallet_name_container @@ -284,28 +286,15 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain .style(grin_gui_core::theme::ContainerStyle::HoverableBrightForeground); wallet_directory_container = wallet_directory_container .style(grin_gui_core::theme::ContainerStyle::HoverableBrightForeground); - }*/ - - let wallet_row = Row::new() - // .push(checkbox) - /* .push( - Column::new() - .push(wallet_name_container) - .width(Length::FillPortion(1)), - ) - .push( - Column::new() - .push(wallet_chain_container) - .width(Length::FillPortion(1)), - ) - .push( - Column::new() - .push(wallet_directory_container) - .width(Length::FillPortion(3)), - )*/ - .push(Text::new("arse").size(DEFAULT_FONT_SIZE)); - - let mut table_row = TableRow::new(wallet_row) + } + + let wallet_row = vec![ + wallet_name_container, + wallet_chain_container, + wallet_directory_container, + ]; + + let mut table_row = TableRow::new(wallet_row, 0) .padding(iced::Padding::from(9)) .width(Length::Fill) .on_press(move |_| { @@ -317,16 +306,13 @@ pub fn data_container<'a>(state: &'a StateContainer, config: &Config) -> Contain if selected_wallet { // selected wallet should be highlighted - table_row = - table_row.style(grin_gui_core::style::table_row::TableRowStyle::TableRowSelected); + table_row = table_row.style(TableRowStyle::TableRowSelected); } else { // contrast row styles to spice things up if pos % 2 == 0 { - table_row = table_row - .style(grin_gui_core::style::table_row::TableRowStyle::TableRowLowlife); + table_row = table_row.style(TableRowStyle::TableRowLowlight); } else { - table_row = table_row - .style(grin_gui_core::style::table_row::TableRowStyle::TableRowHighlife); + table_row = table_row.style(TableRowStyle::TableRowHighlight); } }