From 850968715c16f3800fa899fe939dbf45d1e1a9b8 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 15 Jun 2023 11:16:32 -0400 Subject: [PATCH] udpate iced to use latest rebase --- Cargo.toml | 8 +-- cosmic-theme/Cargo.toml | 2 +- examples/cosmic-sctk/Cargo.toml | 2 +- examples/cosmic/Cargo.toml | 2 +- iced | 2 +- src/theme/mod.rs | 81 +++++++++++++++++---------- src/theme/segmented_button.rs | 6 +- src/widget/aspect_ratio.rs | 6 +- src/widget/cosmic_container.rs | 6 +- src/widget/popover.rs | 12 ++-- src/widget/rectangle_tracker/mod.rs | 6 +- src/widget/segmented_button/style.rs | 2 +- src/widget/segmented_button/widget.rs | 25 ++++----- 13 files changed, 87 insertions(+), 73 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8a2285d1..30775ed9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,23 +7,21 @@ edition = "2021" name = "cosmic" [features] -default = ["tiny_skia", "winit", "tokio", "a11y"] +default = ["winit", "tokio", "a11y"] debug = ["iced/debug"] a11y = ["iced/a11y", "iced_accessibility"] -tiny_skia = ["iced/tiny-skia", "iced_tiny_skia"] wayland = ["iced/wayland", "iced_sctk", "sctk",] wgpu = ["iced/wgpu", "iced_wgpu"] tokio = ["dep:tokio", "iced/tokio"] smol = ["iced/smol"] winit = ["iced/winit", "iced_winit"] -winit_tiny_skia = ["winit", "tiny_skia"] winit_wgpu = ["winit", "wgpu"] [dependencies] apply = "0.3.0" derive_setters = "0.1.5" lazy_static = "1.4.0" -palette = "0.6.1" +palette = "0.7" tokio = { version = "1.24.2", optional = true } sctk = { package = "smithay-client-toolkit", git = "https://github.com/pop-os/client-toolkit", optional = true, tag = "themed-pointer"} slotmap = "1.0.6" @@ -61,9 +59,9 @@ path = "iced/futures" path = "iced/accessibility" optional = true + [dependencies.iced_tiny_skia] path = "iced/tiny_skia" -optional = true [dependencies.iced_style] path = "iced/style" diff --git a/cosmic-theme/Cargo.toml b/cosmic-theme/Cargo.toml index 7f745b64..b53e3387 100644 --- a/cosmic-theme/Cargo.toml +++ b/cosmic-theme/Cargo.toml @@ -17,7 +17,7 @@ theme-from-image = ["kmeans_colors", "contrast-derivation", "float-cmp", "image" hex-color = ["hex"] [dependencies] -palette = {version = "0.6", features = ["serializing"] } +palette = {version = "0.7", features = ["serializing"] } anyhow = "1.0" hex = {version = "0.4.3", optional = true} kmeans_colors = { version = "0.5", features = ["palette_color"], default-features = false, optional = true } diff --git a/examples/cosmic-sctk/Cargo.toml b/examples/cosmic-sctk/Cargo.toml index f6d3da38..e614bb88 100644 --- a/examples/cosmic-sctk/Cargo.toml +++ b/examples/cosmic-sctk/Cargo.toml @@ -6,4 +6,4 @@ edition = "2021" publish = false [dependencies] -libcosmic = { path = "../..", default-features = false, features = ["wayland", "tokio", "tiny_skia", "a11y"] } +libcosmic = { path = "../..", default-features = false, features = ["wayland", "tokio", "a11y"] } diff --git a/examples/cosmic/Cargo.toml b/examples/cosmic/Cargo.toml index feb41ae5..5e97c675 100644 --- a/examples/cosmic/Cargo.toml +++ b/examples/cosmic/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] apply = "0.3.0" fraction = "0.13.0" -libcosmic = { path = "../..", default-features = false, features = ["debug", "winit_tiny_skia", "a11y"] } +libcosmic = { path = "../..", default-features = false, features = ["debug", "winit", "a11y"] } once_cell = "1.15" slotmap = "1.0.6" env_logger = "0.10" diff --git a/iced b/iced index 978e9fe8..c308e226 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 978e9fe8142bb301ce27ad23ce0afb12ef8918a7 +Subproject commit c308e2266867a7bb4dfadb2dc8bdf310b7c87ee8 diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 231d5faa..5ab9cde1 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -4,6 +4,7 @@ pub mod expander; mod segmented_button; +use std::f32::consts::PI; use std::hash::Hash; use std::hash::Hasher; use std::rc::Rc; @@ -16,7 +17,9 @@ use cosmic_config::CosmicConfigEntry; use cosmic_theme::util::CssColor; use cosmic_theme::Component; use cosmic_theme::LayeredTheme; -use iced_core::renderer::BorderRadius; +use iced_core::gradient::Linear; +use iced_core::BorderRadius; +use iced_core::Radians; use iced_futures::Subscription; use iced_style::application; use iced_style::button; @@ -233,8 +236,8 @@ impl button::StyleSheet for Theme { let component = style.cosmic(self); button::Appearance { border_radius: match style { - Button::Link => 0.0, - _ => 24.0, + Button::Link => 0.0.into(), + _ => 24.0.into(), }, background: match style { Button::Link | Button::Text => None, @@ -317,7 +320,7 @@ impl checkbox::StyleSheet for Theme { palette.background.base.into() }), icon_color: palette.accent.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.accent.base @@ -334,7 +337,7 @@ impl checkbox::StyleSheet for Theme { palette.background.base.into() }), icon_color: palette.background.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: neutral_7.into(), text_color: None, @@ -346,7 +349,7 @@ impl checkbox::StyleSheet for Theme { palette.background.base.into() }), icon_color: palette.success.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.success.base @@ -363,7 +366,7 @@ impl checkbox::StyleSheet for Theme { palette.background.base.into() }), icon_color: palette.destructive.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.destructive.base @@ -390,7 +393,7 @@ impl checkbox::StyleSheet for Theme { neutral_10.into() }), icon_color: palette.accent.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.accent.base @@ -407,7 +410,7 @@ impl checkbox::StyleSheet for Theme { neutral_10.into() }), icon_color: self.current_container().on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { self.current_container().base @@ -424,7 +427,7 @@ impl checkbox::StyleSheet for Theme { neutral_10.into() }), icon_color: palette.success.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.success.base @@ -441,7 +444,7 @@ impl checkbox::StyleSheet for Theme { neutral_10.into() }), icon_color: palette.destructive.on.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { palette.destructive.base @@ -519,10 +522,17 @@ impl container::StyleSheet for Theme { } Container::HeaderBar => { let palette = self.cosmic(); + let mut header_top = palette.background.base; + let header_bottom = palette.background.base; + header_top.alpha = 0.8; container::Appearance { text_color: Some(Color::from(palette.background.on)), - background: Some(iced::Background::Color(palette.background.base.into())), + background: Some(iced::Background::Gradient(iced_core::Gradient::Linear( + Linear::new(Radians(3.0 * PI / 2.0)) + .add_stop(0.0, header_top.into()) + .add_stop(1.0, header_bottom.into()), + ))), border_radius: BorderRadius::from([16.0, 16.0, 0.0, 0.0]), border_width: 0.0, border_color: Color::TRANSPARENT, @@ -572,6 +582,7 @@ impl slider::StyleSheet for Theme { Color::TRANSPARENT, ), width: 4.0, + border_radius: 2.0.into(), }, handle: slider::Handle { @@ -616,7 +627,7 @@ impl menu::StyleSheet for Theme { text_color: cosmic.on_bg_color().into(), background: Background::Color(cosmic.background.base.into()), border_width: 0.0, - border_radius: 16.0, + border_radius: 16.0.into(), border_color: Color::TRANSPARENT, selected_text_color: cosmic.on_bg_color().into(), // TODO doesn't seem to be specified @@ -638,7 +649,7 @@ impl pick_list::StyleSheet for Theme { text_color: cosmic.on_bg_color().into(), background: Color::TRANSPARENT.into(), placeholder_color: cosmic.on_bg_color().into(), - border_radius: 24.0, + border_radius: 24.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, // icon_size: 0.7, // TODO: how to replace @@ -772,6 +783,16 @@ impl pane_grid::StyleSheet for Theme { width: 2.0, }) } + + fn hovered_region(&self, style: &Self::Style) -> pane_grid::Appearance { + let theme = self.cosmic(); + pane_grid::Appearance { + background: Background::Color(theme.bg_color().into()), + border_width: 2.0, + border_color: theme.bg_divider().into(), + border_radius: 0.0.into(), + } + } } /* @@ -802,17 +823,17 @@ impl progress_bar::StyleSheet for Theme { ProgressBar::Primary => progress_bar::Appearance { background: Color::from(theme.background.divider).into(), bar: Color::from(theme.accent.base).into(), - border_radius: 2.0, + border_radius: 2.0.into(), }, ProgressBar::Success => progress_bar::Appearance { background: Color::from(theme.background.divider).into(), bar: Color::from(theme.success.base).into(), - border_radius: 2.0, + border_radius: 2.0.into(), }, ProgressBar::Danger => progress_bar::Appearance { background: Color::from(theme.background.divider).into(), bar: Color::from(theme.destructive.base).into(), - border_radius: 2.0, + border_radius: 2.0.into(), }, ProgressBar::Custom(f) => f(self), } @@ -845,19 +866,19 @@ impl rule::StyleSheet for Theme { Rule::Default => rule::Appearance { color: self.current_container().divider.into(), width: 1, - radius: 0.0, + radius: 0.0.into(), fill_mode: rule::FillMode::Full, }, Rule::LightDivider => rule::Appearance { color: self.current_container().divider.into(), width: 1, - radius: 0.0, + radius: 0.0.into(), fill_mode: rule::FillMode::Padded(10), }, Rule::HeavyDivider => rule::Appearance { color: self.current_container().divider.into(), width: 4, - radius: 4.0, + radius: 4.0.into(), fill_mode: rule::FillMode::Full, }, Rule::Custom(f) => f(self), @@ -876,12 +897,12 @@ impl scrollable::StyleSheet for Theme { background: Some(Background::Color( self.current_container().component.base.into(), )), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, scroller: scrollable::Scroller { color: self.current_container().component.divider.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, }, @@ -899,12 +920,12 @@ impl scrollable::StyleSheet for Theme { background: Some(Background::Color( self.current_container().component.hover.into(), )), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, scroller: scrollable::Scroller { color: theme.accent.base.into(), - border_radius: 4.0, + border_radius: 4.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, }, @@ -1028,14 +1049,14 @@ impl text_input::StyleSheet for Theme { match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 8.0, + border_radius: 8.0.into(), border_width: 1.0, border_color: self.current_container().component.divider.into(), icon_color: self.current_container().on.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 24.0, + border_radius: 24.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, icon_color: self.current_container().on.into(), @@ -1051,14 +1072,14 @@ impl text_input::StyleSheet for Theme { match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 8.0, + border_radius: 8.0.into(), border_width: 1.0, border_color: palette.accent.base.into(), icon_color: self.current_container().on.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 24.0, + border_radius: 24.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, icon_color: self.current_container().on.into(), @@ -1074,14 +1095,14 @@ impl text_input::StyleSheet for Theme { match style { TextInput::Default => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 8.0, + border_radius: 8.0.into(), border_width: 1.0, border_color: palette.accent.base.into(), icon_color: self.current_container().on.into(), }, TextInput::Search => text_input::Appearance { background: Color::from(bg).into(), - border_radius: 24.0, + border_radius: 24.0.into(), border_width: 0.0, border_color: Color::TRANSPARENT, icon_color: self.current_container().on.into(), diff --git a/src/theme/segmented_button.rs b/src/theme/segmented_button.rs index 32123414..1e1f53c3 100644 --- a/src/theme/segmented_button.rs +++ b/src/theme/segmented_button.rs @@ -3,7 +3,7 @@ use crate::widget::segmented_button::{Appearance, ItemAppearance, StyleSheet}; use crate::{theme::Theme, widget::segmented_button::ItemStatusAppearance}; -use iced_core::{renderer::BorderRadius, Background}; +use iced_core::{Background, BorderRadius}; use palette::{rgb::Rgb, Alpha}; #[derive(Default)] @@ -141,7 +141,7 @@ impl StyleSheet for Theme { mod horizontal { use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance}; - use iced_core::{renderer::BorderRadius, Background}; + use iced_core::{Background, BorderRadius}; use palette::{rgb::Rgb, Alpha}; pub fn selection_active(cosmic: &cosmic_theme::Theme>) -> ItemStatusAppearance { @@ -222,7 +222,7 @@ pub fn hover( mod vertical { use crate::widget::segmented_button::{ItemAppearance, ItemStatusAppearance}; - use iced_core::{renderer::BorderRadius, Background}; + use iced_core::{Background, BorderRadius}; use palette::{rgb::Rgb, Alpha}; pub fn selection_active(cosmic: &cosmic_theme::Theme>) -> ItemStatusAppearance { diff --git a/src/widget/aspect_ratio.rs b/src/widget/aspect_ratio.rs index 0a0df145..bf000006 100644 --- a/src/widget/aspect_ratio.rs +++ b/src/widget/aspect_ratio.rs @@ -186,7 +186,7 @@ where tree: &mut Tree, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -206,7 +206,7 @@ where &self, tree: &Tree, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> mouse::Interaction { @@ -221,7 +221,7 @@ where theme: &Renderer::Theme, renderer_style: &renderer::Style, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, ) { self.container.draw( diff --git a/src/widget/cosmic_container.rs b/src/widget/cosmic_container.rs index 84da98e6..3214b7fa 100644 --- a/src/widget/cosmic_container.rs +++ b/src/widget/cosmic_container.rs @@ -173,7 +173,7 @@ where tree: &mut Tree, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -193,7 +193,7 @@ where &self, tree: &Tree, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> mouse::Interaction { @@ -208,7 +208,7 @@ where theme: &Renderer::Theme, renderer_style: &renderer::Style, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, ) { let theme = if let Some(layer) = self.layer { diff --git a/src/widget/popover.rs b/src/widget/popover.rs index 64670a1c..2135f7f6 100644 --- a/src/widget/popover.rs +++ b/src/widget/popover.rs @@ -83,7 +83,7 @@ where tree: &mut Tree, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -103,7 +103,7 @@ where &self, tree: &Tree, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> mouse::Interaction { @@ -123,7 +123,7 @@ where theme: &Renderer::Theme, renderer_style: &renderer::Style, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, ) { self.content.as_widget().draw( @@ -208,7 +208,7 @@ where &mut self, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -227,7 +227,7 @@ where fn mouse_interaction( &self, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> mouse::Interaction { @@ -246,7 +246,7 @@ where theme: &Renderer::Theme, style: &renderer::Style, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, ) { let bounds = layout.bounds(); self.content.borrow().as_widget().draw( diff --git a/src/widget/rectangle_tracker/mod.rs b/src/widget/rectangle_tracker/mod.rs index 3d9f378c..6b84e5d2 100644 --- a/src/widget/rectangle_tracker/mod.rs +++ b/src/widget/rectangle_tracker/mod.rs @@ -185,7 +185,7 @@ where tree: &mut Tree, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, renderer: &Renderer, clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -205,7 +205,7 @@ where &self, tree: &Tree, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, renderer: &Renderer, ) -> mouse::Interaction { @@ -220,7 +220,7 @@ where theme: &Renderer::Theme, renderer_style: &renderer::Style, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, viewport: &Rectangle, ) { let _ = self.tx.unbounded_send((self.id, layout.bounds())); diff --git a/src/widget/segmented_button/style.rs b/src/widget/segmented_button/style.rs index ea91b785..5cc2e1a7 100644 --- a/src/widget/segmented_button/style.rs +++ b/src/widget/segmented_button/style.rs @@ -1,7 +1,7 @@ // Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 -use iced_core::{renderer::BorderRadius, Background, Color}; +use iced_core::{Background, BorderRadius, Color}; /// Appearance of the segmented button. #[derive(Default, Clone, Copy)] diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index 272bb217..cee18b34 100644 --- a/src/widget/segmented_button/widget.rs +++ b/src/widget/segmented_button/widget.rs @@ -10,9 +10,9 @@ use iced::{ alignment, event, keyboard, mouse, touch, Background, Color, Command, Element, Event, Length, Point, Rectangle, Size, }; -use iced_core::renderer::BorderRadius; use iced_core::text::{LineHeight, Shaping}; use iced_core::widget::{self, operation, tree}; +use iced_core::BorderRadius; use iced_core::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget}; use std::marker::PhantomData; @@ -303,7 +303,7 @@ where tree: &mut Tree, event: Event, layout: Layout<'_>, - cursor_position: Point, + cursor_position: mouse::Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, @@ -311,10 +311,10 @@ where let bounds = layout.bounds(); let state = tree.state.downcast_mut::(); - if bounds.contains(cursor_position) { + if cursor_position.is_over(bounds) { for (nth, key) in self.model.order.iter().copied().enumerate() { let bounds = self.variant_button_bounds(bounds, nth); - if bounds.contains(cursor_position) { + if cursor_position.is_over(bounds) { if self.model.items[key].enabled { // Record that the mouse is hovering over this button. state.hovered = key; @@ -322,13 +322,11 @@ where // If marked as closable, show a close icon. if self.model.items[key].closable { if let Some(on_close) = self.on_close.as_ref() { - if close_bounds( + if cursor_position.is_over(close_bounds( bounds, f32::from(self.icon_size), self.button_padding, - ) - .contains(cursor_position) - { + )) { if let Event::Mouse(mouse::Event::ButtonReleased( mouse::Button::Left, )) @@ -404,18 +402,15 @@ where &self, _tree: &Tree, layout: Layout<'_>, - cursor_position: iced::Point, + cursor_position: mouse::Cursor, _viewport: &iced::Rectangle, _renderer: &Renderer, ) -> iced_core::mouse::Interaction { let bounds = layout.bounds(); - if bounds.contains(cursor_position) { + if cursor_position.is_over(bounds) { for (nth, key) in self.model.order.iter().copied().enumerate() { - if self - .variant_button_bounds(bounds, nth) - .contains(cursor_position) - { + if cursor_position.is_over(self.variant_button_bounds(bounds, nth)) { return if self.model.items[key].enabled { iced_core::mouse::Interaction::Pointer } else { @@ -436,7 +431,7 @@ where theme: &::Theme, _style: &renderer::Style, layout: Layout<'_>, - _cursor_position: iced::Point, + _cursor_position: mouse::Cursor, _viewport: &iced::Rectangle, ) { let state = tree.state.downcast_ref::();