diff --git a/client/Cargo.toml b/client/Cargo.toml index c7f0f17..712e8d9 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -24,7 +24,7 @@ serde = { version = "1.0.196", features = ["derive"] } serde_yaml = "0.9.31" # application window -iced = { version = "0.12.1", features = ["svg"] } +iced = { version = "0.12.1", features = ["svg", "palette"] } # plugins async-trait = "0.1.76" diff --git a/client/src/component/entry.rs b/client/src/component/entry.rs index 8194ad3..3014729 100644 --- a/client/src/component/entry.rs +++ b/client/src/component/entry.rs @@ -1,5 +1,5 @@ pub fn view(entry: &crate::model::Entry, active: bool) -> iced::Element<'static, crate::Message> { - return iced::widget::container( + iced::widget::container( iced::widget::row![ iced::widget::text(&entry.title) .size(1. * crate::REM) @@ -9,7 +9,7 @@ pub fn view(entry: &crate::model::Entry, active: bool) -> iced::Element<'static, .padding(0.5 * crate::REM), ) .style(style(active)) - .into(); + .into() } fn style(active: bool) -> iced::theme::Container { @@ -28,10 +28,13 @@ impl iced::widget::container::StyleSheet for Style { fn appearance(&self, _style: &Self::Style) -> iced::widget::container::Appearance { iced::widget::container::Appearance { background: None, - border_radius: iced::BorderRadius::from(0.1 * crate::REM), - border_width: 1., - border_color: iced::Color::WHITE, text_color: None, + border: iced::Border { + radius: iced::border::Radius::from(0.1 * crate::REM), + width: 1., + color: iced::Color::WHITE, + }, + shadow: iced::Shadow::default(), } } } diff --git a/client/src/component/plugin.rs b/client/src/component/plugin.rs index 0cb58c8..c4b75b6 100644 --- a/client/src/component/plugin.rs +++ b/client/src/component/plugin.rs @@ -16,7 +16,7 @@ pub fn view( family: iced::font::Family::Name("FiraCode Nerd Font"), weight: iced::font::Weight::Light, stretch: iced::font::Stretch::Normal, - monospaced: true, + style: iced::font::Style::default(), }) .size(0.75 * crate::REM)] .padding(0.5 * crate::REM), @@ -29,7 +29,7 @@ pub fn view( active_entry_id.is_some() && active_entry_id.unwrap() == &entry.id; crate::component::entry::view(entry, is_active) }) - .collect() + .collect::>() ) ] .padding(0.75 * crate::REM), diff --git a/client/src/component/query_input.rs b/client/src/component/query_input.rs index d1d9e63..c8e87f8 100644 --- a/client/src/component/query_input.rs +++ b/client/src/component/query_input.rs @@ -31,11 +31,14 @@ impl iced::widget::text_input::StyleSheet for Style { type Style = iced::Theme; fn active(&self, _style: &Self::Style) -> iced::widget::text_input::Appearance { + use iced::color; iced::widget::text_input::Appearance { background: iced::Background::Color(iced::Color::TRANSPARENT), - border_radius: iced::BorderRadius::from(0.), - border_width: 0., - border_color: iced::Color::TRANSPARENT, + border: iced::Border { + radius: iced::border::Radius::from(0.), + width: 0., + color: iced::Color::TRANSPARENT, + }, icon_color: iced::color!(0xf3f3f3, 1.), } } @@ -49,18 +52,22 @@ impl iced::widget::text_input::StyleSheet for Style { } fn placeholder_color(&self, _style: &Self::Style) -> iced::Color { + use iced::color; iced::color!(0xf3f3f3, 1.) } fn value_color(&self, _style: &Self::Style) -> iced::Color { + use iced::color; iced::color!(0xffffff, 1.) } fn disabled_color(&self, _style: &Self::Style) -> iced::Color { + use iced::color; iced::color!(0xfafafa, 1.) } fn selection_color(&self, _style: &Self::Style) -> iced::Color { + use iced::color; iced::color!(0x1b1b1b, 1.) } } diff --git a/client/src/main.rs b/client/src/main.rs index 25cc130..a0ccb02 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -68,50 +68,44 @@ impl Application for Centerpiece { Message::Search(input) => self.search(input), Message::Event(event) => match event { - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::Up, - .. - }) - | iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::K, - modifiers: iced::keyboard::Modifiers::CTRL, - }) => self.select_previous_entry(), - - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::Down, - .. - }) - | iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::J, - modifiers: iced::keyboard::Modifiers::CTRL, - }) => self.select_next_entry(), - - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::N, - modifiers: iced::keyboard::Modifiers::CTRL, - }) => self.select_next_plugin(), - - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::P, - modifiers: iced::keyboard::Modifiers::CTRL, - }) => self.select_previous_plugin(), - - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - key_code: iced::keyboard::KeyCode::Enter, - .. - }) => self - .activate_selected_entry() - .unwrap_or(iced::Command::none()), - - iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { - key_code: iced::keyboard::KeyCode::Escape, - .. - }) => iced::window::close(), - + iced::Event::Keyboard(event) => match event { + iced::keyboard::Event::KeyPressed { key, modifiers, .. } => { + if let iced::keyboard::Modifiers::CTRL = modifiers { + return match key.as_ref() { + iced::keyboard::Key::Character("j") => self.select_next_entry(), + iced::keyboard::Key::Character("k") => self.select_previous_entry(), + iced::keyboard::Key::Character("n") => self.select_next_plugin(), + iced::keyboard::Key::Character("p") => { + self.select_previous_plugin() + } + _ => iced::Command::none(), + }; + } + match key.as_ref() { + iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowUp) => { + self.select_previous_entry() + } + iced::keyboard::Key::Named(iced::keyboard::key::Named::ArrowDown) => { + self.select_next_entry() + } + iced::keyboard::Key::Named(iced::keyboard::key::Named::Enter) => self + .activate_selected_entry() + .unwrap_or(iced::Command::none()), + _ => iced::Command::none(), + } + } + iced::keyboard::Event::KeyReleased { key, .. } => { + if key == iced::keyboard::Key::Named(iced::keyboard::key::Named::Escape) { + return iced::window::close(iced::window::Id::MAIN); + } + iced::Command::none() + } + + _ => iced::Command::none(), + }, iced::Event::Mouse(iced::mouse::Event::ButtonPressed( iced::mouse::Button::Left, )) => self.focus_search_input(), - _ => iced::Command::none(), }, @@ -121,21 +115,19 @@ impl Application for Centerpiece { Message::UpdateEntries(plugin_id, entries) => self.update_entries(plugin_id, entries), - Message::Exit => iced::window::close(), + Message::Exit => iced::window::close(iced::window::Id::MAIN), } } fn subscription(&self) -> iced::Subscription { iced::subscription::Subscription::batch(vec![ - iced::subscription::events_with(|event, _status| match event { - iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { - modifiers: _, - key_code: _, - }) => Some(Message::Event(event)), - iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { - modifiers: _, - key_code: _, - }) => Some(Message::Event(event)), + iced::event::listen_with(|event, _status| match event { + iced::Event::Keyboard(iced::keyboard::Event::KeyPressed { .. }) => { + Some(Message::Event(event)) + } + iced::Event::Keyboard(iced::keyboard::Event::KeyReleased { .. }) => { + Some(Message::Event(event)) + } iced::Event::Mouse(iced::mouse::Event::ButtonPressed(_)) => { Some(Message::Event(event)) } @@ -175,7 +167,7 @@ impl Application for Centerpiece { index != 0, self.active_entry_id() )) - .collect() + .collect::>() )) .id(iced::widget::scrollable::Id::new(SCROLLABLE_ID)) .style(iced::theme::Scrollable::Custom(Box::new( @@ -199,20 +191,20 @@ impl Application for Centerpiece { impl Centerpiece { fn settings() -> iced::Settings<()> { - let default_text_size = REM; + let default_text_size = iced::Pixels(REM); let default_font = iced::Font { family: iced::font::Family::Name("FiraCode Nerd Font"), weight: iced::font::Weight::Normal, stretch: iced::font::Stretch::Normal, - monospaced: true, + style: iced::font::Style::default(), }; let id = Some(APP_ID.into()); let window = iced::window::Settings { transparent: true, - size: (650, 400), + size: iced::Size::new(650.0, 400.0), decorations: false, level: iced::window::Level::AlwaysOnTop, resizable: false, @@ -222,6 +214,7 @@ impl Centerpiece { icon: None, visible: true, platform_specific: Self::platform_specific_settings(), + exit_on_close_request: true, }; iced::Settings { @@ -233,18 +226,17 @@ impl Centerpiece { } } - fn platform_specific_settings() -> iced::window::PlatformSpecific { - iced::window::PlatformSpecific { + fn platform_specific_settings() -> iced::window::settings::PlatformSpecific { + iced::window::settings::PlatformSpecific { application_id: APP_ID.into(), } } fn entries(&self) -> Vec<&model::Entry> { - return self - .plugins + self.plugins .iter() .flat_map(|plugin| &plugin.entries) - .collect(); + .collect() } fn active_entry_id(&self) -> Option<&String> { @@ -424,10 +416,13 @@ impl iced::widget::container::StyleSheet for ApplicationWrapperStyle { fn appearance(&self, _style: &Self::Style) -> iced::widget::container::Appearance { iced::widget::container::Appearance { background: Some(iced::Background::Color(iced::Color::BLACK)), - border_color: iced::Color::TRANSPARENT, - border_radius: iced::BorderRadius::from(0.25 * REM), - border_width: 0., text_color: None, + shadow: iced::Shadow::default(), + border: iced::Border { + radius: iced::border::Radius::from(0.25 * REM), + width: 0., + color: iced::Color::TRANSPARENT, + }, } } } @@ -436,18 +431,26 @@ struct ScrollableStyle {} impl iced::widget::scrollable::StyleSheet for ScrollableStyle { type Style = iced::Theme; - fn active(&self, _style: &Self::Style) -> iced::widget::scrollable::Scrollbar { - iced::widget::scrollable::Scrollbar { - background: None, - border_radius: iced::BorderRadius::from(0.), - border_width: 0., - border_color: iced::Color::TRANSPARENT, - scroller: iced::widget::scrollable::Scroller { - color: iced::Color::WHITE, - border_radius: iced::BorderRadius::from(0.25 * REM), - border_width: 4., - border_color: iced::Color::BLACK, + fn active(&self, _style: &Self::Style) -> iced::widget::scrollable::Appearance { + iced::widget::scrollable::Appearance { + scrollbar: iced::widget::scrollable::Scrollbar { + background: None, + scroller: iced::widget::scrollable::Scroller { + color: iced::Color::WHITE, + border: iced::Border { + radius: iced::border::Radius::from(0.25 * REM), + width: 4., + color: iced::Color::BLACK, + }, + }, + border: iced::Border { + radius: iced::border::Radius::from(0.), + width: 0., + color: iced::Color::TRANSPARENT, + }, }, + container: iced::widget::container::Appearance::default(), + gap: None, } } @@ -455,18 +458,26 @@ impl iced::widget::scrollable::StyleSheet for ScrollableStyle { &self, _style: &Self::Style, _is_mouse_over_scrollbar: bool, - ) -> iced::widget::scrollable::Scrollbar { - iced::widget::scrollable::Scrollbar { - background: None, - border_radius: iced::BorderRadius::from(0.), - border_width: 0., - border_color: iced::Color::TRANSPARENT, - scroller: iced::widget::scrollable::Scroller { - color: iced::Color::WHITE, - border_radius: iced::BorderRadius::from(0.25 * REM), - border_width: 4., - border_color: iced::Color::BLACK, + ) -> iced::widget::scrollable::Appearance { + iced::widget::scrollable::Appearance { + scrollbar: iced::widget::scrollable::Scrollbar { + background: None, + scroller: iced::widget::scrollable::Scroller { + color: iced::Color::WHITE, + border: iced::Border { + radius: iced::border::Radius::from(0.25 * REM), + width: 4., + color: iced::Color::BLACK, + }, + }, + border: iced::Border { + radius: iced::border::Radius::from(0.), + width: 0., + color: iced::Color::TRANSPARENT, + }, }, + container: iced::widget::container::Appearance::default(), + gap: None, } } }