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

Add compat with libcosmic #12

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add compat with libcosmic
Requires adding the libcosmic feature in Cargo.toml
```
cosmic-time = { version = 1.2.3, features = ["libcosmic"] }
```
  • Loading branch information
13r0ck committed Jun 1, 2023
commit 2daeb71350cb41489f44ba21f0ba98acf8128f9b
2,425 changes: 2,268 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ documentation = "https://docs.rs/cosmic-time"
keywords = ["gui", "animation", "interface", "widgets", "iced"]
categories = ["gui"]

[features]
default = ["iced", "iced_native", "iced_futures", "iced_core", "iced_style"]
libcosmic = ["dep:libcosmic"]

[workspace]
members = [
"examples/*",
]

[dependencies]
iced = { version = "0.9.0", features = [ "tokio" ] }
iced_native = "0.10.1"
iced_futures = "0.6.0"
iced_core = "0.9.0"
iced_style = "0.8.0"
iced = { version = "0.9.0", features = [ "tokio" ], optional = true }
iced_native = { version = "0.10.1", optional = true }
iced_futures = { version = "0.6.0", optional = true }
iced_core = { version = "0.9.0", optional = true }
iced_style = { version = "0.8.0", optional = true }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", rev = "5765053", features = [ "tokio", "wayland" ], optional = true }
3 changes: 3 additions & 0 deletions src/keyframes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ mod space;
mod style_button;
mod style_container;

#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{widget, Length};
#[cfg(not(feature = "libcosmic"))]
use iced_native::{widget, Length};

pub use button::Button;
Expand Down
24 changes: 16 additions & 8 deletions src/keyframes/button.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
use iced_native::{widget, Element, Length, Padding};
#[cfg(feature = "libcosmic")]
use cosmic::iced::widget;
#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{widget::Id as IcedId, Element, Length, Padding, Renderer as IcedRenderer};

#[cfg(not(feature = "libcosmic"))]
use iced_native::{
widget, widget::Id as IcedId, Element, Length, Padding, Renderer as IcedRenderer,
};

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

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

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

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
Self(IcedId::unique())
}

/// Used by [`crate::chain!`] macro
Expand All @@ -38,14 +46,14 @@ impl Id {
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Button<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::button::StyleSheet,
{
Button::as_widget(self, timeline, content)
}
}

impl From<Id> for widget::Id {
impl From<Id> for IcedId {
fn from(id: Id) -> Self {
id.0
}
Expand Down Expand Up @@ -147,10 +155,10 @@ impl Button {
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Button<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::button::StyleSheet,
{
let id: widget::Id = id.into();
let id: IcedId = id.into();

widget::Button::new(content)
.width(get_length(&id, timeline, 0, Length::Shrink))
Expand Down
24 changes: 16 additions & 8 deletions src/keyframes/column.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
use iced_native::{widget, Length, Padding, Pixels};
#[cfg(feature = "libcosmic")]
use cosmic::iced::widget;
#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer};

#[cfg(not(feature = "libcosmic"))]
use iced_native::{
widget, widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer,
};

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

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

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

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
Self(IcedId::unique())
}

/// Used by [`crate::chain!`] macro
Expand All @@ -37,14 +45,14 @@ impl Id {
timeline: &crate::Timeline,
) -> widget::Column<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
Column::as_widget(self, timeline)
}
}

impl From<Id> for widget::Id {
impl From<Id> for IcedId {
fn from(id: Id) -> Self {
id.0
}
Expand Down Expand Up @@ -148,10 +156,10 @@ impl Column {
timeline: &crate::Timeline,
) -> widget::Column<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
let id: widget::Id = id.into();
let id: IcedId = id.into();

widget::Column::new()
.spacing(timeline.get(&id, 0).map(|m| m.value).unwrap_or(0.))
Expand Down
26 changes: 18 additions & 8 deletions src/keyframes/container.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
use iced_native::{widget, Element, Length, Padding, Pixels};
#[cfg(feature = "libcosmic")]
use cosmic::iced::widget;
#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{
widget::Id as IcedId, Element, Length, Padding, Pixels, Renderer as IcedRenderer,
};

#[cfg(not(feature = "libcosmic"))]
use iced_native::{
widget, widget::Id as IcedId, Element, Length, Padding, Pixels, Renderer as IcedRenderer,
};

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

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

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

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
Self(IcedId::unique())
}

/// Used by [`crate::chain!`] macro
Expand All @@ -38,14 +48,14 @@ impl Id {
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Container<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
Container::as_widget(self, timeline, content)
}
}

impl From<Id> for widget::Id {
impl From<Id> for IcedId {
fn from(id: Id) -> Self {
id.0
}
Expand Down Expand Up @@ -153,10 +163,10 @@ impl Container {
content: impl Into<Element<'a, Message, Renderer>>,
) -> widget::Container<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
let id: widget::Id = id.into();
let id: IcedId = id.into();

widget::Container::new(content)
.width(get_length(&id, timeline, 0, Length::Shrink))
Expand Down
24 changes: 16 additions & 8 deletions src/keyframes/row.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
use iced_native::{widget, Length, Padding, Pixels};
#[cfg(feature = "libcosmic")]
use cosmic::iced::widget;
#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer};

#[cfg(not(feature = "libcosmic"))]
use iced_native::{
widget, widget::Id as IcedId, Length, Padding, Pixels, Renderer as IcedRenderer,
};

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

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

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

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
Self(IcedId::unique())
}

/// Used by [`crate::chain!`] macro
Expand All @@ -37,14 +45,14 @@ impl Id {
timeline: &crate::Timeline,
) -> widget::Row<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
Row::as_widget(self, timeline)
}
}

impl From<Id> for widget::Id {
impl From<Id> for IcedId {
fn from(id: Id) -> Self {
id.0
}
Expand Down Expand Up @@ -148,10 +156,10 @@ impl Row {
timeline: &crate::Timeline,
) -> widget::Row<'a, Message, Renderer>
where
Renderer: iced_native::Renderer,
Renderer: IcedRenderer,
Renderer::Theme: widget::container::StyleSheet,
{
let id: widget::Id = id.into();
let id: IcedId = id.into();

widget::Row::new()
.spacing(timeline.get(&id, 0).map(|m| m.value).unwrap_or(0.))
Expand Down
18 changes: 12 additions & 6 deletions src/keyframes/space.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
use iced_native::{widget, Length};
#[cfg(feature = "libcosmic")]
use cosmic::iced::widget;
#[cfg(feature = "libcosmic")]
use cosmic::iced_core::{widget::Id as IcedId, Length};

#[cfg(not(feature = "libcosmic"))]
use iced_native::{widget, widget::Id as IcedId, Length};

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

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

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

/// Creates a unique [`Id`].
///
/// This function produces a different [`Id`] every time it is called.
pub fn unique() -> Self {
Self(widget::Id::unique())
Self(IcedId::unique())
}

/// Used by [`crate::chain!`] macro
Expand All @@ -37,7 +43,7 @@ impl Id {
}
}

impl From<Id> for widget::Id {
impl From<Id> for IcedId {
fn from(id: Id) -> Self {
id.0
}
Expand Down Expand Up @@ -131,7 +137,7 @@ impl Space {
}

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

widget::Space::new(
get_length(&id, timeline, 0, Length::Shrink),
Expand Down
Loading