Skip to content

Commit

Permalink
fix(cosmic): support icon color renderer style
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Sep 1, 2023
1 parent 4013946 commit deb6f81
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"rust-analyzer.check.overrideCommand": ["just", "check-json"],
"git-blame.gitWebUrl": ""
}
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ 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 }
# libcosmic = { path = "../libcosmic", optional = true }
# libcosmic = { path = "../libcosmic", optional = true, features = [ "tokio" ]}
once_cell = { version = "1.18.0", optional = true }
float-cmp = "0.9"

10 changes: 10 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
check *args: (check-cosmic args) (check-iced args)

check-cosmic *args:
cargo clippy --no-default-features --features wayland-libcosmic {{args}} -- -W clippy::pedantic
cargo clippy --no-default-features --features winit-libcosmic {{args}} -- -W clippy::pedantic

check-iced *args:
cargo clippy --no-default-features --features iced {{args}} -- -W clippy::pedantic

check-json: (check '--message-format=json')
6 changes: 3 additions & 3 deletions src/keyframes/cards.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmic::iced_core::widget::Id as IcedId;
use cosmic::widget::IconSource;
use cosmic::widget::icon::Handle;
use cosmic::Element;

use crate::keyframes::Repeat;
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Id {
show_more_label: &'a str,
show_less_label: &'a str,
clear_all_label: &'a str,
show_less_icon: Option<IconSource<'a>>,
show_less_icon: Option<Handle>,
expanded: bool,
) -> crate::widget::Cards<'a, Message, cosmic::Renderer>
where
Expand Down Expand Up @@ -203,7 +203,7 @@ impl Cards {
show_more_label: &'a str,
show_less_label: &'a str,
clear_all_label: &'a str,
show_less_icon: Option<IconSource<'a>>,
show_less_icon: Option<Handle>,
expanded: bool,
) -> crate::widget::Cards<'a, Message, cosmic::Renderer>
where
Expand Down
5 changes: 4 additions & 1 deletion src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ where
tree: &Tree,
renderer: &mut Renderer,
theme: &Renderer::Theme,
_style: &renderer::Style,
#[cfg(feature = "libcosmic")] style: &renderer::Style,
#[cfg(not(feature = "libcosmic"))] _style: &renderer::Style,
layout: Layout<'_>,
cursor_position: mouse::Cursor,
_viewport: &Rectangle,
Expand All @@ -216,6 +217,8 @@ where
renderer,
theme,
&renderer::Style {
#[cfg(feature = "libcosmic")]
icon_color: styling.icon_color.unwrap_or(style.icon_color),
text_color: styling.text_color,
},
content_layout,
Expand Down
52 changes: 28 additions & 24 deletions src/widget/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use self::iced_core::{
use cosmic::{
cosmic_theme::LayeredTheme,
iced_core,
iced_widget::{column, text, Row},
widget::{button, card::style::StyleSheet, icon, IconSource},
widget::{button, card::style::StyleSheet, column, icon, icon::Handle, row, text},

Check failure on line 9 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

unused import: `row`

Check warning on line 9 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

unused import: `row`

Check failure on line 9 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

unused import: `row`

Check warning on line 9 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

unused import: `row`
};
use float_cmp::approx_eq;

Expand All @@ -31,7 +30,7 @@ pub fn cards<'a, Message, F>(
show_more_label: &'a str,
show_less_label: &'a str,
clear_all_label: &'a str,
show_less_icon: Option<IconSource<'a>>,
show_less_icon: Option<Handle>,
expanded: bool,
) -> Cards<'a, Message, cosmic::Renderer>
where
Expand Down Expand Up @@ -102,7 +101,7 @@ where
show_more_label: &'a str,
show_less_label: &'a str,
clear_all_label: &'a str,
show_less_icon: Option<IconSource<'a>>,
show_less_icon: Option<Handle>,
expanded: bool,
) -> Self
where
Expand All @@ -114,31 +113,32 @@ where
show_less_button: {
let mut show_less_children = Vec::with_capacity(3);
if let Some(source) = show_less_icon {
show_less_children.push(icon(source, ICON_SIZE).into());
show_less_children.push(icon(source).size(ICON_SIZE).into());

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

the trait bound `cosmic::widget::IconSource<'_>: std::convert::From<cosmic::widget::icon::Handle>` is not satisfied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

this function takes 2 arguments but 1 argument was supplied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

the trait bound `IconSource<'_>: From<cosmic::widget::icon::Handle>` is not satisfied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

this function takes 2 arguments but 1 argument was supplied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

the trait bound `cosmic::widget::IconSource<'_>: std::convert::From<cosmic::widget::icon::Handle>` is not satisfied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

this function takes 2 arguments but 1 argument was supplied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

the trait bound `IconSource<'_>: From<cosmic::widget::icon::Handle>` is not satisfied

Check failure on line 116 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

this function takes 2 arguments but 1 argument was supplied
}
show_less_children.push(text(show_less_label).width(Length::Shrink).into());
show_less_children.push(
icon(IconSource::from("pan-up-symbolic"), ICON_SIZE)
.style(cosmic::theme::Svg::Symbolic)
icon::handle::from_name("pan-up-symbolic")

Check failure on line 120 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: could not find `handle` in `icon`

Check failure on line 120 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: could not find `handle` in `icon`

Check failure on line 120 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: could not find `handle` in `icon`

Check failure on line 120 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: could not find `handle` in `icon`
.size(ICON_SIZE)
.icon()
.into(),
);
let off_animation = chain::Cards::off(id.clone(), 1.0);

let button_content = row::with_children(show_less_children)

Check failure on line 127 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: use of undeclared crate or module `row`

Check failure on line 127 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: use of undeclared crate or module `row`

Check failure on line 127 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: use of undeclared crate or module `row`

Check failure on line 127 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: use of undeclared crate or module `row`
.align_items(iced_core::Alignment::Center)
.spacing(TOP_SPACING)
.width(Length::Shrink);

Element::from(
button(cosmic::theme::Button::Text)
.custom(vec![Row::with_children(show_less_children)
.align_items(iced_core::Alignment::Center)
.spacing(TOP_SPACING)
.width(Length::Shrink)
.into()])
button(button_content)
.style(cosmic::theme::Button::Text)

Check failure on line 134 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

no method named `style` found for struct `cosmic::widget::Button` in the current scope

Check failure on line 134 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

no method named `style` found for struct `cosmic::widget::Button` in the current scope

Check failure on line 134 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

no method named `style` found for struct `cosmic::widget::Button` in the current scope

Check failure on line 134 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

no method named `style` found for struct `cosmic::widget::Button` in the current scope
.width(Length::Shrink)
.on_press(on_show_more(off_animation, false))
.padding([PADDING / 2, PADDING]),
)
},
clear_all_button: Element::from(
button(cosmic::theme::Button::Text)
.text(clear_all_label.as_ref())
button::text(clear_all_label)

Check failure on line 141 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: use of undeclared crate or module `button`

Check failure on line 141 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: use of undeclared crate or module `button`

Check failure on line 141 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: use of undeclared crate or module `button`

Check failure on line 141 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: use of undeclared crate or module `button`
.width(Length::Shrink)
.on_press(on_clear_all)
.padding([PADDING / 2, PADDING]),
Expand All @@ -147,15 +147,19 @@ where
.into_iter()
.enumerate()
.map(|(i, w)| {
let b = button(cosmic::theme::Button::Card)
.custom(vec![if i == 0 && !expanded && can_show_more {
column![w, text(show_more_label).size(10)]
.spacing(VERTICAL_SPACING)
.align_items(iced_core::Alignment::Center)
.into()
} else {
w
}])
let custom_content = if i == 0 && !expanded && can_show_more {
column::with_capacity(2)

Check failure on line 151 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

cannot find function `with_capacity` in module `column`

Check failure on line 151 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

cannot find function `with_capacity` in module `column`

Check failure on line 151 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

cannot find function `with_capacity` in module `column`

Check failure on line 151 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

cannot find function `with_capacity` in module `column`
.push(w)
.push(text(show_more_label).size(10))
.spacing(VERTICAL_SPACING)
.align_items(iced_core::Alignment::Center)
.into()
} else {
w
};

let b = cosmic::iced::widget::button(custom_content)
.style(cosmic::theme::IcedButton::Card)

Check failure on line 162 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: could not find `IcedButton` in `theme`

Check failure on line 162 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: could not find `IcedButton` in `theme`

Check failure on line 162 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / all

failed to resolve: could not find `IcedButton` in `theme`

Check failure on line 162 in src/widget/cards.rs

View workflow job for this annotation

GitHub Actions / wayland

failed to resolve: could not find `IcedButton` in `theme`
.padding(PADDING);
if i == 0 && !expanded && can_show_more {
let on_animation = chain::Cards::on(id.clone(), 1.0);
Expand Down
4 changes: 3 additions & 1 deletion src/widget/cosmic_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use cosmic::iced_style::button::{Appearance, StyleSheet};

/// A generic widget that produces a message when pressed.
#[allow(missing_debug_implementations)]
pub struct Button<'a, Message, Renderer = cosmic::iced::Renderer>
pub struct Button<'a, Message, Renderer = cosmic::Renderer>
where
Renderer: cosmic::iced_core::Renderer,
Renderer::Theme: StyleSheet,
Expand Down Expand Up @@ -271,6 +271,8 @@ where
renderer,
theme,
&renderer::Style {
#[cfg(feature = "libcosmic")]
icon_color: styling.icon_color.unwrap_or(style.icon_color),

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / all

struct `cosmic::iced_core::renderer::Style` has no field named `icon_color`

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / wayland

struct `Style` has no field named `icon_color`

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / wayland

no field `icon_color` on type `cosmic::iced_style::button::Appearance`

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / all

struct `cosmic::iced_core::renderer::Style` has no field named `icon_color`

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / wayland

struct `Style` has no field named `icon_color`

Check failure on line 275 in src/widget/cosmic_button.rs

View workflow job for this annotation

GitHub Actions / wayland

no field `icon_color` on type `cosmic::iced_style::button::Appearance`
text_color: styling.text_color,
scale_factor: style.scale_factor,
},
Expand Down
1 change: 1 addition & 0 deletions src/widget/cosmic_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ where
renderer,
theme,
&renderer::Style {
icon_color: style.icon_color.unwrap_or(renderer_style.icon_color),
text_color: style.text_color.unwrap_or(renderer_style.text_color),
scale_factor: renderer_style.scale_factor,
},
Expand Down

0 comments on commit deb6f81

Please sign in to comment.