From b510b89b98acd7fd3fe3ae2a9a2b88703c7ba927 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 2 Mar 2023 16:51:32 -0500 Subject: [PATCH] fix(entry): entry bg alpha typo & border radius fixes --- examples/cosmic/src/window.rs | 2 +- examples/cosmic/src/window/demo.rs | 22 ++++++++++++++++++++-- src/theme/mod.rs | 18 +++++++++--------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/examples/cosmic/src/window.rs b/examples/cosmic/src/window.rs index e1175bab..a0219e74 100644 --- a/examples/cosmic/src/window.rs +++ b/examples/cosmic/src/window.rs @@ -176,7 +176,7 @@ impl Window { } #[allow(dead_code)] -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub enum Message { Bluetooth(bluetooth::Message), Close, diff --git a/examples/cosmic/src/window/demo.rs b/examples/cosmic/src/window/demo.rs index 1b6f3f25..acfad0b3 100644 --- a/examples/cosmic/src/window/demo.rs +++ b/examples/cosmic/src/window/demo.rs @@ -1,7 +1,7 @@ use apply::Apply; use cosmic::{ cosmic_theme, - iced::widget::{checkbox, pick_list, progress_bar, radio, row, slider, text}, + iced::widget::{checkbox, pick_list, progress_bar, radio, row, slider, text, text_input}, iced::{Alignment, Length}, theme::{self, Button as ButtonTheme, Theme}, widget::{ @@ -11,6 +11,7 @@ use cosmic::{ Element, }; use fraction::{Decimal, ToPrimitive}; +use once_cell::sync::Lazy; use super::{Page, Window}; @@ -28,8 +29,9 @@ pub enum MultiOption { OptionD, OptionE, } +static INPUT_ID: Lazy = Lazy::new(text_input::Id::unique); -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Debug)] pub enum Message { ButtonPressed, CheckboxToggled(bool), @@ -46,6 +48,7 @@ pub enum Message { ToggleWarning, TogglerToggled(bool), ViewSwitcher(segmented_button::Entity), + InputChanged(String), } pub enum Output { @@ -67,6 +70,7 @@ pub struct State { pub spin_button: spin_button::Model, pub toggler_value: bool, pub view_switcher: segmented_button::SingleSelectModel, + pub entry_value: String, } impl Default for State { @@ -104,6 +108,7 @@ impl Default for State { .insert(|b| b.text("Segmented Button").data(DemoView::TabB)) .insert(|b| b.text("Tab C").data(DemoView::TabC)) .build(), + entry_value: String::new(), } } } @@ -136,6 +141,9 @@ impl State { cosmic::settings::set_default_icon_theme(theme); } } + Message::InputChanged(s) => { + self.entry_value = s; + } } None @@ -390,6 +398,16 @@ impl State { .padding(8) .width(Length::Fill) .into(), + text_input( + "Type to search apps or type “?” for more options...", + &self.entry_value, + Message::InputChanged, + ) + // .on_submit(Message::Activate(None)) + .padding(8) + .size(20) + .id(INPUT_ID.clone()) + .into(), ]) .into() } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 0631499e..1533b4d1 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -988,17 +988,17 @@ impl text_input::StyleSheet for Theme { fn active(&self, style: &Self::Style) -> text_input::Appearance { let palette = self.cosmic(); let mut bg = palette.palette.neutral_7; - bg.alpha = 0.75; + bg.alpha = 0.25; match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 2.0, + border_radius: 8.0, border_width: 1.0, border_color: self.current_container().component.divider.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 0.0, + border_radius: 24.0, border_width: 0.0, border_color: Color::TRANSPARENT, }, @@ -1008,18 +1008,18 @@ impl text_input::StyleSheet for Theme { fn hovered(&self, style: &Self::Style) -> text_input::Appearance { let palette = self.cosmic(); let mut bg = palette.palette.neutral_7; - bg.alpha = 0.75; + bg.alpha = 0.25; match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 2.0, + border_radius: 8.0, border_width: 1.0, border_color: palette.accent.base.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 0.0, + border_radius: 24.0, border_width: 0.0, border_color: Color::TRANSPARENT, }, @@ -1029,18 +1029,18 @@ impl text_input::StyleSheet for Theme { fn focused(&self, style: &Self::Style) -> text_input::Appearance { let palette = self.cosmic(); let mut bg = palette.palette.neutral_7; - bg.alpha = 0.75; + bg.alpha = 0.25; match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 2.0, + border_radius: 8.0, border_width: 1.0, border_color: palette.accent.base.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 0.0, + border_radius: 24.0, border_width: 0.0, border_color: Color::TRANSPARENT, },