Skip to content

Commit

Permalink
feat: update iced to 0.12.1
Browse files Browse the repository at this point in the history
  • Loading branch information
oknozor committed Apr 18, 2024
1 parent 0136c54 commit 35248d4
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 668 deletions.
1,151 changes: 567 additions & 584 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ default = ["iced/wgpu", "iced/palette"]
debug = ["iced/debug"]

[dependencies]
iced = { version = "0.10.0", features = ["wgpu", "palette", "svg", "image", "tokio"] }
iced_core = "0.10.0"
iced_runtime = "0.1.1"
iced_style = "0.9.0"
iced = { version = "0.12.1", features = ["wgpu", "palette", "svg", "image", "tokio"] }
iced_core = "0.12.3"
iced_runtime = "0.12.1"
iced_style = "0.12.1"
tokio = { version = "1.29.1", features = ["process", "macros", "io-util"] }
redb = "1.5.0"

Expand Down
6 changes: 3 additions & 3 deletions src/app/entries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::app::Message;
use crate::icons::{fallback_icon, Extension, IconPath};
use crate::THEME;
use iced::widget::{column, container, row, text, Button, Container, Image, Row};
use iced::{Alignment, Length, Renderer};
use iced::{Alignment, Length};
use std::borrow::Cow;

pub(crate) mod db_entry;
Expand Down Expand Up @@ -48,7 +48,7 @@ pub(crate) trait AsEntry<'a> {
where
'b: 'a,
{
let title_row: Container<'_, Message, Renderer> =
let title_row: Container<Message> =
container(iced::widget::row(vec![text(self.get_display_name())
.size(theme.title.font_size)
.into()]))
Expand All @@ -59,7 +59,7 @@ pub(crate) trait AsEntry<'a> {
.align_x(theme.title.align_x)
.align_y(theme.title.align_y);

let description_row: Option<Container<'_, Message, Renderer>> =
let description_row: Option<Container<Message>> =
self.get_description().map(|description| {
container(row!(
text(description.as_ref()).size(theme.description.font_size)
Expand Down
49 changes: 27 additions & 22 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use std::process::exit;

use iced::alignment::{Horizontal, Vertical};
use iced::futures::channel::mpsc::{Sender, TrySendError};
use iced::keyboard::KeyCode;
use iced::widget::{column, container, scrollable, text_input, Column, Container, Row, Text};
use iced::window::PlatformSpecific;
use iced::{
subscription, window, Application, Command, Element, Length, Renderer, Settings, Subscription,
};
use iced::{window, Application, Command, Element, Length, Settings, Subscription, event};
use iced_core::widget::operation::scrollable::RelativeOffset;
use iced_core::{Event, Font};
use iced_core::{Event, Font, Pixels, Size};
use iced_core::keyboard::Key;
use iced_core::keyboard::key::Named;
use iced_core::window::settings::PlatformSpecific;
use iced_style::Theme;
use onagre_launcher_toolkit::launcher::{Request, Response};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -49,7 +48,10 @@ pub fn run(pre_value: Option<String>) -> iced::Result {
id: Some("onagre".to_string()),
window: window::Settings {
transparent: true,
size: THEME.size,
size: Size {
width: THEME.size.0 as f32,
height: THEME.size.1 as f32,
},
decorations: false,
resizable: false,
position: window::Position::Centered,
Expand All @@ -61,12 +63,13 @@ pub fn run(pre_value: Option<String>) -> iced::Result {
application_id: "onagre".to_string(),
},
level: Default::default(),
exit_on_close_request: false,
},
default_text_size: THEME.font_size as f32,
default_text_size: Pixels::from(THEME.font_size),
antialiasing: true,
exit_on_close_request: false,
default_font,
flags: OnagreFlags { pre_value },
fonts: vec![],
})
}

Expand All @@ -81,7 +84,7 @@ pub enum Message {
Loading,
InputChanged(String),
Click(usize),
KeyboardEvent(KeyCode),
KeyboardEvent(Key),
SubscriptionResponse(SubscriptionMessage),
Unfocused,
}
Expand Down Expand Up @@ -148,7 +151,7 @@ impl Application for Onagre<'_> {
}
}

fn view(&self) -> Element<'_, Self::Message, Renderer<Self::Theme>> {
fn view(&self) -> Element<'_, Self::Message> {
// Build rows from current mode search entries
let selected = self.selected();
let rows = match &self.state.get_active_mode() {
Expand All @@ -164,7 +167,7 @@ impl Application for Onagre<'_> {
.iter()
.enumerate()
.map(|(idx, entry)| entry.to_row(selected, idx, icon.as_ref()).into())
.collect()
.collect::<Vec<Element<'_, Self::Message>>>()
}
ActiveMode::Web { modifier, .. } => {
let icon = self.state.plugin_matchers.get_plugin_icon("web");
Expand Down Expand Up @@ -408,24 +411,24 @@ impl Onagre<'_> {
exit(0);
}

fn handle_input(&mut self, key_code: KeyCode) -> Command<Message> {
fn handle_input(&mut self, key_code: Key) -> Command<Message> {
match key_code {
KeyCode::Up => {
Key::Named(Named::ArrowUp) => {
trace!("Selected line : {:?}", self.selected());
return self.dec_selected();
}
KeyCode::Down => {
Key::Named(Named::ArrowDown) => {
trace!("Selected line : {:?}", self.selected());
return self.inc_selected();
}
KeyCode::Enter => return self.on_execute(),
KeyCode::Tab => {
Key::Named(Named::Enter) => return self.on_execute(),
Key::Named(Named::Tab) => {
if let Some(selected) = self.selected() {
self.pop_request(Request::Complete(selected as u32))
.expect("Unable to send request to pop-launcher");
}
}
KeyCode::Escape => {
Key::Named(Named::Escape) => {
exit(0);
}
_ => {}
Expand Down Expand Up @@ -627,12 +630,14 @@ impl Onagre<'_> {
}

fn keyboard_event() -> Subscription<Message> {
subscription::events_with(|event, _status| match event {
Event::Window(window::Event::Unfocused) => Some(Message::Unfocused),
event::listen_with(|event, _status| match event {
Event::Window(_, event) if event == window::Event::Unfocused => Some(Message::Unfocused),
Event::Keyboard(iced::keyboard::Event::KeyPressed {
modifiers: _,
key_code,
}) => Some(Message::KeyboardEvent(key_code)),
text: _,
key,
location: _
}) => Some(Message::KeyboardEvent(key)),
_ => None,
})
}
Expand Down
12 changes: 8 additions & 4 deletions src/app/style/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::app::style::search::SearchContainerStyles;
use crate::app::style::Scale;
use crate::config::color::OnagreColor;
use crate::config::padding::OnagrePadding;
use iced_core::{Background, BorderRadius};
use iced_core::{Background, Border};
use iced_core::border::Radius;
use iced_style::container::{Appearance, StyleSheet};

// The top level container wrapping the app
Expand Down Expand Up @@ -49,9 +50,12 @@ impl StyleSheet for &AppContainerStyles {
Appearance {
text_color: Some(self.color.into()),
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border_color: self.border_color.into(),
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
shadow: Default::default(),
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/app/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::THEME_PATH;
use crate::THEME_SCALE;
use iced::widget::container::Appearance;
use iced::Background;
use iced_core::{BorderRadius, Length};
use iced_core::{Border, Length};
use iced_core::border::Radius;
use tracing::{error, warn};

pub mod app;
Expand Down Expand Up @@ -149,10 +150,13 @@ impl iced::widget::container::StyleSheet for &Theme {
fn appearance(&self, _: &Self::Style) -> Appearance {
Appearance {
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
text_color: Some(self.color.into()),
border_color: self.border_color.into(),
shadow: Default::default(),
}
}
}
11 changes: 7 additions & 4 deletions src/app/style/rows/button.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use iced_core::{Color, Vector};
use iced_core::{Border, Color, Vector};
use iced_style::button::{Appearance, StyleSheet};

// Button is just used as a wrapper to get access to the click event.
Expand Down Expand Up @@ -30,9 +30,12 @@ fn no_style() -> Appearance {
Appearance {
shadow_offset: Vector { x: 0.0, y: 0.0 },
background: None,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
border: Border {
color: Color::TRANSPARENT,
width: 0.0,
radius: 0.0.into(),
},
text_color: Color::BLACK,
shadow: Default::default(),
}
}
12 changes: 8 additions & 4 deletions src/app/style/rows/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::config::color::OnagreColor;
use crate::config::padding::OnagrePadding;
use iced::alignment::{Horizontal, Vertical};
use iced::Length;
use iced_core::{Background, BorderRadius};
use iced_core::{Background, Border};
use iced_core::border::Radius;
use iced_style::container::{Appearance, StyleSheet};

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -60,9 +61,12 @@ impl StyleSheet for &GenericContainerStyle {
Appearance {
text_color: Some(self.color.into()),
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border_color: self.border_color.into(),
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
shadow: Default::default(),
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/app/style/rows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::config::padding::OnagrePadding;
use generic::GenericContainerStyle;
use iced::alignment::{Horizontal, Vertical};
use iced::Length;
use iced_core::Background;
use iced_core::BorderRadius;
use iced_core::{Background, Border};
use iced_core::border::Radius;
use iced_style::container::{Appearance, StyleSheet};
use icon::IconStyle;

Expand Down Expand Up @@ -59,9 +59,12 @@ impl StyleSheet for &RowStyles {
Appearance {
text_color: Some(self.color.into()),
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border_color: self.border_color.into(),
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
shadow: Default::default(),
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/app/style/scrollable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::app::style::Scale;
use crate::config::color::OnagreColor;
use crate::config::padding::OnagrePadding;
use iced::Length;
use iced_core::{Background, BorderRadius};
use iced_core::{Background, Border};
use iced_core::border::Radius;
use iced_style::container::{Appearance, StyleSheet};

pub mod scroller;
Expand Down Expand Up @@ -48,9 +49,12 @@ impl StyleSheet for &RowContainerStyle {
Appearance {
text_color: Some(self.color.into()),
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border_color: self.border_color.into(),
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
shadow: Default::default(),
}
}
}
Expand Down
37 changes: 23 additions & 14 deletions src/app/style/scrollable/scroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use crate::app::style::Scale;
use crate::config::color::OnagreColor;
use iced::widget::scrollable::Scrollbar;
use iced::Background;
use iced_core::BorderRadius;
use iced_style::scrollable::StyleSheet;
use iced_core::Border;
use iced_core::border::Radius;
use iced_style::scrollable::{Appearance, StyleSheet};
use iced_style::theme::Scrollable;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -61,22 +62,30 @@ impl From<&ScrollerStyles> for Scrollable {
impl StyleSheet for &ScrollerStyles {
type Style = iced::Theme;

fn active(&self, _: &Self::Style) -> Scrollbar {
Scrollbar {
background: Some(Background::Color(self.background.into())),
border_radius: BorderRadius::from(self.border_radius),
border_width: self.border_width,
border_color: self.border_color.into(),
scroller: iced::widget::scrollable::Scroller {
color: self.scroller_color.into(),
border_radius: BorderRadius::from(self.scroller_border_radius),
border_width: self.scroller_border_width,
border_color: self.scroller_border_color.into(),
fn active(&self, _: &Self::Style) -> Appearance {
Appearance {
container: Default::default(),
scrollbar: Scrollbar {
background: Some(Background::Color(self.background.into())),
border: Border {
color: self.border_color.into(),
width: self.border_width,
radius: Radius::from(self.border_radius),
},
scroller: iced::widget::scrollable::Scroller {
color: self.scroller_color.into(),
border: Border {
color: self.scroller_border_color.into(),
width: self.scroller_border_width,
radius: Radius::from(self.scroller_border_radius),
}
},
},
gap: None,
}
}

fn hovered(&self, style: &Self::Style, _is_mouse_over_scrollbar: bool) -> Scrollbar {
fn hovered(&self, style: &Self::Style, _is_mouse_over_scrollbar: bool) -> Appearance {
self.active(style)
}
}
Loading

0 comments on commit 35248d4

Please sign in to comment.