Skip to content

Commit

Permalink
chore: update to 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Nov 30, 2023
1 parent 71116b2 commit b486f9b
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 99 deletions.
17 changes: 9 additions & 8 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,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"
Expand Down
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};
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
13 changes: 11 additions & 2 deletions src/widget/cosmic_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
},
)
}

Expand Down
91 changes: 49 additions & 42 deletions src/widget/cosmic_toggler.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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_widget::text::State<Renderer::Paragraph>>();

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(
Expand Down Expand Up @@ -230,7 +243,7 @@ where

fn draw(
&self,
_state: &Tree,
tree: &Tree,
renderer: &mut Renderer,
theme: &Renderer::Theme,
style: &renderer::Style,
Expand All @@ -250,18 +263,12 @@ where
if let Some(label) = &self.label {

Check warning on line 263 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

unused variable: `label`

Check warning on line 263 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

unused variable: `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(),
);
}

Expand Down
Loading

0 comments on commit b486f9b

Please sign in to comment.