Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to 0.12 #17

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand All @@ -24,12 +24,13 @@ 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 }
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 = "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" ], optional = true }
# libcosmic = { path = "../libcosmic", optional = true, features = [ "tokio" ]}
once_cell = { version = "1.18.0", optional = true }
Expand Down
1 change: 0 additions & 1 deletion examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ edition = "2021"
publish = false

[dependencies]
iced = "0.10.0"
cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] }
2 changes: 1 addition & 1 deletion examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<id::Container> = Lazy::new(id::Container::unique);

Expand Down
2 changes: 1 addition & 1 deletion examples/pokedex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "8727b3f", features = ["image", "debug", "tokio"] }
cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] }
serde_json = "1.0"

Expand Down
4 changes: 2 additions & 2 deletions examples/pokedex/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<id::Space> = Lazy::new(id::Space::unique);
Expand Down
3 changes: 0 additions & 3 deletions examples/pong/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
25 changes: 21 additions & 4 deletions examples/pong/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 7 additions & 3 deletions examples/pong/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -90,7 +94,7 @@ impl Application for Pong {
fn subscription(&self) -> Subscription<Message> {
Subscription::batch(vec![
self.timeline.as_subscription::<Event>().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,
Expand Down
3 changes: 3 additions & 0 deletions examples/pong/src/theme.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use cosmic_time::reexports::iced;
use iced::widget::{container, text};
use iced::{application, color};

Expand Down Expand Up @@ -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<Theme>;
Expand Down
2 changes: 1 addition & 1 deletion examples/stopwatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "8727b3f", features = ["smol"] }
cosmic-time = { path = "../..", default-features = false, features = ["iced", "once_cell"] }

1 change: 1 addition & 0 deletions src/reexports/iced.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use iced;
pub use iced_core;
pub use iced_futures;
pub use iced_runtime;
Expand Down
1 change: 1 addition & 0 deletions src/reexports/libcosmic.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use cosmic::iced;
pub use cosmic::iced_core;
pub use cosmic::iced_futures;
pub use cosmic::iced_runtime;
Expand Down
7 changes: 4 additions & 3 deletions src/reexports/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
39 changes: 39 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,3 +22,36 @@ pub fn static_array_from_iter<T: Copy + Default, const SIZE: usize>(

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],
)
}
13 changes: 11 additions & 2 deletions src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)
}

Expand Down
34 changes: 25 additions & 9 deletions src/widget/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -266,22 +267,32 @@ 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);
}

if fully_expanded {
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 =
Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions src/widget/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
},
)
}

Expand Down
13 changes: 11 additions & 2 deletions src/widget/cosmic_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
)
}

Expand Down
Loading
Loading