From 8149faca4d71c42d70616e9b4cb65495650b2543 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Wed, 10 May 2023 18:48:14 -0400 Subject: [PATCH] cleanup --- Cargo.toml | 2 +- iced | 2 +- src/applet/mod.rs | 37 +++++++++++--------- src/keyboard_nav.rs | 2 -- src/theme/mod.rs | 8 ++--- src/widget/aspect_ratio.rs | 2 +- src/widget/cosmic_container.rs | 2 +- src/widget/icon.rs | 10 +++--- src/widget/rectangle_tracker/mod.rs | 2 +- src/widget/rectangle_tracker/subscription.rs | 8 ++--- src/widget/search/model.rs | 1 - src/widget/segmented_button/widget.rs | 9 +++-- src/widget/warning.rs | 1 + 13 files changed, 43 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79c4f755..a786d40b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" name = "cosmic" [features] -default = ["tiny_skia", "winit", "tokio", "a11y", "lazy"] +default = ["tiny_skia", "wayland", "applet", "tokio", "a11y", "lazy"] debug = ["iced/debug"] lazy = ["iced/lazy"] a11y = ["iced/a11y", "iced_accessibility"] diff --git a/iced b/iced index afaabc4e..c95da35a 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit afaabc4ec9cfecae443b5da98bae905d31baa97b +Subproject commit c95da35ad4e88689bba6b0f94edad21db1600fb6 diff --git a/src/applet/mod.rs b/src/applet/mod.rs index 60e4fc1c..7faff9c6 100644 --- a/src/applet/mod.rs +++ b/src/applet/mod.rs @@ -5,12 +5,12 @@ use iced::{ widget::{self, Container}, Color, Element, Length, Rectangle, Settings, }; -use iced_core::BorderRadius; -use iced_native::command::platform_specific::wayland::{ +use iced_core::layout::Limits; +use iced_style::{button::StyleSheet, container::Appearance}; +use iced_widget::runtime::command::platform_specific::wayland::{ popup::{SctkPopupSettings, SctkPositioner}, window::SctkWindowSettings, }; -use iced_style::{button::StyleSheet, container::Appearance}; use sctk::reexports::protocols::xdg::shell::client::xdg_positioner::{Anchor, Gravity}; use crate::{theme::Button, Renderer}; @@ -19,14 +19,15 @@ pub use cosmic_panel_config; const APPLET_PADDING: u32 = 8; +#[must_use] pub fn applet_button_theme() -> Button { Button::Custom { active: Box::new(|t| iced_style::button::Appearance { - border_radius: BorderRadius::from(0.0), + border_radius: 0.0, ..t.active(&Button::Text) }), hover: Box::new(|t| iced_style::button::Appearance { - border_radius: BorderRadius::from(0.0), + border_radius: 0.0, ..t.hovered(&Button::Text) }), } @@ -63,6 +64,7 @@ impl Default for CosmicAppletHelper { } impl CosmicAppletHelper { + #[must_use] pub fn suggested_size(&self) -> (u16, u16) { match &self.size { Size::PanelSize(size) => match size { @@ -87,18 +89,20 @@ impl CosmicAppletHelper { } #[must_use] + #[allow(clippy::cast_precision_loss)] pub fn window_settings_with_flags(&self, flags: F) -> Settings { let (width, height) = self.suggested_size(); let width = u32::from(width); let height = u32::from(height); Settings { initial_surface: InitialSurface::XdgWindow(SctkWindowSettings { - iced_settings: iced_native::window::Settings { - size: (width + APPLET_PADDING * 2, height + APPLET_PADDING * 2), - min_size: Some((width + APPLET_PADDING * 2, height + APPLET_PADDING * 2)), - max_size: Some((width + APPLET_PADDING * 2, height + APPLET_PADDING * 2)), - ..Default::default() - }, + size: (width + APPLET_PADDING * 2, height + APPLET_PADDING * 2), + size_limits: Limits::NONE + .min_height(height as f32 + APPLET_PADDING as f32 * 2.0) + .max_height(height as f32 + APPLET_PADDING as f32 * 2.0) + .min_width(width as f32 + APPLET_PADDING as f32 * 2.0) + .max_width(width as f32 + APPLET_PADDING as f32 * 2.0), + ..Default::default() }), ..crate::settings_with_flags(flags) @@ -124,7 +128,7 @@ impl CosmicAppletHelper { &self, content: impl Into>, ) -> Container<'a, Message, Renderer> { - let (valign, halign) = match self.anchor { + let (vertical_align, horizontal_align) = match self.anchor { PanelAnchor::Left => (Vertical::Center, Horizontal::Left), PanelAnchor::Right => (Vertical::Center, Horizontal::Right), PanelAnchor::Top => (Vertical::Top, Horizontal::Center), @@ -142,15 +146,16 @@ impl CosmicAppletHelper { )) .width(Length::Shrink) .height(Length::Shrink) - .align_x(halign) - .align_y(valign) + .align_x(horizontal_align) + .align_y(vertical_align) } #[must_use] + #[allow(clippy::cast_possible_wrap)] pub fn get_popup_settings( &self, - parent: iced_native::window::Id, - id: iced_native::window::Id, + parent: iced_core::window::Id, + id: iced_core::window::Id, size: Option<(u32, u32)>, width_padding: Option, height_padding: Option, diff --git a/src/keyboard_nav.rs b/src/keyboard_nav.rs index 211fe3dd..af4703e4 100644 --- a/src/keyboard_nav.rs +++ b/src/keyboard_nav.rs @@ -14,7 +14,6 @@ pub enum Message { Search, } -#[must_use] pub fn subscription() -> Subscription { subscription::events_with(|event, status| match (event, status) { // Focus @@ -61,7 +60,6 @@ pub fn subscription() -> Subscription { } /// Unfocuses any actively-focused widget. -#[must_use] pub fn unfocus() -> Command { Command::::widget(unfocus_operation()) } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 7f7afaa1..6b9130db 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -12,12 +12,10 @@ pub use self::segmented_button::SegmentedButton; use cosmic_theme::Component; use cosmic_theme::LayeredTheme; -use iced_core::renderer::BorderRadius; use iced_style::application; use iced_style::button; use iced_style::checkbox; use iced_style::container; -use iced_style::core::text; use iced_style::menu; use iced_style::pane_grid; use iced_style::pick_list; @@ -865,7 +863,7 @@ impl scrollable::StyleSheet for Theme { fn hovered( &self, _style: &Self::Style, - is_mouse_over_scrollbar: bool, + _is_mouse_over_scrollbar: bool, ) -> scrollable::Scrollbar { let theme = self.cosmic(); @@ -1082,11 +1080,11 @@ impl text_input::StyleSheet for Theme { palette.accent.base.into() } - fn disabled_color(&self, style: &Self::Style) -> Color { + fn disabled_color(&self, _style: &Self::Style) -> Color { todo!() } - fn disabled(&self, style: &Self::Style) -> text_input::Appearance { + fn disabled(&self, _style: &Self::Style) -> text_input::Appearance { todo!() } } diff --git a/src/widget/aspect_ratio.rs b/src/widget/aspect_ratio.rs index de9f8371..0a0df145 100644 --- a/src/widget/aspect_ratio.rs +++ b/src/widget/aspect_ratio.rs @@ -6,7 +6,7 @@ use iced_core::layout; use iced_core::mouse; use iced_core::overlay; use iced_core::renderer; -use iced_core::widget::{Operation, Tree}; +use iced_core::widget::Tree; use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; pub use iced_style::container::{Appearance, StyleSheet}; diff --git a/src/widget/cosmic_container.rs b/src/widget/cosmic_container.rs index 267eef3c..84da98e6 100644 --- a/src/widget/cosmic_container.rs +++ b/src/widget/cosmic_container.rs @@ -6,7 +6,7 @@ use iced_core::layout; use iced_core::mouse; use iced_core::overlay; use iced_core::renderer; -use iced_core::widget::{Operation, Tree}; +use iced_core::widget::Tree; use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; pub use iced_style::container::{Appearance, StyleSheet}; diff --git a/src/widget/icon.rs b/src/widget/icon.rs index 0eea85fb..7691f733 100644 --- a/src/widget/icon.rs +++ b/src/widget/icon.rs @@ -79,7 +79,7 @@ impl<'a> IconSource<'a> { } else if let Some(icon) = icon { Handle::Image(icon.into()) } else { - eprintln!("icon '{:?}' size {} not found", self, size); + eprintln!("icon '{self:?}' size {size} not found"); Handle::Image(image::Handle::from_memory(Vec::new())) } } @@ -236,8 +236,8 @@ pub fn icon<'a>(source: impl Into>, size: u16) -> Icon<'a> { impl<'a> Icon<'a> { fn raster_element(&self, handle: image::Handle) -> Element<'static, Message> { Image::new(handle) - .width(self.width.unwrap_or(Length::Fixed(self.size as f32))) - .height(self.height.unwrap_or(Length::Fixed(self.size as f32))) + .width(self.width.unwrap_or(Length::Fixed(f32::from(self.size)))) + .height(self.height.unwrap_or(Length::Fixed(f32::from(self.size)))) .content_fit(self.content_fit) .into() } @@ -245,8 +245,8 @@ impl<'a> Icon<'a> { fn svg_element(&self, handle: svg::Handle) -> Element<'static, Message> { svg::Svg::::new(handle) .style(self.style.clone()) - .width(self.width.unwrap_or(Length::Fixed(self.size as f32))) - .height(self.height.unwrap_or(Length::Fixed(self.size as f32))) + .width(self.width.unwrap_or(Length::Fixed(f32::from(self.size)))) + .height(self.height.unwrap_or(Length::Fixed(f32::from(self.size)))) .content_fit(self.content_fit) .into() } diff --git a/src/widget/rectangle_tracker/mod.rs b/src/widget/rectangle_tracker/mod.rs index 1d5b59a6..3d9f378c 100644 --- a/src/widget/rectangle_tracker/mod.rs +++ b/src/widget/rectangle_tracker/mod.rs @@ -10,7 +10,7 @@ use iced_core::layout; use iced_core::mouse; use iced_core::overlay; use iced_core::renderer; -use iced_core::widget::{Operation, Tree}; +use iced_core::widget::Tree; use iced_core::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; use std::{fmt::Debug, hash::Hash}; diff --git a/src/widget/rectangle_tracker/subscription.rs b/src/widget/rectangle_tracker/subscription.rs index b0ece685..0c61808b 100644 --- a/src/widget/rectangle_tracker/subscription.rs +++ b/src/widget/rectangle_tracker/subscription.rs @@ -41,10 +41,10 @@ async fn start_listening { if let Some(prev) = map.get(&u.0) { let new = u.1; - if prev.width != new.width - || prev.height != new.height - || prev.x != new.x - || prev.y != new.y + if (prev.width - new.width).abs() > 0.1 + || (prev.height - new.height).abs() > 0.1 + || (prev.x - new.x).abs() > 0.1 + || (prev.y - new.y).abs() > 0.1 { map.insert(u.0, new); return ( diff --git a/src/widget/search/model.rs b/src/widget/search/model.rs index 0b099ece..632c05b6 100644 --- a/src/widget/search/model.rs +++ b/src/widget/search/model.rs @@ -13,7 +13,6 @@ pub struct Model { impl Model { /// Focuses the search field. - #[must_use] pub fn focus(&mut self) -> crate::iced::Command { self.state = State::Active; iced::widget::text_input::focus(self.input_id.clone()) diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index ec7394d2..58756b38 100644 --- a/src/widget/segmented_button/widget.rs +++ b/src/widget/segmented_button/widget.rs @@ -12,7 +12,7 @@ use iced::{ }; use iced_core::renderer::BorderRadius; use iced_core::text::{LineHeight, Shaping}; -use iced_core::widget::{self, operation, tree, Operation}; +use iced_core::widget::{self, operation, tree}; use iced_core::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget}; use std::marker::PhantomData; @@ -391,7 +391,7 @@ where &self, tree: &mut Tree, _layout: Layout<'_>, - renderer: &Renderer, + _renderer: &Renderer, operation: &mut dyn iced_core::widget::Operation< iced_core::widget::OperationOutputWrapper, >, @@ -568,10 +568,10 @@ where // Draw the text in this button. renderer.fill_text(iced_core::text::Text { content: text, - size: f32::from(self.font_size), + size: self.font_size, bounds, color: status_appearance.text_color, - font: font.clone(), + font, horizontal_alignment, vertical_alignment: alignment::Vertical::Center, shaping: Shaping::Advanced, @@ -642,7 +642,6 @@ where } /// A command that focuses a segmented item stored in a widget. -#[must_use] pub fn focus(id: Id) -> Command { Command::widget(operation::focusable::focus(id.0)) } diff --git a/src/widget/warning.rs b/src/widget/warning.rs index b64315f3..e4d812c1 100644 --- a/src/widget/warning.rs +++ b/src/widget/warning.rs @@ -64,6 +64,7 @@ impl<'a, Message: 'static + Clone> From> for Element<'a, Me } } +#[must_use] pub fn warning_container(theme: &Theme) -> widget::container::Appearance { widget::container::Appearance { text_color: Some(theme.cosmic().warning.on.into()),