diff --git a/liana-ui/src/component/hw.rs b/liana-ui/src/component/hw.rs index b9b84e3cd..d5cf2414d 100644 --- a/liana-ui/src/component/hw.rs +++ b/liana-ui/src/component/hw.rs @@ -1,13 +1,14 @@ use crate::{color, component::text, icon, image, theme, widget::*}; use iced::{ - widget::{column, container, row, text::IntoFragment, tooltip}, + widget::{column, container, row, tooltip}, Alignment, Length, }; +use std::borrow::Cow; use std::fmt::Display; pub fn locked_hardware_wallet<'a, T: 'a, K: Display>( kind: K, - pairing_code: Option>, + pairing_code: Option> + Display>, ) -> Container<'a, T> { Container::new( column(vec![ @@ -37,7 +38,7 @@ pub fn supported_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>( kind: K, version: Option, fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { Container::new( column(vec![ @@ -61,8 +62,8 @@ pub fn warning_hardware_wallet<'a, T: 'static, K: Display, V: Display, F: Displa kind: K, version: Option, fingerprint: F, - alias: Option>, - warning: &'static str, + alias: Option> + Display>, + warning: &'a str, ) -> Container<'a, T> { container( row(vec![ @@ -82,7 +83,7 @@ pub fn warning_hardware_wallet<'a, T: 'static, K: Display, V: Display, F: Displa .into(), column(vec![tooltip::Tooltip::new( icon::warning_icon(), - warning, + iced::widget::text!("{}", warning), tooltip::Position::Bottom, ) .style(theme::card::simple) @@ -155,7 +156,7 @@ pub fn processing_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display> kind: K, version: Option, fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { container( row(vec![ @@ -184,36 +185,43 @@ pub fn processing_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display> .padding(10) } -pub fn selected_hardware_wallet( +pub fn selected_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display>( kind: K, version: Option, fingerprint: F, - alias: Option>, - warning: Option<&'static str>, -) -> Container<'static, T> { + alias: Option> + Display>, + warning: Option> + Display>, +) -> Container<'a, T> { container( - Row::new() - .push( - column(vec![ - Row::new() - .spacing(5) - .push_maybe(alias.map(|a| text::p1_bold(a))) - .push(text::p1_regular(format!("#{}", fingerprint))) - .into(), - Row::new() - .spacing(5) - .push(text::caption(kind.to_string())) - .push_maybe(version.map(|v| text::caption(v.to_string()))) - .into(), - ]) - .width(Length::Fill), - ) - .push_maybe(warning.map(|w| { - tooltip::Tooltip::new(icon::warning_icon(), w, tooltip::Position::Bottom) - .style(theme::card::simple) - })) - .push(image::success_mark_icon().width(Length::Fixed(50.0))) - .align_y(Alignment::Center), + row(vec![ + column(vec![ + Row::new() + .spacing(5) + .push_maybe(alias.map(text::p1_bold)) + .push(text::p1_regular(format!("#{}", fingerprint))) + .into(), + Row::new() + .spacing(5) + .push(text::caption(kind.to_string())) + .push_maybe(version.map(|v| text::caption(v))) + .into(), + ]) + .width(Length::Fill) + .into(), + // if let Some(w) = warning { + // tooltip::Tooltip::new( + // icon::warning_icon(), + // iced::widget::text!("{}", w), + // tooltip::Position::Bottom, + // ) + // .style(theme::card::simple) + // .into() + // } else { + // Row::new().into() + // }, + image::success_mark_icon().width(Length::Fixed(50.0)).into(), + ]) + .align_y(Alignment::Center), ) .padding(10) } @@ -222,7 +230,7 @@ pub fn sign_success_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Displa kind: K, version: Option, fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { container( row(vec![ @@ -257,7 +265,7 @@ pub fn registration_success_hardware_wallet<'a, T: 'a, K: Display, V: Display, F kind: K, version: Option, fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { container( row(vec![ @@ -385,7 +393,7 @@ pub fn unsupported_version_hardware_wallet<'a, T: 'static, K: Display, V: Displa pub fn sign_success_hot_signer<'a, T: 'a, F: Display>( fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { container( row(vec![ @@ -417,7 +425,7 @@ pub fn sign_success_hot_signer<'a, T: 'a, F: Display>( pub fn selected_hot_signer<'a, T: 'a, F: Display>( fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { container( row(vec![ @@ -446,7 +454,7 @@ pub fn selected_hot_signer<'a, T: 'a, F: Display>( pub fn unselected_hot_signer<'a, T: 'a, F: Display>( fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { Container::new( column(vec![ @@ -470,7 +478,7 @@ pub fn unselected_hot_signer<'a, T: 'a, F: Display>( pub fn hot_signer<'a, T: 'a, F: Display>( fingerprint: F, - alias: Option>, + alias: Option> + Display>, ) -> Container<'a, T> { Container::new( column(vec![ diff --git a/liana-ui/src/component/notification.rs b/liana-ui/src/component/notification.rs index a324d7344..0eda3ddf6 100644 --- a/liana-ui/src/component/notification.rs +++ b/liana-ui/src/component/notification.rs @@ -61,7 +61,7 @@ pub fn processing_hardware_wallet<'a, T: 'a, K: Display, V: Display, F: Display> kind: K, version: Option, fingerprint: F, - alias: Option>, + alias: Option<&'a str>, ) -> Container<'a, T> { container( row(vec![ diff --git a/liana-ui/src/component/text.rs b/liana-ui/src/component/text.rs index 9d2ea875f..178cd715b 100644 --- a/liana-ui/src/component/text.rs +++ b/liana-ui/src/component/text.rs @@ -1,5 +1,6 @@ use crate::{font, theme::Theme}; use iced::advanced::text::{IntoFragment, Shaping}; +use std::fmt::Display; pub const H1_SIZE: u16 = 40; pub const H2_SIZE: u16 = 29; @@ -10,98 +11,98 @@ pub const P1_SIZE: u16 = 16; pub const P2_SIZE: u16 = 14; pub const CAPTION_SIZE: u16 = 12; -pub fn h1<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h1<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::BOLD) .size(H1_SIZE) } -pub fn h2<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h2<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::BOLD) .size(H2_SIZE) } -pub fn h3<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h3<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::BOLD) .size(H3_SIZE) } -pub fn h4_bold<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h4_bold<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::BOLD) .size(H4_SIZE) } -pub fn h4_regular<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h4_regular<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::REGULAR) .size(H4_SIZE) } -pub fn h5_medium<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h5_medium<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::MEDIUM) .size(H5_SIZE) } -pub fn h5_regular<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn h5_regular<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::REGULAR) .size(H5_SIZE) } -pub fn p1_bold<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn p1_bold<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::BOLD) .size(P1_SIZE) } -pub fn p1_medium<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn p1_medium<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::MEDIUM) .size(P1_SIZE) } -pub fn p1_regular<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn p1_regular<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::REGULAR) .size(P1_SIZE) } -pub fn p2_medium<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn p2_medium<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::MEDIUM) .size(P2_SIZE) } -pub fn p2_regular<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn p2_regular<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::REGULAR) .size(P2_SIZE) } -pub fn caption<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { - iced::widget::Text::new(content) +pub fn caption<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { + iced::widget::text!("{}", content) .shaping(Shaping::Advanced) .font(font::REGULAR) .size(CAPTION_SIZE) } -pub fn text<'a>(content: impl IntoFragment<'a>) -> iced::widget::Text<'a, Theme> { +pub fn text<'a>(content: impl Display) -> iced::widget::Text<'a, Theme> { p1_regular(content) }