Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Chore: Update to iced 0.12 #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,143 changes: 558 additions & 585 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.0", features = ["wgpu", "palette", "svg", "image", "tokio"] }
iced_core = "0.12.0"
iced_runtime = "0.12.0"
iced_style = "0.12.0"
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
52 changes: 27 additions & 25 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

use iced::alignment::{Horizontal, Vertical};
use iced::futures::channel::mpsc::{Sender, TrySendError};
use iced::keyboard::KeyCode;
use iced::keyboard::Key;
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::{event, window, Application, Command, Element, Length, Settings, Subscription};
use iced_core::keyboard::key::Named;
use iced_core::widget::operation::scrollable::RelativeOffset;
use iced_core::{Event, Font};
use iced_core::window::settings::PlatformSpecific;
use iced_core::{Event, Font, Pixels, Size};
use iced_style::Theme;
use onagre_launcher_toolkit::launcher::{Request, Response};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -49,7 +48,7 @@
id: Some("onagre".to_string()),
window: window::Settings {
transparent: true,
size: THEME.size,
size: Size::new(THEME.size.0 as f32, THEME.size.1 as f32),
decorations: false,
resizable: false,
position: window::Position::Centered,
Expand All @@ -61,12 +60,13 @@
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(THEME.font_size as f32),
antialiasing: true,
exit_on_close_request: false,
default_font,
flags: OnagreFlags { pre_value },
fonts: vec![],
})
}

Expand All @@ -81,7 +81,7 @@
Loading,
InputChanged(String),
Click(usize),
KeyboardEvent(KeyCode),
KeyboardEvent(Key),
SubscriptionResponse(SubscriptionMessage),
Unfocused,
}
Expand Down Expand Up @@ -148,15 +148,18 @@
}
}

fn view(&self) -> Element<'_, Self::Message, Renderer<Self::Theme>> {
fn view(&self) -> Element<'_, Self::Message, Self::Theme> {
// Build rows from current mode search entries
let selected = self.selected();
let rows = match &self.state.get_active_mode() {
ActiveMode::Plugin {
plugin_name,

Check failure on line 156 in src/app/mod.rs

View workflow job for this annotation

GitHub Actions / Lints & Format

unused variable: `plugin_name`
history,
..
} if *history => {
// FIXME the .into() doesn't work anymore -- need to check why!
vec![]
/*
let icon = self.state.plugin_matchers.get_plugin_icon(plugin_name);
self.state
.cache
Expand All @@ -165,6 +168,7 @@
.enumerate()
.map(|(idx, entry)| entry.to_row(selected, idx, icon.as_ref()).into())
.collect()
*/
}
ActiveMode::Web { modifier, .. } => {
let icon = self.state.plugin_matchers.get_plugin_icon("web");
Expand Down Expand Up @@ -208,7 +212,6 @@
})
.collect(),
};

// Scrollable element containing the rows
let scrollable =
scrollable(column(rows))
Expand Down Expand Up @@ -408,24 +411,24 @@
exit(0);
}

fn handle_input(&mut self, key_code: KeyCode) -> Command<Message> {
match key_code {
KeyCode::Up => {
fn handle_input(&mut self, key: Key) -> Command<Message> {
match key {
Key::Named(Named::ArrowUp) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I wasn't sure what we really wanted... this is verbose, but typesafe :)

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,11 @@
}

fn keyboard_event() -> Subscription<Message> {
subscription::events_with(|event, _status| match event {
Event::Window(window::Event::Unfocused) => Some(Message::Unfocused),
Event::Keyboard(iced::keyboard::Event::KeyPressed {
modifiers: _,
key_code,
}) => Some(Message::KeyboardEvent(key_code)),
event::listen_with(|event, _status| match event {
Event::Window(_window_id, window::Event::Unfocused) => Some(Message::Unfocused),
Event::Keyboard(iced::keyboard::Event::KeyPressed { key, .. }) => {
Some(Message::KeyboardEvent(key))
}
_ => None,
})
}
Expand Down
11 changes: 7 additions & 4 deletions src/app/style/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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::{border::Radius as BorderRadius, Background, Border};
use iced_style::container::{Appearance, StyleSheet};

// The top level container wrapping the app
Expand Down Expand Up @@ -49,9 +49,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 {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
..Default::default()
}
}
}
Expand Down
14 changes: 9 additions & 5 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;
use iced_core::{border::Radius as BorderRadius, Length};
use tracing::{error, warn};

pub mod app;
Expand Down Expand Up @@ -148,11 +149,14 @@ 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,
text_color: Some(self.color.into()),
border_color: self.border_color.into(),
background: Some(Background::Color(self.background.into())),
border: Border {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
..Default::default()
}
}
}
13 changes: 8 additions & 5 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 @@ -28,11 +28,14 @@ impl StyleSheet for &ButtonStyle {

fn no_style() -> Appearance {
Appearance {
text_color: Color::BLACK,
shadow_offset: Vector { x: 0.0, y: 0.0 },
background: None,
border_radius: 0.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
text_color: Color::BLACK,
border: Border {
radius: 0.0.into(),
color: Color::TRANSPARENT,
width: 0.0,
},
..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::Border;
use iced_core::{border::Radius as BorderRadius, Background};
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 {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
..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::Border;
use iced_core::{border::Radius as BorderRadius, Background};
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 {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
..Default::default()
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/app/style/scrollable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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::{border::Radius as BorderRadius, Background, Border};
use iced_style::container::{Appearance, StyleSheet};

pub mod scroller;
Expand Down Expand Up @@ -48,9 +48,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 {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
..Default::default()
}
}
}
Expand Down
38 changes: 24 additions & 14 deletions src/app/style/scrollable/scroller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ 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::Radius as BorderRadius;
use iced_core::Border;
use iced_style::container;
use iced_style::scrollable::{Appearance, StyleSheet};
use iced_style::theme::Scrollable;

#[derive(Debug, PartialEq)]
Expand Down Expand Up @@ -61,22 +63,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: container::Appearance::default(),
scrollbar: Scrollbar {
background: Some(Background::Color(self.background.into())),
border: Border {
radius: BorderRadius::from(self.border_radius),
width: self.border_width,
color: self.border_color.into(),
},
scroller: iced::widget::scrollable::Scroller {
color: self.scroller_color.into(),
border: Border {
radius: BorderRadius::from(self.scroller_border_radius),
width: self.scroller_border_width,
color: self.scroller_border_color.into(),
},
},
},
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
Loading