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/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..0b4ea23 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, @@ -250,18 +263,12 @@ where 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..aeaad3f 100644 --- a/src/widget/toggler.rs +++ b/src/widget/toggler.rs @@ -156,25 +156,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 +247,7 @@ where fn draw( &self, - _state: &Tree, + tree: &Tree, renderer: &mut Renderer, theme: &Renderer::Theme, style: &renderer::Style, @@ -249,18 +267,12 @@ where if let Some(label) = &self.label { 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(), ); }