Skip to content

Commit 2daeb71

Browse files
committed
Add compat with libcosmic
Requires adding the libcosmic feature in Cargo.toml ``` cosmic-time = { version = 1.2.3, features = ["libcosmic"] } ```
1 parent dbce137 commit 2daeb71

17 files changed

+4006
-223
lines changed

Cargo.lock

Lines changed: 2268 additions & 157 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ documentation = "https://docs.rs/cosmic-time"
1010
keywords = ["gui", "animation", "interface", "widgets", "iced"]
1111
categories = ["gui"]
1212

13+
[features]
14+
default = ["iced", "iced_native", "iced_futures", "iced_core", "iced_style"]
15+
libcosmic = ["dep:libcosmic"]
16+
1317
[workspace]
1418
members = [
1519
"examples/*",
1620
]
1721

1822
[dependencies]
19-
iced = { version = "0.9.0", features = [ "tokio" ] }
20-
iced_native = "0.10.1"
21-
iced_futures = "0.6.0"
22-
iced_core = "0.9.0"
23-
iced_style = "0.8.0"
23+
iced = { version = "0.9.0", features = [ "tokio" ], optional = true }
24+
iced_native = { version = "0.10.1", optional = true }
25+
iced_futures = { version = "0.6.0", optional = true }
26+
iced_core = { version = "0.9.0", optional = true }
27+
iced_style = { version = "0.8.0", optional = true }
28+
libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "5765053", features = [ "tokio", "wayland" ], optional = true }

src/keyframes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ mod space;
99
mod style_button;
1010
mod style_container;
1111

12+
#[cfg(feature = "libcosmic")]
13+
use cosmic::iced_core::{widget, Length};
14+
#[cfg(not(feature = "libcosmic"))]
1215
use iced_native::{widget, Length};
1316

1417
pub use button::Button;

src/keyframes/button.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
use iced_native::{widget, Element, Length, Padding};
1+
#[cfg(feature = "libcosmic")]
2+
use cosmic::iced::widget;
3+
#[cfg(feature = "libcosmic")]
4+
use cosmic::iced_core::{widget::Id as IcedId, Element, Length, Padding, Renderer as IcedRenderer};
5+
6+
#[cfg(not(feature = "libcosmic"))]
7+
use iced_native::{
8+
widget, widget::Id as IcedId, Element, Length, Padding, Renderer as IcedRenderer,
9+
};
210

311
use crate::keyframes::{as_f32, get_length, Repeat};
412
use crate::timeline::Frame;
513
use crate::{Ease, Linear, MovementType};
614

715
/// A Button's animation Id. Used for linking animation built in `update()` with widget output in `view()`
816
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Id(iced_native::widget::Id);
17+
pub struct Id(IcedId);
1018

1119
impl Id {
1220
/// Creates a custom [`Id`].
1321
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
14-
Self(widget::Id::new(id))
22+
Self(IcedId::new(id))
1523
}
1624

1725
/// Creates a unique [`Id`].
1826
///
1927
/// This function produces a different [`Id`] every time it is called.
2028
pub fn unique() -> Self {
21-
Self(widget::Id::unique())
29+
Self(IcedId::unique())
2230
}
2331

2432
/// Used by [`crate::chain!`] macro
@@ -38,14 +46,14 @@ impl Id {
3846
content: impl Into<Element<'a, Message, Renderer>>,
3947
) -> widget::Button<'a, Message, Renderer>
4048
where
41-
Renderer: iced_native::Renderer,
49+
Renderer: IcedRenderer,
4250
Renderer::Theme: widget::button::StyleSheet,
4351
{
4452
Button::as_widget(self, timeline, content)
4553
}
4654
}
4755

48-
impl From<Id> for widget::Id {
56+
impl From<Id> for IcedId {
4957
fn from(id: Id) -> Self {
5058
id.0
5159
}
@@ -147,10 +155,10 @@ impl Button {
147155
content: impl Into<Element<'a, Message, Renderer>>,
148156
) -> widget::Button<'a, Message, Renderer>
149157
where
150-
Renderer: iced_native::Renderer,
158+
Renderer: IcedRenderer,
151159
Renderer::Theme: widget::button::StyleSheet,
152160
{
153-
let id: widget::Id = id.into();
161+
let id: IcedId = id.into();
154162

155163
widget::Button::new(content)
156164
.width(get_length(&id, timeline, 0, Length::Shrink))

src/keyframes/column.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
use iced_native::{widget, Length, Padding, Pixels};
1+
#[cfg(feature = "libcosmic")]
2+
use cosmic::iced::widget;
3+
#[cfg(feature = "libcosmic")]
4+
use cosmic::iced_core::{widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer};
5+
6+
#[cfg(not(feature = "libcosmic"))]
7+
use iced_native::{
8+
widget, widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer,
9+
};
210

311
use crate::keyframes::{as_f32, get_length, Repeat};
412
use crate::timeline::Frame;
513
use crate::{Ease, Linear, MovementType};
614

715
/// A Column's animation Id. Used for linking animation built in `update()` with widget output in `view()`
816
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Id(iced_native::widget::Id);
17+
pub struct Id(IcedId);
1018

1119
impl Id {
1220
/// Creates a custom [`Id`].
1321
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
14-
Self(widget::Id::new(id))
22+
Self(IcedId::new(id))
1523
}
1624

1725
/// Creates a unique [`Id`].
1826
///
1927
/// This function produces a different [`Id`] every time it is called.
2028
pub fn unique() -> Self {
21-
Self(widget::Id::unique())
29+
Self(IcedId::unique())
2230
}
2331

2432
/// Used by [`crate::chain!`] macro
@@ -37,14 +45,14 @@ impl Id {
3745
timeline: &crate::Timeline,
3846
) -> widget::Column<'a, Message, Renderer>
3947
where
40-
Renderer: iced_native::Renderer,
48+
Renderer: IcedRenderer,
4149
Renderer::Theme: widget::container::StyleSheet,
4250
{
4351
Column::as_widget(self, timeline)
4452
}
4553
}
4654

47-
impl From<Id> for widget::Id {
55+
impl From<Id> for IcedId {
4856
fn from(id: Id) -> Self {
4957
id.0
5058
}
@@ -148,10 +156,10 @@ impl Column {
148156
timeline: &crate::Timeline,
149157
) -> widget::Column<'a, Message, Renderer>
150158
where
151-
Renderer: iced_native::Renderer,
159+
Renderer: IcedRenderer,
152160
Renderer::Theme: widget::container::StyleSheet,
153161
{
154-
let id: widget::Id = id.into();
162+
let id: IcedId = id.into();
155163

156164
widget::Column::new()
157165
.spacing(timeline.get(&id, 0).map(|m| m.value).unwrap_or(0.))

src/keyframes/container.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
use iced_native::{widget, Element, Length, Padding, Pixels};
1+
#[cfg(feature = "libcosmic")]
2+
use cosmic::iced::widget;
3+
#[cfg(feature = "libcosmic")]
4+
use cosmic::iced_core::{
5+
widget::Id as IcedId, Element, Length, Padding, Pixels, Renderer as IcedRenderer,
6+
};
7+
8+
#[cfg(not(feature = "libcosmic"))]
9+
use iced_native::{
10+
widget, widget::Id as IcedId, Element, Length, Padding, Pixels, Renderer as IcedRenderer,
11+
};
212

313
use crate::keyframes::{as_f32, get_length, Repeat};
414
use crate::timeline::Frame;
515
use crate::{Ease, Linear, MovementType};
616

717
/// A Container's animation Id. Used for linking animation built in `update()` with widget output in `view()`
818
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Id(iced_native::widget::Id);
19+
pub struct Id(IcedId);
1020

1121
impl Id {
1222
/// Creates a custom [`Id`].
1323
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
14-
Self(widget::Id::new(id))
24+
Self(IcedId::new(id))
1525
}
1626

1727
/// Creates a unique [`Id`].
1828
///
1929
/// This function produces a different [`Id`] every time it is called.
2030
pub fn unique() -> Self {
21-
Self(widget::Id::unique())
31+
Self(IcedId::unique())
2232
}
2333

2434
/// Used by [`crate::chain!`] macro
@@ -38,14 +48,14 @@ impl Id {
3848
content: impl Into<Element<'a, Message, Renderer>>,
3949
) -> widget::Container<'a, Message, Renderer>
4050
where
41-
Renderer: iced_native::Renderer,
51+
Renderer: IcedRenderer,
4252
Renderer::Theme: widget::container::StyleSheet,
4353
{
4454
Container::as_widget(self, timeline, content)
4555
}
4656
}
4757

48-
impl From<Id> for widget::Id {
58+
impl From<Id> for IcedId {
4959
fn from(id: Id) -> Self {
5060
id.0
5161
}
@@ -153,10 +163,10 @@ impl Container {
153163
content: impl Into<Element<'a, Message, Renderer>>,
154164
) -> widget::Container<'a, Message, Renderer>
155165
where
156-
Renderer: iced_native::Renderer,
166+
Renderer: IcedRenderer,
157167
Renderer::Theme: widget::container::StyleSheet,
158168
{
159-
let id: widget::Id = id.into();
169+
let id: IcedId = id.into();
160170

161171
widget::Container::new(content)
162172
.width(get_length(&id, timeline, 0, Length::Shrink))

src/keyframes/row.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1-
use iced_native::{widget, Length, Padding, Pixels};
1+
#[cfg(feature = "libcosmic")]
2+
use cosmic::iced::widget;
3+
#[cfg(feature = "libcosmic")]
4+
use cosmic::iced_core::{widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer};
5+
6+
#[cfg(not(feature = "libcosmic"))]
7+
use iced_native::{
8+
widget, widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer,
9+
};
210

311
use crate::keyframes::{as_f32, get_length, Repeat};
412
use crate::timeline::Frame;
513
use crate::{Ease, Linear, MovementType};
614

715
/// A Row's animation Id. Used for linking animation built in `update()` with widget output in `view()`
816
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Id(iced_native::widget::Id);
17+
pub struct Id(IcedId);
1018

1119
impl Id {
1220
/// Creates a custom [`Id`].
1321
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
14-
Self(widget::Id::new(id))
22+
Self(IcedId::new(id))
1523
}
1624

1725
/// Creates a unique [`Id`].
1826
///
1927
/// This function produces a different [`Id`] every time it is called.
2028
pub fn unique() -> Self {
21-
Self(widget::Id::unique())
29+
Self(IcedId::unique())
2230
}
2331

2432
/// Used by [`crate::chain!`] macro
@@ -37,14 +45,14 @@ impl Id {
3745
timeline: &crate::Timeline,
3846
) -> widget::Row<'a, Message, Renderer>
3947
where
40-
Renderer: iced_native::Renderer,
48+
Renderer: IcedRenderer,
4149
Renderer::Theme: widget::container::StyleSheet,
4250
{
4351
Row::as_widget(self, timeline)
4452
}
4553
}
4654

47-
impl From<Id> for widget::Id {
55+
impl From<Id> for IcedId {
4856
fn from(id: Id) -> Self {
4957
id.0
5058
}
@@ -148,10 +156,10 @@ impl Row {
148156
timeline: &crate::Timeline,
149157
) -> widget::Row<'a, Message, Renderer>
150158
where
151-
Renderer: iced_native::Renderer,
159+
Renderer: IcedRenderer,
152160
Renderer::Theme: widget::container::StyleSheet,
153161
{
154-
let id: widget::Id = id.into();
162+
let id: IcedId = id.into();
155163

156164
widget::Row::new()
157165
.spacing(timeline.get(&id, 0).map(|m| m.value).unwrap_or(0.))

src/keyframes/space.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
use iced_native::{widget, Length};
1+
#[cfg(feature = "libcosmic")]
2+
use cosmic::iced::widget;
3+
#[cfg(feature = "libcosmic")]
4+
use cosmic::iced_core::{widget::Id as IcedId, Length};
5+
6+
#[cfg(not(feature = "libcosmic"))]
7+
use iced_native::{widget, widget::Id as IcedId, Length};
28

39
use crate::keyframes::{as_f32, get_length, Repeat};
410
use crate::timeline::Frame;
511
use crate::{Ease, Linear, MovementType};
612

713
/// A Space's animation Id. Used for linking animation built in `update()` with widget output in `view()`
814
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
9-
pub struct Id(iced_native::widget::Id);
15+
pub struct Id(IcedId);
1016

1117
impl Id {
1218
/// Creates a custom [`Id`].
1319
pub fn new(id: impl Into<std::borrow::Cow<'static, str>>) -> Self {
14-
Self(widget::Id::new(id))
20+
Self(IcedId::new(id))
1521
}
1622

1723
/// Creates a unique [`Id`].
1824
///
1925
/// This function produces a different [`Id`] every time it is called.
2026
pub fn unique() -> Self {
21-
Self(widget::Id::unique())
27+
Self(IcedId::unique())
2228
}
2329

2430
/// Used by [`crate::chain!`] macro
@@ -37,7 +43,7 @@ impl Id {
3743
}
3844
}
3945

40-
impl From<Id> for widget::Id {
46+
impl From<Id> for IcedId {
4147
fn from(id: Id) -> Self {
4248
id.0
4349
}
@@ -131,7 +137,7 @@ impl Space {
131137
}
132138

133139
pub fn as_widget(id: Id, timeline: &crate::Timeline) -> widget::Space {
134-
let id: widget::Id = id.into();
140+
let id: IcedId = id.into();
135141

136142
widget::Space::new(
137143
get_length(&id, timeline, 0, Length::Shrink),

0 commit comments

Comments
 (0)