From 5443b95f0151722d0e7c4ad5fe37ed4d43d1cd10 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 30 Nov 2023 14:28:28 -0500 Subject: [PATCH 1/4] chore: update to 0.12 --- Cargo.toml | 17 ++++--- examples/counter/Cargo.toml | 1 - examples/counter/src/main.rs | 2 +- examples/pokedex/Cargo.toml | 2 +- examples/pokedex/src/main.rs | 4 +- examples/pong/Cargo.toml | 3 -- examples/pong/src/layer.rs | 25 +++++++-- examples/pong/src/main.rs | 10 ++-- examples/pong/src/theme.rs | 3 ++ examples/stopwatch/Cargo.toml | 2 +- src/reexports/iced.rs | 1 + src/reexports/libcosmic.rs | 1 + src/reexports/mod.rs | 7 +-- src/widget/button.rs | 13 ++++- src/widget/cards.rs | 34 +++++++++---- src/widget/container.rs | 13 ++++- src/widget/cosmic_button.rs | 13 ++++- src/widget/cosmic_container.rs | 13 ++++- src/widget/cosmic_toggler.rs | 93 ++++++++++++++++++---------------- src/widget/toggler.rs | 82 ++++++++++++++++-------------- 20 files changed, 215 insertions(+), 124 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e50a444..5d09a90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cosmic-time" -version = "0.3.0" +version = "0.4.0" edition = "2021" description = "An animation Crate for Iced and Cosmic DE" authors = ["Brock Szuszczewicz "] @@ -24,13 +24,14 @@ members = [ ] [dependencies] -iced = { version = "0.10.0", features = [ "tokio" ], optional = true } -iced_runtime = { version = "0.1.1", optional = true } -iced_widget = { version = "0.1.3", optional = true } -iced_futures = { version = "0.7.0", optional = true } -iced_core = { version = "0.10.0", optional = true } -iced_style = { version = "0.9.0", optional = true } -libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], optional = true } +iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["tokio"], optional = true } +# iced = { version = "0.12.0", features = [ "tokio" ], optional = true } +iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +iced_widget = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +iced_futures = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +iced_core = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +iced_style = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], branch = "update-0.12", optional = true } # libcosmic = { path = "../libcosmic", optional = true, features = [ "tokio" ]} once_cell = { version = "1.18.0", optional = true } float-cmp = "0.9" diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 73c4073..bde5aca 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -6,5 +6,4 @@ edition = "2021" publish = false [dependencies] -iced = "0.10.0" cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs index 171979f..fd6a542 100644 --- a/examples/counter/src/main.rs +++ b/examples/counter/src/main.rs @@ -5,7 +5,7 @@ use iced::{ Alignment, Application, Command, Element, Event, Length, Settings, Subscription, Theme, }; -use cosmic_time::{self, anim, chain, id, once_cell::sync::Lazy, Timeline}; +use cosmic_time::{self, anim, chain, id, once_cell::sync::Lazy, reexports::iced, Timeline}; static CONTAINER: Lazy = Lazy::new(id::Container::unique); diff --git a/examples/pokedex/Cargo.toml b/examples/pokedex/Cargo.toml index 430f692..41c7723 100644 --- a/examples/pokedex/Cargo.toml +++ b/examples/pokedex/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -iced = { version = "0.10.0", features = ["image", "debug", "tokio"] } +iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["image", "debug", "tokio"] } cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } serde_json = "1.0" diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 76f1b7b..7f2dd1a 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -6,8 +6,8 @@ use iced::{ }; use cosmic_time::{ - self, anim, chain, id, once_cell::sync::Lazy, Back, Bounce, Circular, Ease, Elastic, - Exponential, Linear, Quadratic, Quartic, Quintic, Sinusoidal, Timeline, + self, anim, chain, id, once_cell::sync::Lazy, reexports::iced, Back, Bounce, Circular, Ease, + Elastic, Exponential, Linear, Quadratic, Quartic, Quintic, Sinusoidal, Timeline, }; static SPACE: Lazy = Lazy::new(id::Space::unique); diff --git a/examples/pong/Cargo.toml b/examples/pong/Cargo.toml index ed5db27..c94e9aa 100644 --- a/examples/pong/Cargo.toml +++ b/examples/pong/Cargo.toml @@ -6,8 +6,5 @@ edition = "2021" publish = false [dependencies] -iced = "0.10.0" -iced_core = "0.10.0" -iced_runtime = "0.1.1" cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } rand = "0.8.5" diff --git a/examples/pong/src/layer.rs b/examples/pong/src/layer.rs index f8f385e..30a4e0a 100644 --- a/examples/pong/src/layer.rs +++ b/examples/pong/src/layer.rs @@ -5,6 +5,7 @@ * */ +use cosmic_time::reexports::iced_core::{self, Vector}; use iced_core::widget::{self, Tree}; use iced_core::{ event, layout, mouse, overlay, renderer, Clipboard, Color, Element, Event, Layout, Length, @@ -51,8 +52,15 @@ where self.base.as_widget().height() } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { - self.base.as_widget().layout(renderer, limits) + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { + self.base + .as_widget() + .layout(&mut tree.children[0], renderer, limits) } fn on_event( @@ -157,12 +165,21 @@ where Renderer: iced_core::Renderer, Message: Clone, { - fn layout(&self, renderer: &Renderer, _bounds: Size, position: Point) -> layout::Node { + fn layout( + &mut self, + renderer: &Renderer, + _bounds: Size, + position: Point, + _translation: Vector, + ) -> layout::Node { let limits = layout::Limits::new(Size::ZERO, self.size) .width(Length::Fill) .height(Length::Fill); - let child = self.content.as_widget().layout(renderer, &limits); + let child = self + .content + .as_widget() + .layout(&mut self.tree.children[0], renderer, &limits); let mut node = layout::Node::with_children(self.size, vec![child]); node.move_to(position); diff --git a/examples/pong/src/main.rs b/examples/pong/src/main.rs index 104aa27..9f13fc5 100644 --- a/examples/pong/src/main.rs +++ b/examples/pong/src/main.rs @@ -1,12 +1,16 @@ +use cosmic_time::reexports::iced_futures::event::listen_raw; use iced::event; use iced::keyboard::{self, KeyCode}; -use iced::subscription; + use iced::widget::{column, container, row, Space}; use iced::{executor, Application, Command, Event, Length, Settings, Subscription}; use iced_core::window; use cosmic_time::{ - self, anim, chain, id, once_cell::sync::Lazy, Duration, Instant, Speed, Timeline, + self, anim, chain, id, + once_cell::sync::Lazy, + reexports::{iced, iced_core}, + Duration, Instant, Speed, Timeline, }; use rand::prelude::*; @@ -90,7 +94,7 @@ impl Application for Pong { fn subscription(&self) -> Subscription { Subscription::batch(vec![ self.timeline.as_subscription::().map(Message::Tick), - subscription::events_with(|event, status| match (event, status) { + listen_raw(|event, status| match (event, status) { ( Event::Keyboard(keyboard::Event::KeyPressed { key_code, diff --git a/examples/pong/src/theme.rs b/examples/pong/src/theme.rs index 1604643..5e6afa9 100644 --- a/examples/pong/src/theme.rs +++ b/examples/pong/src/theme.rs @@ -1,3 +1,4 @@ +use cosmic_time::reexports::iced; use iced::widget::{container, text}; use iced::{application, color}; @@ -57,6 +58,8 @@ impl container::StyleSheet for Theme { pub mod widget { #![allow(dead_code)] + use cosmic_time::reexports::iced; + use crate::theme::Theme; pub type Renderer = iced::Renderer; diff --git a/examples/stopwatch/Cargo.toml b/examples/stopwatch/Cargo.toml index df890a2..862e551 100644 --- a/examples/stopwatch/Cargo.toml +++ b/examples/stopwatch/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" publish = false [dependencies] -iced = { version = "0.10.0", features = ["smol"] } +iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["smol"] } cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } diff --git a/src/reexports/iced.rs b/src/reexports/iced.rs index 93e0672..5f24144 100644 --- a/src/reexports/iced.rs +++ b/src/reexports/iced.rs @@ -1,3 +1,4 @@ +pub use iced; pub use iced_core; pub use iced_futures; pub use iced_runtime; diff --git a/src/reexports/libcosmic.rs b/src/reexports/libcosmic.rs index 5e71680..1db8add 100644 --- a/src/reexports/libcosmic.rs +++ b/src/reexports/libcosmic.rs @@ -1,3 +1,4 @@ +pub use cosmic::iced; pub use cosmic::iced_core; pub use cosmic::iced_futures; pub use cosmic::iced_runtime; diff --git a/src/reexports/mod.rs b/src/reexports/mod.rs index 2411751..b267871 100644 --- a/src/reexports/mod.rs +++ b/src/reexports/mod.rs @@ -3,9 +3,10 @@ #[cfg(feature = "libcosmic")] mod libcosmic; #[cfg(feature = "libcosmic")] -pub use self::libcosmic::{iced_core, iced_futures, iced_runtime, iced_style, iced_widget}; +pub use self::libcosmic::{iced, iced_core, iced_futures, iced_runtime, iced_style, iced_widget}; #[cfg(feature = "iced")] -mod iced; +#[path = "iced.rs"] +mod _iced; #[cfg(feature = "iced")] -pub use self::iced::{iced_core, iced_futures, iced_runtime, iced_style, iced_widget}; +pub use self::_iced::{iced, iced_core, iced_futures, iced_runtime, iced_style, iced_widget}; diff --git a/src/widget/button.rs b/src/widget/button.rs index 04fad5c..7016f87 100644 --- a/src/widget/button.rs +++ b/src/widget/button.rs @@ -126,14 +126,23 @@ where self.height } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { layout( renderer, limits, self.width, self.height, self.padding, - |renderer, limits| self.content.as_widget().layout(renderer, limits), + |renderer, limits| { + self.content + .as_widget() + .layout(&mut tree.children[0], renderer, limits) + }, ) } diff --git a/src/widget/cards.rs b/src/widget/cards.rs index 57df807..d11ecea 100644 --- a/src/widget/cards.rs +++ b/src/widget/cards.rs @@ -250,12 +250,13 @@ where #[allow(clippy::too_many_lines)] fn layout( &self, + tree: &mut Tree, renderer: &Renderer, limits: &iced_core::layout::Limits, ) -> iced_core::layout::Node { let mut children = Vec::with_capacity(1 + self.elements.len()); let mut size = Size::new(0.0, 0.0); - + let tree_children = &mut tree.children; if self.elements.is_empty() { return Node::with_children(size, children); } @@ -266,13 +267,17 @@ where let show_less = &self.show_less_button; let clear_all = &self.clear_all_button; - let show_less_node = show_less.as_widget().layout(renderer, limits); - let clear_all_node = clear_all.as_widget().layout(renderer, limits); + let show_less_node = show_less + .as_widget() + .layout(&mut tree_children[0], renderer, limits); + let clear_all_node = clear_all + .as_widget() + .layout(&mut tree_children[1], renderer, limits); size.width += show_less_node.size().width + clear_all_node.size().width; let custom_limits = limits.min_width(size.width); - for c in &self.elements { - let card_node = c.as_widget().layout(renderer, &custom_limits); + for (c, t) in self.elements.iter().zip(tree_children[2..].iter_mut()) { + let card_node = c.as_widget().layout(t, renderer, &custom_limits); size.width = size.width.max(card_node.size().width); } @@ -280,8 +285,14 @@ where let show_less = &self.show_less_button; let clear_all = &self.clear_all_button; - let show_less_node = show_less.as_widget().layout(renderer, limits); - let mut clear_all_node = clear_all.as_widget().layout(renderer, limits); + let show_less_node = + show_less + .as_widget() + .layout(&mut tree_children[0], renderer, limits); + let mut clear_all_node = + clear_all + .as_widget() + .layout(&mut tree_children[1], renderer, limits); let clear_all_node_size = clear_all_node.size(); clear_all_node = @@ -300,11 +311,16 @@ where .max_width(size.width) .width(Length::Fixed(size.width)); - for (i, c) in self.elements.iter().enumerate() { + for (i, (c, t)) in self + .elements + .iter() + .zip(tree_children[2..].iter_mut()) + .enumerate() + { let progress = self.percent * size.height; let card_node = c .as_widget() - .layout(renderer, &custom_limits) + .layout(t, renderer, &custom_limits) .translate(Vector::new(0.0, progress)); size.height = size.height.max(progress + card_node.size().height); diff --git a/src/widget/container.rs b/src/widget/container.rs index 678fe5d..b29bf28 100644 --- a/src/widget/container.rs +++ b/src/widget/container.rs @@ -166,7 +166,12 @@ where self.height } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { layout( renderer, limits, @@ -177,7 +182,11 @@ where self.padding, self.horizontal_alignment, self.vertical_alignment, - |renderer, limits| self.content.as_widget().layout(renderer, limits), + |renderer, limits| { + self.content + .as_widget() + .layout(&mut tree.children[0], renderer, limits) + }, ) } diff --git a/src/widget/cosmic_button.rs b/src/widget/cosmic_button.rs index f487260..788cbf4 100644 --- a/src/widget/cosmic_button.rs +++ b/src/widget/cosmic_button.rs @@ -179,14 +179,23 @@ where self.height } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { layout( renderer, limits, self.width, self.height, self.padding, - |renderer, limits| self.content.as_widget().layout(renderer, limits), + |renderer, limits| { + self.content + .as_widget() + .layout(&mut tree.children[0], renderer, limits) + }, ) } diff --git a/src/widget/cosmic_container.rs b/src/widget/cosmic_container.rs index 2ef607b..cf1536d 100644 --- a/src/widget/cosmic_container.rs +++ b/src/widget/cosmic_container.rs @@ -162,7 +162,12 @@ where self.height } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { layout( renderer, limits, @@ -173,7 +178,11 @@ where self.padding, self.horizontal_alignment, self.vertical_alignment, - |renderer, limits| self.content.as_widget().layout(renderer, limits), + |renderer, limits| { + self.content + .as_widget() + .layout(&mut tree.children[0], renderer, limits) + }, ) } diff --git a/src/widget/cosmic_toggler.rs b/src/widget/cosmic_toggler.rs index 7717111..ccabb8f 100644 --- a/src/widget/cosmic_toggler.rs +++ b/src/widget/cosmic_toggler.rs @@ -1,17 +1,14 @@ //! Show toggle controls using togglers. -use cosmic::iced_core::alignment; -use cosmic::iced_core::event; -use cosmic::iced_core::layout; -use cosmic::iced_core::mouse; -use cosmic::iced_core::renderer; -use cosmic::iced_core::text; -use cosmic::iced_core::widget::Tree; -use cosmic::iced_core::{ - Alignment, Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Widget, + +use iced_core::{ + alignment, event, layout, mouse, renderer, text, widget::Tree, Clipboard, Element, Event, + Layout, Length, Pixels, Rectangle, Shell, Widget, }; -use cosmic::iced_widget::{Row, Text}; -use crate::{chain, id, lerp}; +use crate::{ + chain, id, lerp, + reexports::{iced, iced_core, iced_widget}, +}; pub use cosmic::iced_style::toggler::{Appearance, StyleSheet}; /// A toggler widget. @@ -155,27 +152,43 @@ where Length::Shrink } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { - let mut row = Row::<(), Renderer>::new() - .width(self.width) - .spacing(self.spacing) - .align_items(Alignment::Center); - - if let Some(label) = &self.label { - row = row.push( - Text::new(label) - .horizontal_alignment(self.text_alignment) - .font(self.font.unwrap_or_else(|| renderer.default_font())) - .width(self.width) - .size(self.text_size.unwrap_or_else(|| renderer.default_size())) - .line_height(self.text_line_height) - .shaping(self.text_shaping), - ); - } - - row = row.push(Row::new().width(2.0 * self.size).height(self.size)); - - row.layout(renderer, limits) + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { + let limits = limits.width(self.width); + + layout::next_to_each_other( + &limits, + self.spacing, + |_| layout::Node::new(iced_core::Size::new(2.0 * self.size, self.size)), + |limits| { + if let Some(label) = self.label.as_deref() { + let state = tree + .state + .downcast_mut::>(); + + iced_core::widget::text::layout( + state, + renderer, + limits, + self.width, + Length::Shrink, + label, + self.text_line_height, + self.text_size.map(iced::Pixels), + self.font, + self.text_alignment, + alignment::Vertical::Top, + self.text_shaping, + ) + } else { + layout::Node::new(iced_core::Size::ZERO) + } + }, + ) } fn on_event( @@ -230,7 +243,7 @@ where fn draw( &self, - _state: &Tree, + tree: &Tree, renderer: &mut Renderer, theme: &Renderer::Theme, style: &renderer::Style, @@ -247,21 +260,15 @@ where let mut children = layout.children(); - if let Some(label) = &self.label { + if let Some(_label) = &self.label { let label_layout = children.next().unwrap(); - cosmic::iced_widget::text::draw( + iced_widget::text::draw( renderer, style, label_layout, - label, - self.text_size, - self.text_line_height, - self.font, - Default::default(), - self.text_alignment, - alignment::Vertical::Center, - self.text_shaping, + tree.state.downcast_ref(), + iced_widget::text::Appearance::default(), ); } diff --git a/src/widget/toggler.rs b/src/widget/toggler.rs index f49a3e0..c97ae5e 100644 --- a/src/widget/toggler.rs +++ b/src/widget/toggler.rs @@ -8,16 +8,12 @@ use iced_core::layout; use iced_core::mouse; use iced_core::renderer; use iced_core::text; -use iced_core::text::LineHeight; -use iced_core::text::Shaping; -use iced_core::widget::{self, Text, Tree}; + +use iced_core::widget::{self, Tree}; use iced_core::{ - color, Alignment, Clipboard, Color, Element, Event, Layout, Length, Pixels, Rectangle, Shell, - Widget, + color, Clipboard, Color, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Widget, }; -use iced_widget::Row; - use crate::{chain, id, lerp}; pub use iced_style::toggler::{Appearance, StyleSheet}; @@ -156,25 +152,43 @@ where Length::Shrink } - fn layout(&self, renderer: &Renderer, limits: &layout::Limits) -> layout::Node { - let mut row = Row::<(), Renderer>::new() - .width(self.width) - .spacing(self.spacing) - .align_items(Alignment::Center); - - if let Some(label) = &self.label { - row = row.push( - Text::new(label) - .horizontal_alignment(self.text_alignment) - .font(self.font.unwrap_or_else(|| renderer.default_font())) - .width(self.width) - .size(self.text_size.unwrap_or_else(|| renderer.default_size())), - ); - } - - row = row.push(Row::new().width(2.0 * self.size).height(self.size)); - - row.layout(renderer, limits) + fn layout( + &self, + tree: &mut Tree, + renderer: &Renderer, + limits: &layout::Limits, + ) -> layout::Node { + let limits = limits.width(self.width); + + layout::next_to_each_other( + &limits, + self.spacing, + |_| layout::Node::new(iced_core::Size::new(2.0 * self.size, self.size)), + |limits| { + if let Some(label) = self.label.as_deref() { + let state = tree + .state + .downcast_mut::>(); + + iced_core::widget::text::layout( + state, + renderer, + limits, + self.width, + Length::Shrink, + label, + iced_core::text::LineHeight::default(), + self.text_size.map(iced::Pixels), + self.font, + self.text_alignment, + alignment::Vertical::Top, + iced_core::text::Shaping::Advanced, + ) + } else { + layout::Node::new(iced_core::Size::ZERO) + } + }, + ) } fn on_event( @@ -229,7 +243,7 @@ where fn draw( &self, - _state: &Tree, + tree: &Tree, renderer: &mut Renderer, theme: &Renderer::Theme, style: &renderer::Style, @@ -246,21 +260,15 @@ where let mut children = layout.children(); - if let Some(label) = &self.label { + if self.label.is_some() { let label_layout = children.next().unwrap(); - iced_core::widget::text::draw( + iced_widget::text::draw( renderer, style, label_layout, - label, - self.text_size, - LineHeight::default(), - self.font, - Default::default(), - self.text_alignment, - alignment::Vertical::Center, - Shaping::Advanced, + tree.state.downcast_ref(), + iced_widget::text::Appearance::default(), ); } From f68e1acf2106e3b1863bd3718713028e64e007ad Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 1 Dec 2023 17:53:11 -0500 Subject: [PATCH 2/4] fix: toggler layout --- src/utils.rs | 39 ++++++++++++++++++++++++++++++++++++ src/widget/cosmic_toggler.rs | 17 ++++++++++------ src/widget/toggler.rs | 6 +++++- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 0fb30ab..ca47b16 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,6 +2,12 @@ //! Utility functions for handling data in this library. +#[cfg(feature = "libcosmic")] +use crate::reexports::iced_core::{ + layout::{Limits, Node}, + Point, Size, +}; + /// Collect iterator into static array without panicking or collecting into a Vec. /// /// Initializes with `T::default()`, then takes `SIZE` values from the iterator. @@ -16,3 +22,36 @@ pub fn static_array_from_iter( array } + +#[cfg(feature = "libcosmic")] +/// Produces a [`Node`] with two children nodes one right next to each other. +pub fn next_to_each_other( + limits: &Limits, + spacing: f32, + left: impl FnOnce(&Limits) -> Node, + right: impl FnOnce(&Limits) -> Node, +) -> Node { + let mut right_node = right(limits); + let right_size = right_node.size(); + + let left_limits = limits.shrink(Size::new(right_size.width + spacing, 0.0)); + let mut left_node = left(&left_limits); + let left_size = left_node.size(); + + let (left_y, right_y) = if left_size.height > right_size.height { + (0.0, (left_size.height - right_size.height) / 2.0) + } else { + ((right_size.height - left_size.height) / 2.0, 0.0) + }; + + left_node.move_to(Point::new(0.0, left_y)); + right_node.move_to(Point::new(left_size.width + spacing, right_y)); + + Node::with_children( + Size::new( + left_size.width + spacing + right_size.width, + left_size.height.max(right_size.height), + ), + vec![left_node, right_node], + ) +} diff --git a/src/widget/cosmic_toggler.rs b/src/widget/cosmic_toggler.rs index ccabb8f..6712d34 100644 --- a/src/widget/cosmic_toggler.rs +++ b/src/widget/cosmic_toggler.rs @@ -1,8 +1,9 @@ //! Show toggle controls using togglers. use iced_core::{ - alignment, event, layout, mouse, renderer, text, widget::Tree, Clipboard, Element, Event, - Layout, Length, Pixels, Rectangle, Shell, Widget, + alignment, event, layout, mouse, renderer, text, + widget::{self, tree, Tree}, + Clipboard, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Widget, }; use crate::{ @@ -41,7 +42,7 @@ where Renderer::Theme: StyleSheet, { /// The default size of a [`Toggler`]. - pub const DEFAULT_SIZE: f32 = 20.0; + pub const DEFAULT_SIZE: f32 = 24.0; /// Creates a new [`Toggler`]. /// @@ -65,7 +66,7 @@ where text_size: None, text_line_height: text::LineHeight::default(), text_alignment: alignment::Horizontal::Left, - text_shaping: text::Shaping::Basic, + text_shaping: text::Shaping::Advanced, spacing: 0.0, font: None, style: Default::default(), @@ -152,6 +153,10 @@ where Length::Shrink } + fn state(&self) -> tree::State { + tree::State::new(widget::text::State::::default()) + } + fn layout( &self, tree: &mut Tree, @@ -160,10 +165,9 @@ where ) -> layout::Node { let limits = limits.width(self.width); - layout::next_to_each_other( + crate::utils::next_to_each_other( &limits, self.spacing, - |_| layout::Node::new(iced_core::Size::new(2.0 * self.size, self.size)), |limits| { if let Some(label) = self.label.as_deref() { let state = tree @@ -188,6 +192,7 @@ where layout::Node::new(iced_core::Size::ZERO) } }, + |_| layout::Node::new(iced_core::Size::new(2.0 * self.size, self.size)), ) } diff --git a/src/widget/toggler.rs b/src/widget/toggler.rs index c97ae5e..cf392c0 100644 --- a/src/widget/toggler.rs +++ b/src/widget/toggler.rs @@ -9,7 +9,7 @@ use iced_core::mouse; use iced_core::renderer; use iced_core::text; -use iced_core::widget::{self, Tree}; +use iced_core::widget::{self, tree, Tree}; use iced_core::{ color, Clipboard, Color, Element, Event, Layout, Length, Pixels, Rectangle, Shell, Widget, }; @@ -152,6 +152,10 @@ where Length::Shrink } + fn state(&self) -> tree::State { + tree::State::new(widget::text::State::::default()) + } + fn layout( &self, tree: &mut Tree, From f7a1485e306dabbd019f5e7d15dc3476ab4c6703 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 4 Dec 2023 12:48:18 -0500 Subject: [PATCH 3/4] chore: updates --- Cargo.toml | 12 ++++++------ examples/pokedex/Cargo.toml | 2 +- examples/stopwatch/Cargo.toml | 2 +- src/widget/cosmic_toggler.rs | 3 ++- src/widget/toggler.rs | 3 ++- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5d09a90..671da2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,13 +24,13 @@ members = [ ] [dependencies] -iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["tokio"], optional = true } +iced = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", features = ["tokio"], optional = true } # iced = { version = "0.12.0", features = [ "tokio" ], optional = true } -iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } -iced_widget = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } -iced_futures = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } -iced_core = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } -iced_style = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", optional = true } +iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } +iced_widget = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } +iced_futures = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } +iced_core = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } +iced_style = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], branch = "update-0.12", optional = true } # libcosmic = { path = "../libcosmic", optional = true, features = [ "tokio" ]} once_cell = { version = "1.18.0", optional = true } diff --git a/examples/pokedex/Cargo.toml b/examples/pokedex/Cargo.toml index 41c7723..9a5988d 100644 --- a/examples/pokedex/Cargo.toml +++ b/examples/pokedex/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" publish = false [dependencies] -iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["image", "debug", "tokio"] } +iced = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", features = ["image", "debug", "tokio"] } cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } serde_json = "1.0" diff --git a/examples/stopwatch/Cargo.toml b/examples/stopwatch/Cargo.toml index 862e551..a7a71ca 100644 --- a/examples/stopwatch/Cargo.toml +++ b/examples/stopwatch/Cargo.toml @@ -6,6 +6,6 @@ edition = "2021" publish = false [dependencies] -iced = { git = "https://github.com/iced-rs/iced", rev = "7f8b176", features = ["smol"] } +iced = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", features = ["smol"] } cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] } diff --git a/src/widget/cosmic_toggler.rs b/src/widget/cosmic_toggler.rs index 6712d34..0eb87a3 100644 --- a/src/widget/cosmic_toggler.rs +++ b/src/widget/cosmic_toggler.rs @@ -254,7 +254,7 @@ where style: &renderer::Style, layout: Layout<'_>, cursor_position: mouse::Cursor, - _viewport: &Rectangle, + viewport: &Rectangle, ) { /// Makes sure that the border radius of the toggler looks good at every size. const BORDER_RADIUS_RATIO: f32 = 32.0 / 13.0; @@ -274,6 +274,7 @@ where label_layout, tree.state.downcast_ref(), iced_widget::text::Appearance::default(), + viewport, ); } diff --git a/src/widget/toggler.rs b/src/widget/toggler.rs index cf392c0..a315136 100644 --- a/src/widget/toggler.rs +++ b/src/widget/toggler.rs @@ -253,7 +253,7 @@ where style: &renderer::Style, layout: Layout<'_>, cursor_position: mouse::Cursor, - _viewport: &Rectangle, + viewport: &Rectangle, ) { /// Makes sure that the border radius of the toggler looks good at every size. const BORDER_RADIUS_RATIO: f32 = 32.0 / 13.0; @@ -273,6 +273,7 @@ where label_layout, tree.state.downcast_ref(), iced_widget::text::Appearance::default(), + viewport, ); } From 083e98f8013e14bde8cd17c074486a71bacb8559 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 4 Dec 2023 17:55:20 -0500 Subject: [PATCH 4/4] chore: update branch --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 671da2d..a89fc2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ iced_widget = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", option iced_futures = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } iced_core = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } iced_style = { git = "https://github.com/iced-rs/iced", rev = "8727b3f", optional = true } -libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], branch = "update-0.12", optional = true } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], optional = true } # libcosmic = { path = "../libcosmic", optional = true, features = [ "tokio" ]} once_cell = { version = "1.18.0", optional = true } float-cmp = "0.9"