Skip to content

Commit

Permalink
⬆️ implement breaking changes for iced bump
Browse files Browse the repository at this point in the history
  • Loading branch information
a-kenji committed Mar 2, 2024
1 parent 829f31d commit 9a78fea
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 96 deletions.
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 8 additions & 5 deletions client/src/component/entry.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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 {
Expand All @@ -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(),
}
}
}
4 changes: 2 additions & 2 deletions client/src/component/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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::<Vec<_>>()
)
]
.padding(0.75 * crate::REM),
Expand Down
13 changes: 10 additions & 3 deletions client/src/component/query_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.),
}
}
Expand All @@ -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.)
}
}
181 changes: 96 additions & 85 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},

Expand All @@ -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<Self::Message> {
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))
}
Expand Down Expand Up @@ -175,7 +167,7 @@ impl Application for Centerpiece {
index != 0,
self.active_entry_id()
))
.collect()
.collect::<Vec<_>>()
))
.id(iced::widget::scrollable::Id::new(SCROLLABLE_ID))
.style(iced::theme::Scrollable::Custom(Box::new(
Expand All @@ -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,
Expand All @@ -222,6 +214,7 @@ impl Centerpiece {
icon: None,
visible: true,
platform_specific: Self::platform_specific_settings(),
exit_on_close_request: true,
};

iced::Settings {
Expand All @@ -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> {
Expand Down Expand Up @@ -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,
},
}
}
}
Expand All @@ -436,37 +431,53 @@ 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,
}
}

fn hovered(
&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,
}
}
}

0 comments on commit 9a78fea

Please sign in to comment.