diff --git a/Cargo.toml b/Cargo.toml index 379f60ca..478c28b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,16 +7,17 @@ edition = "2021" name = "cosmic" [features] -default = ["dyrend", "winit", "tokio"] +default = ["tiny_skia", "winit", "tokio", "a11y", "lazy"] debug = ["iced/debug"] -softbuffer = ["iced/softbuffer", "iced_softbuffer"] -dyrend = ["iced/dyrend"] -wayland = ["iced/wayland", "iced/dyrend", "iced_sctk"] +lazy = ["iced/lazy"] +a11y = ["iced/a11y", "iced_accessibility"] +tiny_skia = ["iced/tiny-skia", "iced_tiny_skia"] +wayland = ["iced/wayland", "iced_sctk"] wgpu = ["iced/wgpu", "iced_wgpu"] tokio = ["dep:tokio", "iced/tokio"] winit = ["iced/winit", "iced_winit"] applet = ["cosmic-panel-config", "sctk", "wayland"] -winit_softbuffer = ["winit", "softbuffer"] +winit_tiny_skia = ["winit", "tiny_skia"] winit_wgpu = ["winit", "wgpu"] [dependencies] @@ -37,44 +38,37 @@ freedesktop-icons = "0.2.2" git = "https://github.com/pop-os/cosmic-theme.git" [dependencies.iced] -path = "iced" +path = "../fork/iced" default-features = false features = ["image", "svg"] [dependencies.iced_core] -path = "iced/core" +path = "../fork/iced/core" -[dependencies.iced_lazy] -path = "iced/lazy" +[dependencies.iced_widget] +path = "../fork/iced/widget" -[dependencies.iced_native] -path = "iced/native" +[dependencies.iced_accessibility] +path = "../fork/iced/accessibility" -[dependencies.iced_softbuffer] -path = "iced/softbuffer" optional = true - -[dependencies.iced_dyrend] -path = "iced/dyrend" +[dependencies.iced_tiny_skia] +path = "../fork/iced/tiny_skia" optional = true [dependencies.iced_style] -path = "iced/style" +path = "../fork/iced/style" [dependencies.iced_sctk] -path = "iced/sctk" +path = "../fork/iced/sctk" optional = true [dependencies.iced_winit] -path = "iced/winit" +path = "../fork/iced/winit" optional = true [dependencies.iced_wgpu] -path = "iced/wgpu" -optional = true - -[dependencies.iced_glow] -path = "iced/glow" +path = "../fork/iced/wgpu" optional = true [workspace] diff --git a/examples/cosmic-sctk/Cargo.toml b/examples/cosmic-sctk/Cargo.toml index 277ec5f2..03c3b1b7 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"] } +libcosmic = { path = "../..", default-features = false, features = ["wayland", "tokio", "tiny_skia", "a11y", "lazy"] } diff --git a/examples/cosmic-sctk/src/window.rs b/examples/cosmic-sctk/src/window.rs index 920428b0..d930c021 100644 --- a/examples/cosmic-sctk/src/window.rs +++ b/examples/cosmic-sctk/src/window.rs @@ -2,14 +2,12 @@ // SPDX-License-Identifier: MPL-2.0 use cosmic::{ - iced::{self, wayland::window::set_mode_window, Alignment, Application, Command, Length}, + iced::{self, wayland::window::set_mode_window, Application, Command, Length}, iced::{ wayland::window::{start_drag_window, toggle_maximize}, - widget::{ - column, container, horizontal_space, pick_list, progress_bar, radio, row, slider, - }, + widget::{column, container, horizontal_space, pick_list, progress_bar, row, slider}, + window, }, - iced_native::window, theme::{self, Theme}, widget::{ button, header_bar, nav_bar, nav_bar_toggle, @@ -176,6 +174,7 @@ pub enum Message { InputChanged, Rectangle(RectangleUpdate), NavBar(segmented_button::Entity), + Ignore, } impl Application for Window { @@ -240,9 +239,9 @@ impl Application for Window { Message::ToggleNavBarCondensed => { self.nav_bar_toggled_condensed = !self.nav_bar_toggled_condensed } - Message::Drag => return start_drag_window(window::Id::new(0)), - Message::Minimize => return set_mode_window(window::Id::new(0), window::Mode::Hidden), - Message::Maximize => return toggle_maximize(window::Id::new(0)), + Message::Drag => return start_drag_window(window::Id(0)), + Message::Minimize => return set_mode_window(window::Id(0), window::Mode::Hidden), + Message::Maximize => return toggle_maximize(window::Id(0)), Message::RowSelected(row) => println!("Selected row {row}"), Message::InputChanged => {} Message::Rectangle(r) => match r { @@ -253,6 +252,7 @@ impl Application for Window { self.rectangle_tracker.replace(t); } }, + Message::Ignore => {} } Command::none() @@ -363,13 +363,13 @@ impl Application for Window { .add(settings::item( "Slider", slider(0.0..=100.0, self.slider_value, Message::SliderChanged) - .width(Length::Units(250)), + .width(Length::Fixed(250.0)), )) .add(settings::item( "Progress", progress_bar(0.0..=100.0, self.slider_value) - .width(Length::Units(250)) - .height(Length::Units(4)), + .width(Length::Fixed(250.0)) + .height(Length::Fixed(4.0)), )) .into(), ]) @@ -408,6 +408,12 @@ impl Application for Window { Message::Close } fn subscription(&self) -> iced::Subscription { - rectangle_tracker_subscription(0).map(|(i, e)| Message::Rectangle(e)) + rectangle_tracker_subscription(0).map(|m| { + if let Some((_, e)) = m { + Message::Rectangle(e) + } else { + Message::Ignore + } + }) } } diff --git a/examples/cosmic/Cargo.toml b/examples/cosmic/Cargo.toml index db0cb60e..cdd2b98d 100644 --- a/examples/cosmic/Cargo.toml +++ b/examples/cosmic/Cargo.toml @@ -8,6 +8,7 @@ publish = false [dependencies] apply = "0.3.0" fraction = "0.13.0" -libcosmic = { path = "../..", default-features = false, features = ["debug", "winit_softbuffer"] } +libcosmic = { path = "../..", default-features = false, features = ["debug", "winit_tiny_skia", "a11y", "lazy"] } once_cell = "1.15" -slotmap = "1.0.6" \ No newline at end of file +slotmap = "1.0.6" +env_logger = "0.10" diff --git a/examples/cosmic/src/main.rs b/examples/cosmic/src/main.rs index 1d1f2bfe..143a7b65 100644 --- a/examples/cosmic/src/main.rs +++ b/examples/cosmic/src/main.rs @@ -4,9 +4,15 @@ use cosmic::{iced::Application, settings}; mod window; +use env_logger::Env; pub use window::*; pub fn main() -> cosmic::iced::Result { + let env = Env::default() + .filter_or("MY_LOG_LEVEL", "debug") + .write_style_or("MY_LOG_STYLE", "always"); + + env_logger::init_from_env(env); settings::set_default_icon_theme("Pop"); let mut settings = settings(); settings.window.min_size = Some((600, 300)); diff --git a/examples/cosmic/src/window.rs b/examples/cosmic/src/window.rs index 50b54904..5e32c6d6 100644 --- a/examples/cosmic/src/window.rs +++ b/examples/cosmic/src/window.rs @@ -1,25 +1,27 @@ /// Copyright 2022 System76 // SPDX-License-Identifier: MPL-2.0 use cosmic::{ - iced::widget::{self, button, column, container, horizontal_space, row, text}, iced::{self, Application, Command, Length, Subscription}, - iced_native::{subscription, window}, - iced_winit::window::{close, drag, minimize, toggle_maximize}, + iced::{ + subscription, + widget::{self, column, container, horizontal_space, row, text}, + window::{self, close, drag, minimize, toggle_maximize}, + }, keyboard_nav, - theme::{self, Theme, COSMIC_DARK, COSMIC_LIGHT}, + theme::{self, Theme}, widget::{ header_bar, icon, list, nav_bar, nav_bar_toggle, scrollable, segmented_button, settings, warning, IconSource, }, Element, ElementExt, }; -use once_cell::sync::Lazy; use std::{ sync::atomic::{AtomicU32, Ordering}, vec, }; -static BTN: Lazy = Lazy::new(button::Id::unique); +// XXX The use of button is removed because it assigns the same ID to multiple buttons, causing a crash when a11y is enabled... +// static BTN: Lazy = Lazy::new(|| id::Id::new("BTN")); mod bluetooth; @@ -237,7 +239,7 @@ impl Window { )) .padding(0) .style(theme::Button::Link) - .id(BTN.clone()) + // .id(BTN.clone()) .on_press(Message::from(page)), row!( text(sub_page.title()).size(30), @@ -282,7 +284,7 @@ impl Window { .padding(0) .style(theme::Button::Transparent) .on_press(Message::from(sub_page.into_page())) - .id(BTN.clone()) + // .id(BTN.clone()) .into() } @@ -405,10 +407,10 @@ impl Application for Window { Message::ToggleNavBarCondensed => { self.nav_bar_toggled_condensed = !self.nav_bar_toggled_condensed } - Message::Drag => return drag(window::Id::new(0)), - Message::Close => return close(window::Id::new(0)), - Message::Minimize => return minimize(window::Id::new(0), true), - Message::Maximize => return toggle_maximize(window::Id::new(0)), + Message::Drag => return drag(), + Message::Close => return close(), + Message::Minimize => return minimize(true), + Message::Maximize => return toggle_maximize(), Message::InputChanged => {} @@ -553,7 +555,7 @@ impl Application for Window { column(vec![ header, warning, - iced::widget::vertical_space(Length::Units(12)).into(), + iced::widget::vertical_space(Length::Fixed(12.0)).into(), content, ]) .into() diff --git a/examples/cosmic/src/window/demo.rs b/examples/cosmic/src/window/demo.rs index acfad0b3..ee1db971 100644 --- a/examples/cosmic/src/window/demo.rs +++ b/examples/cosmic/src/window/demo.rs @@ -2,7 +2,7 @@ use apply::Apply; use cosmic::{ cosmic_theme, iced::widget::{checkbox, pick_list, progress_bar, radio, row, slider, text, text_input}, - iced::{Alignment, Length}, + iced::{id, Alignment, Length}, theme::{self, Button as ButtonTheme, Theme}, widget::{ button, container, icon, segmented_button, segmented_selection, settings, spin_button, @@ -29,7 +29,7 @@ pub enum MultiOption { OptionD, OptionE, } -static INPUT_ID: Lazy = Lazy::new(text_input::Id::unique); +static INPUT_ID: Lazy = Lazy::new(id::Id::unique); #[derive(Clone, Debug)] pub enum Message { @@ -253,13 +253,13 @@ impl State { .add(settings::item( "Slider", slider(0.0..=100.0, self.slider_value, Message::SliderChanged) - .width(Length::Units(250)), + .width(Length::Fixed(250.0)), )) .add(settings::item( "Progress", progress_bar(0.0..=100.0, self.slider_value) - .width(Length::Units(250)) - .height(Length::Units(4)), + .width(Length::Fixed(250.0)) + .height(Length::Fixed(4.0)), )) .add(settings::item_row(vec![checkbox( "Checkbox", @@ -401,8 +401,8 @@ impl State { text_input( "Type to search apps or type “?” for more options...", &self.entry_value, - Message::InputChanged, ) + .on_input(Message::InputChanged) // .on_submit(Message::Activate(None)) .padding(8) .size(20) diff --git a/examples/cosmic/src/window/desktop.rs b/examples/cosmic/src/window/desktop.rs index 7f3ddadd..f20722fb 100644 --- a/examples/cosmic/src/window/desktop.rs +++ b/examples/cosmic/src/window/desktop.rs @@ -219,10 +219,10 @@ impl State { for image_path in chunk.iter() { image_row.push(if image_path.ends_with(".svg") { svg(svg::Handle::from_path(image_path)) - .width(Length::Units(150)) + .width(Length::Fixed(150.0)) .into() } else { - image(image_path).width(Length::Units(150)).into() + image(image_path).width(Length::Fixed(150.0)).into() }); } image_column.push(row(image_row).spacing(16).into()); @@ -234,7 +234,7 @@ impl State { horizontal_space(Length::Fill), container( image("/usr/share/backgrounds/pop/kate-hazen-COSMIC-desktop-wallpaper.png") - .width(Length::Units(300)) + .width(Length::Fixed(300.0)) ) .padding(4) .style(theme::Container::Background), diff --git a/examples/cosmic/src/window/editor.rs b/examples/cosmic/src/window/editor.rs index c1423e29..e272050d 100644 --- a/examples/cosmic/src/window/editor.rs +++ b/examples/cosmic/src/window/editor.rs @@ -1,7 +1,6 @@ use apply::Apply; use cosmic::iced::widget::{horizontal_space, row, scrollable}; -use cosmic::iced::Length; -use cosmic::iced_winit::Alignment; +use cosmic::iced::{Alignment, Length}; use cosmic::widget::{button, segmented_button, view_switcher}; use cosmic::{theme, Element}; use slotmap::Key; diff --git a/iced b/iced index 6f6c24bc..bea3f519 160000 --- a/iced +++ b/iced @@ -1 +1 @@ -Subproject commit 6f6c24bc369947b45000353fc0573ec7b692869f +Subproject commit bea3f519ab5036c017e70def32e887a4d11c89aa diff --git a/src/executor/multi.rs b/src/executor/multi.rs index a6f07318..18cb8234 100644 --- a/src/executor/multi.rs +++ b/src/executor/multi.rs @@ -7,7 +7,7 @@ use std::future::Future; pub struct Executor(tokio::runtime::Runtime); #[cfg(feature = "tokio")] -impl iced_native::Executor for Executor { +impl iced::Executor for Executor { fn new() -> Result { Ok(Self( tokio::runtime::Builder::new_multi_thread() diff --git a/src/executor/single.rs b/src/executor/single.rs index e293fc1d..1ffa0529 100644 --- a/src/executor/single.rs +++ b/src/executor/single.rs @@ -7,7 +7,7 @@ use std::future::Future; pub struct Executor(tokio::runtime::Runtime); #[cfg(feature = "tokio")] -impl iced_native::Executor for Executor { +impl iced::Executor for Executor { fn new() -> Result { // Current thread executor requires calling `block_on` to actually run // futures. Main thread is busy with things other than running futures, diff --git a/src/font.rs b/src/font.rs index e3f96983..aed48d59 100644 --- a/src/font.rs +++ b/src/font.rs @@ -3,17 +3,22 @@ pub use iced::Font; -pub const FONT: Font = Font::External { - name: "Fira Sans Regular", - bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"), -}; +pub const FONT: Font = Font::with_name("Fira Sans Regular"); +// pub const FONT: Font = Font::External { +// name: "Fira Sans Regular", +// bytes: include_bytes!("../res/Fira/FiraSans-Regular.otf"), +// }; -pub const FONT_LIGHT: Font = Font::External { - name: "Fira Sans Light", - bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"), -}; +pub const FONT_LIGHT: Font = Font::with_name("Fira Sans Light"); -pub const FONT_SEMIBOLD: Font = Font::External { - name: "Fira Sans SemiBold", - bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"), -}; +// pub const FONT_LIGHT: Font = Font::External { +// name: "Fira Sans Light", +// bytes: include_bytes!("../res/Fira/FiraSans-Light.otf"), +// }; + +pub const FONT_SEMIBOLD: Font = Font::with_name("Fira Sans SemiBold"); + +// pub const FONT_SEMIBOLD: Font = Font::External { +// name: "Fira Sans SemiBold", +// bytes: include_bytes!("../res/Fira/FiraSans-SemiBold.otf"), +// }; diff --git a/src/keyboard_nav.rs b/src/keyboard_nav.rs index 814bcc48..211fe3dd 100644 --- a/src/keyboard_nav.rs +++ b/src/keyboard_nav.rs @@ -3,7 +3,7 @@ use iced::{ keyboard::{self, KeyCode}, mouse, subscription, Command, Event, Subscription, }; -use iced_native::widget::{operation, Id, Operation}; +use iced_core::widget::{operation, Id, Operation}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum Message { diff --git a/src/lib.rs b/src/lib.rs index db470260..f5ddcede 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,6 @@ pub use cosmic_theme; pub use iced; -pub use iced_lazy; -pub use iced_native; #[cfg(feature = "wayland")] pub use iced_sctk; pub use iced_style; diff --git a/src/settings.rs b/src/settings.rs index 7fb35a2f..9f9b20fd 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -27,11 +27,8 @@ pub fn settings() -> iced::Settings { #[must_use] pub fn settings_with_flags(flags: Flags) -> iced::Settings { iced::Settings { - default_font: match font::FONT { - iced::Font::Default => None, - iced::Font::External { bytes, .. } => Some(bytes), - }, - default_text_size: 18, + default_font: font::FONT, + default_text_size: 18.0, ..iced::Settings::with_flags(flags) } } diff --git a/src/theme/mod.rs b/src/theme/mod.rs index 51462d67..452b985a 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -12,11 +12,12 @@ pub use self::segmented_button::SegmentedButton; use cosmic_theme::Component; use cosmic_theme::LayeredTheme; -use iced_core::BorderRadius; +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; @@ -25,8 +26,8 @@ use iced_style::radio; use iced_style::rule; use iced_style::scrollable; use iced_style::slider; +use iced_style::slider::Rail; use iced_style::svg; -use iced_style::text; use iced_style::text_input; use iced_style::toggler; @@ -218,8 +219,8 @@ impl button::StyleSheet for Theme { let component = style.cosmic(self); button::Appearance { border_radius: match style { - Button::Link => BorderRadius::from(0.0), - _ => BorderRadius::from(24.0), + Button::Link => 0.0, + _ => 24.0, }, background: match style { Button::Link | Button::Text => None, @@ -252,22 +253,23 @@ impl button::StyleSheet for Theme { } } - fn focused(&self, style: &Self::Style) -> button::Appearance { - if let Button::Custom { hover, .. } = style { - return hover(self); - } + // TODO add back + // fn focused(&self, style: &Self::Style) -> button::Appearance { + // if let Button::Custom { hover, .. } = style { + // return hover(self); + // } - let active = self.active(style); - let component = style.cosmic(self); - button::Appearance { - background: match style { - Button::Link => None, - Button::LinkActive => Some(Background::Color(component.divider.into())), - _ => Some(Background::Color(component.hover.into())), - }, - ..active - } - } + // let active = self.active(style); + // let component = style.cosmic(self); + // button::Appearance { + // background: match style { + // Button::Link => None, + // Button::LinkActive => Some(Background::Color(component.divider.into())), + // _ => Some(Background::Color(component.hover.into())), + // }, + // ..active + // } + // } } /* @@ -301,7 +303,7 @@ impl checkbox::StyleSheet for Theme { } else { palette.background.base.into() }), - checkmark_color: palette.accent.on.into(), + icon_color: palette.accent.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -318,7 +320,7 @@ impl checkbox::StyleSheet for Theme { } else { palette.background.base.into() }), - checkmark_color: palette.background.on.into(), + icon_color: palette.background.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: neutral_7.into(), @@ -330,7 +332,7 @@ impl checkbox::StyleSheet for Theme { } else { palette.background.base.into() }), - checkmark_color: palette.success.on.into(), + icon_color: palette.success.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -347,7 +349,7 @@ impl checkbox::StyleSheet for Theme { } else { palette.background.base.into() }), - checkmark_color: palette.destructive.on.into(), + icon_color: palette.destructive.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -374,7 +376,7 @@ impl checkbox::StyleSheet for Theme { } else { neutral_10.into() }), - checkmark_color: palette.accent.on.into(), + icon_color: palette.accent.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -391,7 +393,7 @@ impl checkbox::StyleSheet for Theme { } else { neutral_10.into() }), - checkmark_color: self.current_container().on.into(), + icon_color: self.current_container().on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -408,7 +410,7 @@ impl checkbox::StyleSheet for Theme { } else { neutral_10.into() }), - checkmark_color: palette.success.on.into(), + icon_color: palette.success.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -425,7 +427,7 @@ impl checkbox::StyleSheet for Theme { } else { neutral_10.into() }), - checkmark_color: palette.destructive.on.into(), + icon_color: palette.destructive.on.into(), border_radius: 4.0, border_width: if is_checked { 0.0 } else { 1.0 }, border_color: if is_checked { @@ -538,11 +540,15 @@ impl slider::StyleSheet for Theme { //TODO: no way to set rail thickness slider::Appearance { - rail_colors: ( - cosmic.accent.base.into(), - //TODO: no way to set color before/after slider - Color::TRANSPARENT, - ), + rail: Rail { + colors: ( + cosmic.accent.base.into(), + //TODO: no way to set color before/after slider + Color::TRANSPARENT, + ), + width: 4.0, + }, + handle: slider::Handle { shape: slider::HandleShape::Circle { radius: 10.0 }, color: cosmic.accent.base.into(), @@ -610,7 +616,8 @@ impl pick_list::StyleSheet for Theme { border_radius: 24.0, border_width: 0.0, border_color: Color::TRANSPARENT, - icon_size: 0.7, + // icon_size: 0.7, // TODO: how to replace + handle_color: cosmic.on_bg_color().into(), } } @@ -856,7 +863,11 @@ impl scrollable::StyleSheet for Theme { } } - fn hovered(&self, _style: &Self::Style) -> scrollable::Scrollbar { + fn hovered( + &self, + _style: &Self::Style, + is_mouse_over_scrollbar: bool, + ) -> scrollable::Scrollbar { let theme = self.cosmic(); scrollable::Scrollbar { @@ -948,7 +959,7 @@ pub enum Text { Default, Color(Color), // TODO: Can't use dyn Fn since this must be copy - Custom(fn(&Theme) -> text::Appearance), + Custom(fn(&Theme) -> iced_widget::text::Appearance), } impl From for Text { @@ -957,16 +968,16 @@ impl From for Text { } } -impl text::StyleSheet for Theme { +impl iced_widget::text::StyleSheet for Theme { type Style = Text; - fn appearance(&self, style: Self::Style) -> text::Appearance { + fn appearance(&self, style: Self::Style) -> iced_widget::text::Appearance { match style { - Text::Accent => text::Appearance { + Text::Accent => iced_widget::text::Appearance { color: Some(self.cosmic().accent.base.into()), }, - Text::Default => text::Appearance { color: None }, - Text::Color(c) => text::Appearance { color: Some(c) }, + Text::Default => iced_widget::text::Appearance { color: None }, + Text::Color(c) => iced_widget::text::Appearance { color: Some(c) }, Text::Custom(f) => f(self), } } @@ -995,12 +1006,14 @@ impl text_input::StyleSheet for Theme { border_radius: 8.0, 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_width: 0.0, border_color: Color::TRANSPARENT, + icon_color: self.current_container().on.into(), }, } } @@ -1016,12 +1029,14 @@ impl text_input::StyleSheet for Theme { border_radius: 8.0, 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_width: 0.0, border_color: Color::TRANSPARENT, + icon_color: self.current_container().on.into(), }, } } @@ -1037,12 +1052,14 @@ impl text_input::StyleSheet for Theme { border_radius: 8.0, 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_width: 0.0, border_color: Color::TRANSPARENT, + icon_color: self.current_container().on.into(), }, } } @@ -1065,4 +1082,12 @@ impl text_input::StyleSheet for Theme { palette.accent.base.into() } + + fn disabled_color(&self, style: &Self::Style) -> Color { + todo!() + } + + fn disabled(&self, style: &Self::Style) -> text_input::Appearance { + todo!() + } } diff --git a/src/theme/segmented_button.rs b/src/theme/segmented_button.rs index 1e1f53c3..32123414 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::{Background, BorderRadius}; +use iced_core::{renderer::BorderRadius, Background}; 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::{Background, BorderRadius}; + use iced_core::{renderer::BorderRadius, Background}; 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::{Background, BorderRadius}; + use iced_core::{renderer::BorderRadius, Background}; 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 682c0c25..de9f8371 100644 --- a/src/widget/aspect_ratio.rs +++ b/src/widget/aspect_ratio.rs @@ -1,13 +1,13 @@ use iced::widget::Container; use iced::Size; -use iced_native::alignment; -use iced_native::event::{self, Event}; -use iced_native::layout; -use iced_native::mouse; -use iced_native::overlay; -use iced_native::renderer; -use iced_native::widget::{Operation, Tree}; -use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; +use iced_core::alignment; +use iced_core::event::{self, Event}; +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::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; pub use iced_style::container::{Appearance, StyleSheet}; @@ -27,7 +27,7 @@ where #[allow(missing_debug_implementations)] pub struct AspectRatio<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, { ratio: f32, @@ -36,7 +36,7 @@ where impl<'a, Message, Renderer> AspectRatio<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, { fn constrain_limits(&self, size: Size) -> Size { @@ -55,7 +55,7 @@ where impl<'a, Message, Renderer> AspectRatio<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, { /// Creates an empty [`Container`]. @@ -92,14 +92,14 @@ where /// Sets the maximum width of the [`Container`]. #[must_use] - pub fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: f32) -> Self { self.container = self.container.max_width(max_width); self } /// Sets the maximum height of the [`Container`] in pixels. #[must_use] - pub fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: f32) -> Self { self.container = self.container.max_height(max_height); self } @@ -142,14 +142,14 @@ where impl<'a, Message, Renderer> Widget for AspectRatio<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, { fn children(&self) -> Vec { self.container.children() } - fn diff(&self, tree: &mut Tree) { + fn diff(&mut self, tree: &mut Tree) { self.container.diff(tree); } @@ -169,8 +169,16 @@ where self.container.layout(renderer, &custom_limits) } - fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation) { - self.container.operate(tree, layout, operation); + fn operate( + &self, + tree: &mut Tree, + layout: Layout<'_>, + renderer: &Renderer, + operation: &mut dyn iced_core::widget::Operation< + iced_core::widget::OperationOutputWrapper, + >, + ) { + self.container.operate(tree, layout, renderer, operation); } fn on_event( @@ -228,7 +236,7 @@ where } fn overlay<'b>( - &'b self, + &'b mut self, tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, @@ -241,7 +249,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Message: 'a, - Renderer: 'a + iced_native::Renderer, + Renderer: 'a + iced_core::Renderer, Renderer::Theme: StyleSheet, { fn from(column: AspectRatio<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { diff --git a/src/widget/cosmic_container.rs b/src/widget/cosmic_container.rs index 62e58d85..267eef3c 100644 --- a/src/widget/cosmic_container.rs +++ b/src/widget/cosmic_container.rs @@ -1,13 +1,13 @@ use cosmic_theme::LayeredTheme; use iced::widget::Container; -use iced_native::alignment; -use iced_native::event::{self, Event}; -use iced_native::layout; -use iced_native::mouse; -use iced_native::overlay; -use iced_native::renderer; -use iced_native::widget::{Operation, Tree}; -use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; +use iced_core::alignment; +use iced_core::event::{self, Event}; +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::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; pub use iced_style::container::{Appearance, StyleSheet}; pub fn container<'a, Message: 'static, T>( @@ -25,7 +25,7 @@ where #[allow(missing_debug_implementations)] pub struct LayerContainer<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme, { layer: Option, @@ -34,7 +34,7 @@ where impl<'a, Message, Renderer> LayerContainer<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme, ::Style: std::convert::From, { @@ -83,14 +83,14 @@ where /// Sets the maximum width of the [`LayerContainer`]. #[must_use] - pub fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: f32) -> Self { self.container = self.container.max_width(max_width); self } /// Sets the maximum height of the [`LayerContainer`] in pixels. #[must_use] - pub fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: f32) -> Self { self.container = self.container.max_height(max_height); self } @@ -133,14 +133,14 @@ where impl<'a, Message, Renderer> Widget for LayerContainer<'a, Message, Renderer> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme, { fn children(&self) -> Vec { self.container.children() } - fn diff(&self, tree: &mut Tree) { + fn diff(&mut self, tree: &mut Tree) { self.container.diff(tree); } @@ -156,8 +156,16 @@ where self.container.layout(renderer, limits) } - fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation) { - self.container.operate(tree, layout, operation); + fn operate( + &self, + tree: &mut Tree, + layout: Layout<'_>, + renderer: &Renderer, + operation: &mut dyn iced_core::widget::Operation< + iced_core::widget::OperationOutputWrapper, + >, + ) { + self.container.operate(tree, layout, renderer, operation); } fn on_event( @@ -222,7 +230,7 @@ where } fn overlay<'b>( - &'b self, + &'b mut self, tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, @@ -235,7 +243,7 @@ impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where Message: 'a, - Renderer: 'a + iced_native::Renderer, + Renderer: 'a + iced_core::Renderer, Renderer::Theme: StyleSheet + Clone + cosmic_theme::LayeredTheme, { fn from(column: LayerContainer<'a, Message, Renderer>) -> Element<'a, Message, Renderer> { diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index eadebeab..e0623ab3 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -74,12 +74,12 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> { }); let mut widget = widget::row(packed) - .height(Length::Units(50)) + .height(Length::Fixed(50.0)) .padding(8) .spacing(8) .apply(widget::container) .center_y() - .apply(widget::mouse_listener); + .apply(widget::mouse_area); if let Some(message) = self.on_drag.clone() { widget = widget.on_press(message); diff --git a/src/widget/icon.rs b/src/widget/icon.rs index 3810be73..f85b38d0 100644 --- a/src/widget/icon.rs +++ b/src/widget/icon.rs @@ -90,7 +90,13 @@ impl<'a> IconSource<'a> { } /// Get a handle to a raster image from memory. - pub fn raster_from_memory(bytes: impl Into>) -> Self { + pub fn raster_from_memory( + bytes: impl Into> + + std::convert::AsRef<[u8]> + + std::marker::Send + + std::marker::Sync + + 'static, + ) -> Self { IconSource::Handle(Handle::Image(image::Handle::from_memory(bytes))) } @@ -98,7 +104,11 @@ impl<'a> IconSource<'a> { pub fn raster_from_pixels( width: u32, height: u32, - pixels: impl Into>, + pixels: impl Into> + + std::convert::AsRef<[u8]> + + std::marker::Send + + std::marker::Sync + + 'static, ) -> Self { IconSource::Handle(Handle::Image(image::Handle::from_pixels( width, height, pixels, @@ -165,7 +175,7 @@ impl From for IconSource<'static> { } /// A lazily-generated icon. -#[derive(Hash, Setters)] +#[derive(Setters)] pub struct Icon<'a> { #[setters(skip)] source: IconSource<'a>, @@ -181,6 +191,18 @@ pub struct Icon<'a> { force_svg: bool, } +// TODO what to do here +impl Hash for Icon<'_> { + fn hash(&self, state: &mut H) { + self.source.hash(state); + self.theme.hash(state); + self.style.hash(state); + self.size.hash(state); + self.content_fit.hash(state); + self.force_svg.hash(state); + } +} + /// A lazily-generated icon. #[must_use] pub fn icon<'a>(source: impl Into>, size: u16) -> Icon<'a> { @@ -199,8 +221,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::Units(self.size))) - .height(self.height.unwrap_or(Length::Units(self.size))) + .width(self.width.unwrap_or(Length::Fixed(self.size as f32))) + .height(self.height.unwrap_or(Length::Fixed(self.size as f32))) .content_fit(self.content_fit) .into() } @@ -208,8 +230,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::Units(self.size))) - .height(self.height.unwrap_or(Length::Units(self.size))) + .width(self.width.unwrap_or(Length::Fixed(self.size as f32))) + .height(self.height.unwrap_or(Length::Fixed(self.size as f32))) .content_fit(self.content_fit) .into() } @@ -228,7 +250,7 @@ impl<'a> Icon<'a> { let mut source = IconSource::Name(Cow::Borrowed("")); std::mem::swap(&mut source, &mut self.source); - iced_lazy::lazy(hash, move || -> Element { + iced::widget::lazy(hash, move |_| -> Element { match source.load(self.size, self.theme.as_deref(), self.force_svg) { Handle::Svg(handle) => self.svg_element(handle), Handle::Image(handle) => self.raster_element(handle), diff --git a/src/widget/rectangle_tracker/mod.rs b/src/widget/rectangle_tracker/mod.rs index e30d4a85..1d5b59a6 100644 --- a/src/widget/rectangle_tracker/mod.rs +++ b/src/widget/rectangle_tracker/mod.rs @@ -4,14 +4,14 @@ use iced::futures::channel::mpsc::UnboundedSender; use iced::widget::Container; pub use subscription::*; -use iced_native::alignment; -use iced_native::event::{self, Event}; -use iced_native::layout; -use iced_native::mouse; -use iced_native::overlay; -use iced_native::renderer; -use iced_native::widget::{Operation, Tree}; -use iced_native::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; +use iced_core::alignment; +use iced_core::event::{self, Event}; +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::{Clipboard, Element, Layout, Length, Padding, Point, Rectangle, Shell, Widget}; use std::{fmt::Debug, hash::Hash}; pub use iced_style::container::{Appearance, StyleSheet}; @@ -44,7 +44,7 @@ where #[allow(missing_debug_implementations)] pub struct RectangleTrackingContainer<'a, Message, Renderer, I> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, { tx: UnboundedSender<(I, Rectangle)>, @@ -54,7 +54,7 @@ where impl<'a, Message, Renderer, I> RectangleTrackingContainer<'a, Message, Renderer, I> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, I: 'a + Hash + Copy + Send + Sync + Debug, { @@ -93,14 +93,14 @@ where /// Sets the maximum width of the [`Container`]. #[must_use] - pub fn max_width(mut self, max_width: u32) -> Self { + pub fn max_width(mut self, max_width: f32) -> Self { self.container = self.container.max_width(max_width); self } /// Sets the maximum height of the [`Container`] in pixels. #[must_use] - pub fn max_height(mut self, max_height: u32) -> Self { + pub fn max_height(mut self, max_height: f32) -> Self { self.container = self.container.max_height(max_height); self } @@ -144,7 +144,7 @@ where impl<'a, Message, Renderer, I> Widget for RectangleTrackingContainer<'a, Message, Renderer, I> where - Renderer: iced_native::Renderer, + Renderer: iced_core::Renderer, Renderer::Theme: StyleSheet, I: 'a + Hash + Copy + Send + Sync + Debug, { @@ -152,7 +152,7 @@ where self.container.children() } - fn diff(&self, tree: &mut Tree) { + fn diff(&mut self, tree: &mut Tree) { self.container.diff(tree); } @@ -168,8 +168,16 @@ where self.container.layout(renderer, limits) } - fn operate(&self, tree: &mut Tree, layout: Layout<'_>, operation: &mut dyn Operation) { - self.container.operate(tree, layout, operation); + fn operate( + &self, + tree: &mut Tree, + layout: Layout<'_>, + renderer: &Renderer, + operation: &mut dyn iced_core::widget::Operation< + iced_core::widget::OperationOutputWrapper, + >, + ) { + self.container.operate(tree, layout, renderer, operation); } fn on_event( @@ -229,7 +237,7 @@ where } fn overlay<'b>( - &'b self, + &'b mut self, tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, @@ -242,7 +250,7 @@ impl<'a, Message, Renderer, I> From where Message: 'a, - Renderer: 'a + iced_native::Renderer, + Renderer: 'a + iced_core::Renderer, Renderer::Theme: StyleSheet, I: 'a + Hash + Copy + Send + Sync + Debug, { diff --git a/src/widget/rectangle_tracker/subscription.rs b/src/widget/rectangle_tracker/subscription.rs index 80e6ff3c..b0ece685 100644 --- a/src/widget/rectangle_tracker/subscription.rs +++ b/src/widget/rectangle_tracker/subscription.rs @@ -14,7 +14,7 @@ pub fn rectangle_tracker_subscription< R: 'static + Hash + Copy + Send + Sync + Debug + Eq, >( id: I, -) -> iced::Subscription<(I, RectangleUpdate)> { +) -> iced::Subscription)>> { subscription::unfold(id, State::Ready, move |state| start_listening(id, state)) } diff --git a/src/widget/scrollable.rs b/src/widget/scrollable.rs index 26f75d60..202d09e2 100644 --- a/src/widget/scrollable.rs +++ b/src/widget/scrollable.rs @@ -8,6 +8,6 @@ pub fn scrollable<'a, Message>( element: impl Into>, ) -> widget::Scrollable<'a, Message, Renderer> { widget::scrollable(element) - .scrollbar_width(8) - .scroller_width(8) + // .scrollbar_width(8) TODO add these back + // .scroller_width(8) } diff --git a/src/widget/search/field.rs b/src/widget/search/field.rs index 89aa61d0..8a236365 100644 --- a/src/widget/search/field.rs +++ b/src/widget/search/field.rs @@ -11,7 +11,7 @@ use apply::Apply; /// A search field for COSMIC applications. pub fn field( - id: iced::widget::text_input::Id, + id: iced_core::id::Id, phrase: &str, on_change: fn(String) -> Message, on_clear: Message, @@ -29,7 +29,7 @@ pub fn field( /// A search field for COSMIC applications. #[must_use] pub struct Field<'a, Message: 'static + Clone> { - id: iced::widget::text_input::Id, + id: iced_core::id::Id, phrase: &'a str, on_change: fn(String) -> Message, on_clear: Message, @@ -38,7 +38,8 @@ pub struct Field<'a, Message: 'static + Clone> { impl<'a, Message: 'static + Clone> Field<'a, Message> { pub fn into_element(mut self) -> crate::Element<'a, Message> { - let mut input = iced::widget::text_input("", self.phrase, self.on_change) + let mut input = iced::widget::text_input("", self.phrase) + .on_input(self.on_change) .style(crate::theme::TextInput::Search) .width(Length::Fill) .id(self.id); @@ -52,8 +53,8 @@ impl<'a, Message: 'static + Clone> Field<'a, Message> { input, clear_button().on_press(self.on_clear) ) - .width(Length::Units(300)) - .height(Length::Units(38)) + .width(Length::Fixed(300.0)) + .height(Length::Fixed(38.0)) .padding([0, 16]) .spacing(8) .align_items(iced::Alignment::Center) diff --git a/src/widget/search/model.rs b/src/widget/search/model.rs index 27cafcaa..0b099ece 100644 --- a/src/widget/search/model.rs +++ b/src/widget/search/model.rs @@ -6,7 +6,7 @@ use crate::iced; /// A model for managing the state of a search widget. pub struct Model { - pub input_id: iced::widget::text_input::Id, + pub input_id: iced_core::id::Id, pub phrase: String, pub state: State, } @@ -29,7 +29,7 @@ impl Model { impl Default for Model { fn default() -> Self { Self { - input_id: iced::widget::text_input::Id::unique(), + input_id: iced_core::id::Id::unique(), phrase: String::with_capacity(32), state: State::Inactive, } diff --git a/src/widget/segmented_button/horizontal.rs b/src/widget/segmented_button/horizontal.rs index 8fff084b..008e848d 100644 --- a/src/widget/segmented_button/horizontal.rs +++ b/src/widget/segmented_button/horizontal.rs @@ -8,7 +8,7 @@ use super::style::StyleSheet; use super::widget::{SegmentedButton, SegmentedVariant}; use iced::{Length, Rectangle, Size}; -use iced_native::layout; +use iced_core::layout; /// Horizontal [`SegmentedButton`]. pub type HorizontalSegmentedButton<'a, SelectionMode, Message, Renderer> = @@ -25,10 +25,10 @@ pub fn horizontal( model: &Model, ) -> SegmentedButton where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Model: Selectable, { @@ -38,10 +38,10 @@ where impl<'a, SelectionMode, Message, Renderer> SegmentedVariant for SegmentedButton<'a, Horizontal, SelectionMode, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Model: Selectable, SelectionMode: Default, @@ -49,8 +49,8 @@ where type Renderer = Renderer; fn variant_appearance( - theme: &::Theme, - style: &<::Theme as StyleSheet>::Style, + theme: &::Theme, + style: &<::Theme as StyleSheet>::Style, ) -> super::Appearance { theme.horizontal(style) } @@ -85,7 +85,7 @@ where } let size = limits - .height(Length::Units(height as u16)) + .height(Length::Fixed(height)) .resolve(Size::new(width, height)); layout::Node::new(size) diff --git a/src/widget/segmented_button/style.rs b/src/widget/segmented_button/style.rs index 5cc2e1a7..ea91b785 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::{Background, BorderRadius, Color}; +use iced_core::{renderer::BorderRadius, Background, Color}; /// Appearance of the segmented button. #[derive(Default, Clone, Copy)] diff --git a/src/widget/segmented_button/vertical.rs b/src/widget/segmented_button/vertical.rs index 04f3ccc0..3a65409b 100644 --- a/src/widget/segmented_button/vertical.rs +++ b/src/widget/segmented_button/vertical.rs @@ -8,7 +8,7 @@ use super::style::StyleSheet; use super::widget::{SegmentedButton, SegmentedVariant}; use iced::{Length, Rectangle, Size}; -use iced_native::layout; +use iced_core::layout; /// A type marker defining the vertical variant of a [`SegmentedButton`]. pub struct Vertical; @@ -25,10 +25,10 @@ pub fn vertical( model: &Model, ) -> SegmentedButton where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Model: Selectable, SelectionMode: Default, @@ -39,10 +39,10 @@ where impl<'a, SelectionMode, Message, Renderer> SegmentedVariant for SegmentedButton<'a, Vertical, SelectionMode, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Model: Selectable, SelectionMode: Default, @@ -50,8 +50,8 @@ where type Renderer = Renderer; fn variant_appearance( - theme: &::Theme, - style: &<::Theme as StyleSheet>::Style, + theme: &::Theme, + style: &<::Theme as StyleSheet>::Style, ) -> super::Appearance { theme.vertical(style) } @@ -86,7 +86,7 @@ where } let size = limits - .height(Length::Units(height as u16)) + .height(Length::Fixed(height)) .resolve(Size::new(width, height)); layout::Node::new(size) diff --git a/src/widget/segmented_button/widget.rs b/src/widget/segmented_button/widget.rs index e4801574..51789c54 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::BorderRadius; -use iced_native::widget::{self, operation, tree, Operation}; -use iced_native::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget}; +use iced_core::renderer::BorderRadius; +use iced_core::widget::{self, operation, tree, Operation}; +use iced_core::{layout, renderer, widget::Tree, Clipboard, Layout, Shell, Widget}; use std::marker::PhantomData; /// State that is maintained by each individual widget. @@ -46,15 +46,15 @@ impl operation::Focusable for LocalState { /// Isolates variant-specific behaviors from [`SegmentedButton`]. pub trait SegmentedVariant { - type Renderer: iced_native::Renderer; + type Renderer: iced_core::Renderer; /// Get the appearance for this variant of the widget. fn variant_appearance( - theme: &::Theme, - style: &<::Theme as StyleSheet>::Style, + theme: &::Theme, + style: &<::Theme as StyleSheet>::Style, ) -> super::Appearance where - ::Theme: StyleSheet; + ::Theme: StyleSheet; /// Calculates the bounds for the given button by its position. fn variant_button_bounds(&self, bounds: Rectangle, position: usize) -> Rectangle; @@ -67,10 +67,10 @@ pub trait SegmentedVariant { #[derive(Setters)] pub struct SegmentedButton<'a, Variant, SelectionMode, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Model: Selectable, SelectionMode: Default, @@ -91,13 +91,13 @@ where /// Spacing between icon and text in button. pub(super) button_spacing: u16, /// Desired font for active tabs. - pub(super) font_active: Renderer::Font, + pub(super) font_active: Option, /// Desired font for hovered tabs. - pub(super) font_hovered: Renderer::Font, + pub(super) font_hovered: Option, /// Desired font for inactive tabs. - pub(super) font_inactive: Renderer::Font, + pub(super) font_inactive: Option, /// Size of the font. - pub(super) font_size: u16, + pub(super) font_size: f32, /// Size of icon pub(super) icon_size: u16, /// Desired width of the widget. @@ -122,10 +122,10 @@ where impl<'a, Variant, SelectionMode, Message, Renderer> SegmentedButton<'a, Variant, SelectionMode, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Self: SegmentedVariant, Model: Selectable, @@ -141,10 +141,10 @@ where button_padding: [4, 4, 4, 4], button_height: 32, button_spacing: 4, - font_active: Renderer::Font::default(), - font_hovered: Renderer::Font::default(), - font_inactive: Renderer::Font::default(), - font_size: 17, + font_active: None, + font_hovered: None, + font_inactive: None, + font_size: 17.0, icon_size: 16, height: Length::Shrink, width: Length::Fill, @@ -212,6 +212,7 @@ where pub(super) fn max_button_dimensions(&self, renderer: &Renderer, bounds: Size) -> (f32, f32) { let mut width = 0.0f32; let mut height = 0.0f32; + let font = renderer.default_font(); for key in self.model.order.iter().copied() { let mut button_width = 0.0f32; @@ -219,7 +220,7 @@ where // Add text to measurement if text was given. if let Some(text) = self.model.text(key) { - let (w, h) = renderer.measure(text, self.font_size, Default::default(), bounds); + let (w, h) = renderer.measure(text, self.font_size, font, bounds); button_width = w; button_height = h; @@ -253,10 +254,10 @@ where impl<'a, Variant, SelectionMode, Message, Renderer> Widget for SegmentedButton<'a, Variant, SelectionMode, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer, + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer, Renderer::Theme: StyleSheet, Self: SegmentedVariant, Model: Selectable, @@ -379,7 +380,10 @@ where &self, tree: &mut Tree, _layout: Layout<'_>, - operation: &mut dyn Operation, + renderer: &Renderer, + operation: &mut dyn iced_core::widget::Operation< + iced_core::widget::OperationOutputWrapper, + >, ) { let state = tree.state.downcast_mut::(); operation.focusable(state, self.id.as_ref().map(|id| &id.0)); @@ -392,7 +396,7 @@ where cursor_position: iced::Point, _viewport: &iced::Rectangle, _renderer: &Renderer, - ) -> iced_native::mouse::Interaction { + ) -> iced_core::mouse::Interaction { let bounds = layout.bounds(); if bounds.contains(cursor_position) { @@ -402,15 +406,15 @@ where .contains(cursor_position) { return if self.model.items[key].enabled { - iced_native::mouse::Interaction::Pointer + iced_core::mouse::Interaction::Pointer } else { - iced_native::mouse::Interaction::Idle + iced_core::mouse::Interaction::Idle }; } } } - iced_native::mouse::Interaction::Idle + iced_core::mouse::Interaction::Idle } #[allow(clippy::too_many_lines)] @@ -418,7 +422,7 @@ where &self, tree: &Tree, renderer: &mut Renderer, - theme: &::Theme, + theme: &::Theme, _style: &renderer::Style, layout: Layout<'_>, _cursor_position: iced::Point, @@ -458,6 +462,7 @@ where } else { (appearance.inactive, &self.font_inactive) }; + let font = font.unwrap_or_else(|| renderer.default_font()); let button_appearance = if nth == 0 { status_appearance.first @@ -536,7 +541,7 @@ where unimplemented!() } icon::Handle::Svg(handle) => { - iced_native::svg::Renderer::draw(renderer, handle, icon_color, icon_bounds); + iced_core::svg::Renderer::draw(renderer, handle, icon_color, icon_bounds); } } @@ -550,7 +555,7 @@ where bounds.y = y; // Draw the text in this button. - renderer.fill_text(iced_native::text::Text { + renderer.fill_text(iced_core::text::Text { content: text, size: f32::from(self.font_size), bounds, @@ -575,7 +580,7 @@ where unimplemented!() } icon::Handle::Svg(handle) => { - iced_native::svg::Renderer::draw( + iced_core::svg::Renderer::draw( renderer, handle, Some(status_appearance.text_color), @@ -588,11 +593,11 @@ where } fn overlay<'b>( - &'b self, + &'b mut self, _tree: &'b mut Tree, - _layout: iced_native::Layout<'_>, + _layout: iced_core::Layout<'_>, _renderer: &Renderer, - ) -> Option> { + ) -> Option> { None } } @@ -601,10 +606,10 @@ impl<'a, Variant, SelectionMode, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: iced_native::Renderer - + iced_native::text::Renderer - + iced_native::image::Renderer - + iced_native::svg::Renderer + Renderer: iced_core::Renderer + + iced_core::text::Renderer + + iced_core::image::Renderer + + iced_core::svg::Renderer + 'a, Renderer::Theme: StyleSheet, SegmentedButton<'a, Variant, SelectionMode, Message, Renderer>: diff --git a/src/widget/segmented_selection.rs b/src/widget/segmented_selection.rs index 0b6a2059..bc2320e5 100644 --- a/src/widget/segmented_selection.rs +++ b/src/widget/segmented_selection.rs @@ -25,7 +25,7 @@ where .button_padding([16, 0, 16, 0]) .button_height(32) .style(crate::theme::SegmentedButton::Selection) - .font_active(crate::font::FONT_SEMIBOLD) + .font_active(Some(crate::font::FONT_SEMIBOLD)) } /// A selection of multiple choices appearing as a conjoined button. @@ -45,5 +45,5 @@ where .button_padding([16, 0, 16, 0]) .button_height(32) .style(crate::theme::SegmentedButton::Selection) - .font_active(crate::font::FONT_SEMIBOLD) + .font_active(Some(crate::font::FONT_SEMIBOLD)) } diff --git a/src/widget/spin_button/mod.rs b/src/widget/spin_button/mod.rs index d994ee88..adde768c 100644 --- a/src/widget/spin_button/mod.rs +++ b/src/widget/spin_button/mod.rs @@ -76,13 +76,13 @@ impl<'a, Message: 'static> SpinButton<'a, Message> { .on_press(model::Message::Increment), ] .width(Length::Fill) - .height(Length::Units(32)) + .height(Length::Fixed(32.0)) .align_items(Alignment::Center), ) .padding([4, 4]) .align_y(Vertical::Center) - .width(Length::Units(95)) - .height(Length::Units(32)) + .width(Length::Fixed(95.0)) + .height(Length::Fixed(32.0)) .style(theme::Container::custom(container_style)) .apply(Element::from) .map(on_change) diff --git a/src/widget/text.rs b/src/widget/text.rs index c868f9a6..d2357081 100644 --- a/src/widget/text.rs +++ b/src/widget/text.rs @@ -7,7 +7,7 @@ pub use iced::widget::Text; /// [`Text`]: widget::Text pub fn text<'a, Renderer>(text: impl Into>) -> Text<'a, Renderer> where - Renderer: iced_native::text::Renderer, + Renderer: iced_core::text::Renderer, Renderer::Theme: iced::widget::text::StyleSheet, { Text::new(text) diff --git a/src/widget/toggler.rs b/src/widget/toggler.rs index 004f81da..12e9d1a1 100644 --- a/src/widget/toggler.rs +++ b/src/widget/toggler.rs @@ -9,7 +9,7 @@ pub fn toggler<'a, Message>( is_checked: bool, f: impl Fn(bool) -> Message + 'a, ) -> widget::Toggler<'a, Message, Renderer> { - widget::Toggler::new(is_checked, label, f) + widget::Toggler::new(label, is_checked, f) .size(24) .spacing(12) .width(Length::Shrink) diff --git a/src/widget/view_switcher.rs b/src/widget/view_switcher.rs index 7ff711c7..85163e2f 100644 --- a/src/widget/view_switcher.rs +++ b/src/widget/view_switcher.rs @@ -25,7 +25,7 @@ where .button_padding([16, 0, 16, 0]) .button_height(48) .style(crate::theme::SegmentedButton::ViewSwitcher) - .font_active(crate::font::FONT_SEMIBOLD) + .font_active(Some(crate::font::FONT_SEMIBOLD)) } /// A collection of tabs for developing a tabbed interface. @@ -45,5 +45,5 @@ where .button_padding([16, 0, 16, 0]) .button_height(48) .style(crate::theme::SegmentedButton::ViewSwitcher) - .font_active(crate::font::FONT_SEMIBOLD) + .font_active(Some(crate::font::FONT_SEMIBOLD)) }