libcosmic/src/theme/mod.rs

1248 lines
39 KiB
Rust
Raw Normal View History

// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
2023-08-15 10:51:59 +02:00
//! Use COSMIC's themes and styles.
pub mod expander;
mod button;
pub use self::button::Button;
mod segmented_button;
pub use self::segmented_button::SegmentedButton;
use std::cell::RefCell;
2023-06-15 11:16:32 -04:00
use std::f32::consts::PI;
use std::rc::Rc;
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
use std::sync::Arc;
2023-06-12 12:08:14 -04:00
use cosmic_config::config_subscription;
use cosmic_config::CosmicConfigEntry;
2023-08-07 16:03:44 -04:00
use cosmic_theme::composite::over;
2023-06-12 12:08:14 -04:00
use cosmic_theme::util::CssColor;
2022-11-17 20:49:20 -05:00
use cosmic_theme::Component;
2023-02-27 17:42:17 -05:00
use cosmic_theme::LayeredTheme;
2023-06-15 11:16:32 -04:00
use iced_core::gradient::Linear;
use iced_core::BorderRadius;
use iced_core::Radians;
2023-06-12 12:08:14 -04:00
use iced_futures::Subscription;
use iced_style::application;
use iced_style::button as iced_button;
use iced_style::checkbox;
use iced_style::container;
use iced_style::menu;
use iced_style::pane_grid;
use iced_style::pick_list;
use iced_style::progress_bar;
use iced_style::radio;
use iced_style::rule;
use iced_style::scrollable;
use iced_style::slider;
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
use iced_style::slider::Rail;
use iced_style::svg;
use iced_style::text_input;
use iced_style::toggler;
use iced_core::{Background, Color};
2023-02-27 17:42:17 -05:00
use palette::Srgba;
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
pub type CosmicColor = ::palette::rgb::Srgba;
pub type CosmicComponent = cosmic_theme::Component<CosmicColor>;
pub type CosmicTheme = cosmic_theme::Theme<CosmicColor>;
lazy_static::lazy_static! {
2023-08-03 19:30:08 -04:00
pub static ref COSMIC_DARK: CosmicTheme = CosmicTheme::dark_default();
pub static ref COSMIC_HC_DARK: CosmicTheme = CosmicTheme::high_contrast_dark_default();
pub static ref COSMIC_LIGHT: CosmicTheme = CosmicTheme::light_default();
pub static ref COSMIC_HC_LIGHT: CosmicTheme = CosmicTheme::high_contrast_light_default();
2022-11-17 20:49:20 -05:00
pub static ref TRANSPARENT_COMPONENT: Component<CosmicColor> = Component {
base: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
hover: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
pressed: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
selected: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
selected_text: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
focus: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
on: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
2023-02-27 17:42:17 -05:00
on_disabled: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
divider: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
border: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
disabled_border: CosmicColor::new(0.0, 0.0, 0.0, 0.0),
2022-11-17 20:49:20 -05:00
};
}
thread_local! {
pub(crate) static THEME: RefCell<Theme> = RefCell::new(Theme { theme_type: ThemeType::Dark, layer: cosmic_theme::Layer::Background });
}
2023-06-09 17:13:01 -04:00
#[derive(Debug, Clone, PartialEq, Default)]
2023-02-27 19:56:53 -05:00
pub enum ThemeType {
#[default]
Dark,
Light,
HighContrastDark,
HighContrastLight,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
Custom(Arc<CosmicTheme>),
System(Arc<CosmicTheme>),
2023-02-27 17:42:17 -05:00
}
2023-06-09 17:13:01 -04:00
#[derive(Debug, Clone, PartialEq, Default)]
2023-02-27 19:56:53 -05:00
pub struct Theme {
pub theme_type: ThemeType,
pub layer: cosmic_theme::Layer,
}
impl Theme {
#[must_use]
2023-02-27 19:56:53 -05:00
pub fn cosmic(&self) -> &cosmic_theme::Theme<Srgba> {
match self.theme_type {
ThemeType::Dark => &COSMIC_DARK,
ThemeType::Light => &COSMIC_LIGHT,
ThemeType::HighContrastDark => &COSMIC_HC_DARK,
ThemeType::HighContrastLight => &COSMIC_HC_LIGHT,
ThemeType::Custom(ref t) | ThemeType::System(ref t) => t.as_ref(),
2023-02-27 19:56:53 -05:00
}
2023-02-27 17:42:17 -05:00
}
#[must_use]
2023-02-27 19:56:53 -05:00
pub fn dark() -> Self {
Self {
theme_type: ThemeType::Dark,
..Default::default()
}
2023-02-27 17:42:17 -05:00
}
2023-02-27 19:56:53 -05:00
#[must_use]
pub fn light() -> Self {
Self {
theme_type: ThemeType::Light,
..Default::default()
}
2023-02-27 17:42:17 -05:00
}
2023-02-27 19:56:53 -05:00
#[must_use]
pub fn dark_hc() -> Self {
Self {
theme_type: ThemeType::HighContrastDark,
..Default::default()
}
2023-02-27 17:42:17 -05:00
}
#[must_use]
2023-02-27 19:56:53 -05:00
pub fn light_hc() -> Self {
2023-02-27 17:42:17 -05:00
Self {
2023-02-27 19:56:53 -05:00
theme_type: ThemeType::HighContrastLight,
..Default::default()
2023-02-27 17:42:17 -05:00
}
}
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
#[must_use]
pub fn custom(theme: Arc<CosmicTheme>) -> Self {
Self {
theme_type: ThemeType::Custom(theme),
..Default::default()
}
}
#[must_use]
pub fn system(theme: Arc<CosmicTheme>) -> Self {
Self {
theme_type: ThemeType::System(theme),
..Default::default()
}
}
2023-02-27 19:56:53 -05:00
/// get current container
/// can be used in a component that is intended to be a child of a `CosmicContainer`
2023-02-27 17:42:17 -05:00
#[must_use]
2023-02-27 19:56:53 -05:00
pub fn current_container(&self) -> &cosmic_theme::Container<Srgba> {
match self.layer {
cosmic_theme::Layer::Background => &self.cosmic().background,
cosmic_theme::Layer::Primary => &self.cosmic().primary,
cosmic_theme::Layer::Secondary => &self.cosmic().secondary,
}
}
/// set the theme
pub fn set_theme(&mut self, theme: ThemeType) {
self.theme_type = theme;
}
}
2023-02-27 17:42:17 -05:00
impl LayeredTheme for Theme {
fn set_layer(&mut self, layer: cosmic_theme::Layer) {
2023-02-27 19:56:53 -05:00
self.layer = layer;
}
}
#[derive(Default)]
pub enum Application {
#[default]
Default,
Custom(Box<dyn Fn(&Theme) -> application::Appearance>),
}
impl Application {
pub fn custom<F: Fn(&Theme) -> application::Appearance + 'static>(f: F) -> Self {
Self::Custom(Box::new(f))
}
}
impl application::StyleSheet for Theme {
type Style = Application;
2022-11-10 16:19:13 +01:00
fn appearance(&self, style: &Self::Style) -> application::Appearance {
let cosmic = self.cosmic();
match style {
Application::Default => application::Appearance {
icon_color: cosmic.bg_color().into(),
background_color: cosmic.bg_color().into(),
2023-02-27 17:42:17 -05:00
text_color: cosmic.on_bg_color().into(),
},
2023-02-27 17:42:17 -05:00
Application::Custom(f) => f(self),
}
}
}
/// Styles for the button widget from iced-rs.
#[derive(Default)]
pub enum IcedButton {
Deactivated,
Destructive,
Positive,
#[default]
Primary,
Secondary,
Text,
2022-12-20 16:02:44 -07:00
Link,
LinkActive,
2022-11-17 20:49:20 -05:00
Transparent,
2023-07-17 11:44:57 -04:00
Card,
2022-12-17 18:15:24 -05:00
Custom {
active: Box<dyn Fn(&Theme) -> iced_button::Appearance>,
hover: Box<dyn Fn(&Theme) -> iced_button::Appearance>,
2022-12-17 18:15:24 -05:00
},
}
impl IcedButton {
2022-12-23 15:10:13 +01:00
#[allow(clippy::trivially_copy_pass_by_ref)]
#[allow(clippy::match_same_arms)]
2023-02-27 17:42:17 -05:00
fn cosmic<'a>(&'a self, theme: &'a Theme) -> &CosmicComponent {
let cosmic = theme.cosmic();
match self {
IcedButton::Primary => &cosmic.accent_button,
IcedButton::Secondary => &theme.current_container().component,
IcedButton::Positive => &cosmic.success_button,
IcedButton::Destructive => &cosmic.destructive_button,
IcedButton::Text => &cosmic.text_button,
IcedButton::Link => &cosmic.accent_button,
IcedButton::LinkActive => &cosmic.accent_button,
IcedButton::Transparent => &TRANSPARENT_COMPONENT,
IcedButton::Deactivated => &theme.current_container().component,
IcedButton::Card => &theme.current_container().component,
IcedButton::Custom { .. } => &TRANSPARENT_COMPONENT,
}
}
}
impl iced_button::StyleSheet for Theme {
type Style = IcedButton;
fn active(&self, style: &Self::Style) -> iced_button::Appearance {
if let IcedButton::Custom { active, .. } = style {
2022-12-17 18:15:24 -05:00
return active(self);
}
2022-12-19 17:03:13 +01:00
2023-08-04 17:19:30 -04:00
let corner_radii = &self.cosmic().corner_radii;
let component = style.cosmic(self);
iced_button::Appearance {
2022-12-20 16:02:44 -07:00
border_radius: match style {
IcedButton::Link => corner_radii.radius_0.into(),
IcedButton::Card => corner_radii.radius_xs.into(),
2023-08-04 17:19:30 -04:00
_ => corner_radii.radius_xl.into(),
2022-12-20 16:02:44 -07:00
},
background: match style {
IcedButton::Link | IcedButton::Text => None,
IcedButton::LinkActive => Some(Background::Color(component.divider.into())),
_ => Some(Background::Color(component.base.into())),
},
2022-12-20 16:02:44 -07:00
text_color: match style {
IcedButton::Link | IcedButton::LinkActive => component.base.into(),
_ => component.on.into(),
2022-12-20 16:02:44 -07:00
},
..iced_button::Appearance::default()
}
}
fn hovered(&self, style: &Self::Style) -> iced_button::Appearance {
if let IcedButton::Custom { hover, .. } = style {
2022-12-17 18:15:24 -05:00
return hover(self);
}
2022-12-19 17:03:13 +01:00
2022-12-23 15:10:13 +01:00
let active = self.active(style);
let component = style.cosmic(self);
iced_button::Appearance {
2022-12-20 16:02:44 -07:00
background: match style {
IcedButton::Link => None,
IcedButton::LinkActive => Some(Background::Color(component.divider.into())),
_ => Some(Background::Color(component.hover.into())),
2022-12-20 16:02:44 -07:00
},
..active
}
}
2023-01-05 11:29:14 -07:00
fn focused(&self, style: &Self::Style) -> iced_button::Appearance {
if let IcedButton::Custom { hover, .. } = style {
2023-01-05 11:29:14 -07:00
return hover(self);
}
let active = self.active(style);
let component = style.cosmic(self);
iced_button::Appearance {
2023-01-05 11:29:14 -07:00
background: match style {
IcedButton::Link => None,
IcedButton::LinkActive => Some(Background::Color(component.divider.into())),
_ => Some(Background::Color(component.hover.into())),
2023-01-05 11:29:14 -07:00
},
..active
}
}
2023-07-17 11:44:57 -04:00
fn disabled(&self, style: &Self::Style) -> iced_button::Appearance {
2023-07-17 11:44:57 -04:00
let active = self.active(style);
if matches!(style, IcedButton::Card) {
2023-07-17 11:44:57 -04:00
return active;
}
iced_button::Appearance {
2023-07-17 11:44:57 -04:00
shadow_offset: iced_core::Vector::default(),
background: active.background.map(|background| match background {
Background::Color(color) => Background::Color(Color {
a: color.a * 0.5,
..color
}),
Background::Gradient(gradient) => Background::Gradient(gradient.mul_alpha(0.5)),
}),
text_color: Color {
a: active.text_color.a * 0.5,
..active.text_color
},
..active
}
}
}
/*
* TODO: Checkbox
*/
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Checkbox {
Primary,
Secondary,
Success,
Danger,
}
impl Default for Checkbox {
fn default() -> Self {
Self::Primary
}
}
impl checkbox::StyleSheet for Theme {
type Style = Checkbox;
2023-01-03 21:35:35 +01:00
fn active(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
let cosmic = self.cosmic();
let corners = &cosmic.corner_radii;
match style {
2023-02-27 17:42:17 -05:00
Checkbox::Primary => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.accent.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.accent.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.accent.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
Checkbox::Secondary => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.background.component.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.background.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.background.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: cosmic.button.border.into(),
2023-02-27 17:42:17 -05:00
text_color: None,
},
Checkbox::Success => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.success.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.success.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.success.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
Checkbox::Danger => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.destructive.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.destructive.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.destructive.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
}
}
2023-01-03 21:35:35 +01:00
fn hovered(&self, style: &Self::Style, is_checked: bool) -> checkbox::Appearance {
let cosmic = self.cosmic();
let corners = &cosmic.corner_radii;
match style {
2023-02-27 17:42:17 -05:00
Checkbox::Primary => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.accent.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.accent.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.accent.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
Checkbox::Secondary => checkbox::Appearance {
background: Background::Color(if is_checked {
2023-02-27 19:56:53 -05:00
self.current_container().base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
2023-02-27 19:56:53 -05:00
self.current_container().base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
Checkbox::Success => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.success.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.success.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.success.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
Checkbox::Danger => checkbox::Appearance {
background: Background::Color(if is_checked {
cosmic.destructive.base.into()
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.base.into()
2023-02-27 17:42:17 -05:00
}),
icon_color: cosmic.destructive.on.into(),
border_radius: corners.radius_xs.into(),
2023-02-27 17:42:17 -05:00
border_width: if is_checked { 0.0 } else { 1.0 },
border_color: if is_checked {
cosmic.destructive.base
2023-02-27 17:42:17 -05:00
} else {
cosmic.button.border
2023-02-27 17:42:17 -05:00
}
.into(),
text_color: None,
},
}
}
}
#[derive(Default)]
pub enum Expander {
#[default]
Default,
Custom(Box<dyn Fn(&Theme) -> expander::Appearance>),
}
impl Expander {
pub fn custom<F: Fn(&Theme) -> expander::Appearance + 'static>(f: F) -> Self {
Self::Custom(Box::new(f))
}
}
impl expander::StyleSheet for Theme {
type Style = Expander;
fn appearance(&self, style: Self::Style) -> expander::Appearance {
match style {
Expander::Default => expander::Appearance::default(),
Expander::Custom(f) => f(self),
}
}
}
/*
* TODO: Container
*/
#[derive(Default)]
pub enum Container {
2023-02-22 14:06:09 -05:00
Background,
Primary,
Secondary,
#[default]
Transparent,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
HeaderBar,
Custom(Box<dyn Fn(&Theme) -> container::Appearance>),
2023-07-17 11:44:57 -04:00
Card,
}
impl Container {
pub fn custom<F: Fn(&Theme) -> container::Appearance + 'static>(f: F) -> Self {
Self::Custom(Box::new(f))
}
}
impl container::StyleSheet for Theme {
type Style = Container;
2022-11-10 16:19:13 +01:00
fn appearance(&self, style: &Self::Style) -> container::Appearance {
match style {
Container::Transparent => container::Appearance::default(),
2023-02-22 14:06:09 -05:00
Container::Custom(f) => f(self),
Container::Background => {
let palette = self.cosmic();
container::Appearance {
icon_color: Some(Color::from(palette.background.on)),
text_color: Some(Color::from(palette.background.on)),
2023-02-22 14:06:09 -05:00
background: Some(iced::Background::Color(palette.background.base.into())),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
Container::HeaderBar => {
let palette = self.cosmic();
2023-06-15 11:16:32 -04:00
let mut header_top = palette.background.base;
let header_bottom = palette.background.base;
header_top.alpha = 0.8;
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
container::Appearance {
icon_color: Some(Color::from(palette.accent.base)),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
text_color: Some(Color::from(palette.background.on)),
2023-06-15 11:16:32 -04:00
background: Some(iced::Background::Gradient(iced_core::Gradient::Linear(
Linear::new(Radians(3.0 * PI / 2.0))
.add_stop(0.0, header_top.into())
.add_stop(1.0, header_bottom.into()),
))),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
border_radius: BorderRadius::from([16.0, 16.0, 0.0, 0.0]),
2023-02-22 14:06:09 -05:00
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
Container::Primary => {
let palette = self.cosmic();
container::Appearance {
icon_color: Some(Color::from(palette.primary.on)),
text_color: Some(Color::from(palette.primary.on)),
2023-02-22 14:06:09 -05:00
background: Some(iced::Background::Color(palette.primary.base.into())),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
border_radius: 2.0.into(),
2023-02-22 14:06:09 -05:00
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
Container::Secondary => {
let palette = self.cosmic();
container::Appearance {
icon_color: Some(Color::from(palette.secondary.on)),
text_color: Some(Color::from(palette.secondary.on)),
2023-02-22 14:06:09 -05:00
background: Some(iced::Background::Color(palette.secondary.base.into())),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
border_radius: 2.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
2023-07-17 11:44:57 -04:00
Container::Card => {
let palette = self.cosmic();
match self.layer {
cosmic_theme::Layer::Background => container::Appearance {
icon_color: Some(Color::from(palette.background.component.on)),
2023-07-17 11:44:57 -04:00
text_color: Some(Color::from(palette.background.component.on)),
background: Some(iced::Background::Color(
palette.background.component.base.into(),
)),
border_radius: 8.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
cosmic_theme::Layer::Primary => container::Appearance {
icon_color: Some(Color::from(palette.primary.component.on)),
2023-07-17 11:44:57 -04:00
text_color: Some(Color::from(palette.primary.component.on)),
background: Some(iced::Background::Color(
palette.primary.component.base.into(),
)),
border_radius: 8.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
cosmic_theme::Layer::Secondary => container::Appearance {
icon_color: Some(Color::from(palette.secondary.component.on)),
2023-07-17 11:44:57 -04:00
text_color: Some(Color::from(palette.secondary.component.on)),
background: Some(iced::Background::Color(
palette.secondary.component.base.into(),
)),
border_radius: 8.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
}
}
}
}
}
/*
* Slider
*/
impl slider::StyleSheet for Theme {
type Style = ();
2022-11-10 16:19:13 +01:00
fn active(&self, _style: &Self::Style) -> slider::Appearance {
let cosmic = self.cosmic();
//TODO: no way to set rail thickness
slider::Appearance {
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
rail: Rail {
colors: (
cosmic.accent.base.into(),
//TODO: no way to set color before/after slider
Color::TRANSPARENT,
),
width: 4.0,
2023-06-15 11:16:32 -04:00
border_radius: 2.0.into(),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
},
handle: slider::Handle {
2022-11-11 05:06:54 +01:00
shape: slider::HandleShape::Circle { radius: 10.0 },
color: cosmic.accent.base.into(),
border_color: Color::TRANSPARENT,
border_width: 0.0,
2022-11-11 05:06:54 +01:00
},
}
}
2022-11-10 16:19:13 +01:00
fn hovered(&self, style: &Self::Style) -> slider::Appearance {
2022-12-23 15:10:13 +01:00
let mut style = self.active(style);
2023-01-03 21:35:35 +01:00
style.handle.shape = slider::HandleShape::Circle { radius: 16.0 };
style.handle.border_width = 6.0;
2023-02-27 19:56:53 -05:00
let mut border_color = self.cosmic().palette.neutral_10;
2023-02-27 17:42:17 -05:00
border_color.alpha = 0.1;
style.handle.border_color = border_color.into();
style
}
2022-11-10 16:19:13 +01:00
fn dragging(&self, style: &Self::Style) -> slider::Appearance {
2022-12-23 15:10:13 +01:00
let mut style = self.hovered(style);
2023-02-27 19:56:53 -05:00
let mut border_color = self.cosmic().palette.neutral_10;
2023-02-27 17:42:17 -05:00
border_color.alpha = 0.2;
style.handle.border_color = border_color.into();
style
}
}
/*
* TODO: Menu
*/
impl menu::StyleSheet for Theme {
type Style = ();
2022-11-10 16:19:13 +01:00
fn appearance(&self, _style: &Self::Style) -> menu::Appearance {
let cosmic = self.cosmic();
menu::Appearance {
2023-02-27 17:42:17 -05:00
text_color: cosmic.on_bg_color().into(),
background: Background::Color(cosmic.background.base.into()),
border_width: 0.0,
2023-06-15 11:16:32 -04:00
border_radius: 16.0.into(),
border_color: Color::TRANSPARENT,
2023-02-27 17:42:17 -05:00
selected_text_color: cosmic.on_bg_color().into(),
// TODO doesn't seem to be specified
selected_background: Background::Color(cosmic.background.component.hover.into()),
}
}
}
/*
* TODO: Pick List
*/
impl pick_list::StyleSheet for Theme {
type Style = ();
2022-11-10 16:19:13 +01:00
fn active(&self, _style: &()) -> pick_list::Appearance {
let cosmic = &self.cosmic();
pick_list::Appearance {
2023-02-27 17:42:17 -05:00
text_color: cosmic.on_bg_color().into(),
background: Color::TRANSPARENT.into(),
2023-02-27 17:42:17 -05:00
placeholder_color: cosmic.on_bg_color().into(),
2023-06-15 11:16:32 -04:00
border_radius: 24.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
// icon_size: 0.7, // TODO: how to replace
handle_color: cosmic.on_bg_color().into(),
}
}
2022-11-10 16:19:13 +01:00
fn hovered(&self, style: &()) -> pick_list::Appearance {
2023-02-27 17:42:17 -05:00
let cosmic = &self.cosmic();
pick_list::Appearance {
2023-02-27 17:42:17 -05:00
background: Background::Color(cosmic.background.base.into()),
2022-12-23 15:10:13 +01:00
..self.active(style)
}
}
}
/*
* TODO: Radio
*/
impl radio::StyleSheet for Theme {
type Style = ();
2023-02-22 14:06:09 -05:00
fn active(&self, _style: &Self::Style, is_selected: bool) -> radio::Appearance {
let theme = self.cosmic();
radio::Appearance {
2023-02-22 14:06:09 -05:00
background: if is_selected {
Color::from(theme.accent.base).into()
} else {
// TODO: this seems to be defined weirdly in FIGMA
2023-02-27 17:42:17 -05:00
Color::from(theme.background.base).into()
2023-02-22 14:06:09 -05:00
},
dot_color: theme.accent.on.into(),
border_width: 1.0,
2023-02-27 17:42:17 -05:00
border_color: if is_selected {
2023-02-27 18:45:54 -05:00
Color::from(theme.accent.base)
2023-02-27 17:42:17 -05:00
} else {
// TODO: this seems to be defined weirdly in FIGMA
2023-02-27 18:45:54 -05:00
Color::from(theme.palette.neutral_7)
2023-02-27 17:42:17 -05:00
},
text_color: None,
}
}
2023-02-27 18:45:54 -05:00
fn hovered(&self, _style: &Self::Style, is_selected: bool) -> radio::Appearance {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
2023-02-27 18:45:54 -05:00
let mut neutral_10 = theme.palette.neutral_10;
2023-02-27 17:42:17 -05:00
neutral_10.alpha = 0.1;
radio::Appearance {
2023-02-22 14:06:09 -05:00
background: if is_selected {
2023-02-27 17:42:17 -05:00
Color::from(theme.accent.base).into()
2023-02-22 14:06:09 -05:00
} else {
// TODO: this seems to be defined weirdly in FIGMA
2023-02-27 17:42:17 -05:00
Color::from(neutral_10).into()
2023-02-22 14:06:09 -05:00
},
2023-02-27 17:42:17 -05:00
dot_color: theme.accent.on.into(),
border_width: 1.0,
border_color: if is_selected {
2023-02-27 18:45:54 -05:00
Color::from(theme.accent.base)
2023-02-27 17:42:17 -05:00
} else {
// TODO: this seems to be defined weirdly in FIGMA
2023-02-27 18:45:54 -05:00
Color::from(theme.palette.neutral_7)
2023-02-27 17:42:17 -05:00
},
text_color: None,
}
}
}
/*
* Toggler
*/
impl toggler::StyleSheet for Theme {
type Style = ();
2023-01-03 21:35:35 +01:00
fn active(&self, _style: &Self::Style, is_active: bool) -> toggler::Appearance {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
toggler::Appearance {
background: if is_active {
2023-02-22 14:06:09 -05:00
theme.accent.base.into()
} else {
2023-02-22 14:06:09 -05:00
theme.palette.neutral_5.into()
},
background_border: None,
2023-02-22 14:06:09 -05:00
foreground: theme.palette.neutral_2.into(),
foreground_border: None,
}
}
2023-01-03 21:35:35 +01:00
fn hovered(&self, style: &Self::Style, is_active: bool) -> toggler::Appearance {
2023-02-27 17:42:17 -05:00
let cosmic = self.cosmic();
//TODO: grab colors from palette
2023-02-27 18:45:54 -05:00
let mut neutral_10 = cosmic.palette.neutral_10;
2023-02-27 17:42:17 -05:00
neutral_10.alpha = 0.1;
2023-08-07 16:03:44 -04:00
2023-02-27 17:42:17 -05:00
toggler::Appearance {
background: if is_active {
2023-08-07 16:03:44 -04:00
over(neutral_10, cosmic.accent_color())
2023-02-27 17:42:17 -05:00
} else {
2023-08-07 16:03:44 -04:00
over(neutral_10, cosmic.palette.neutral_5)
2023-02-27 17:42:17 -05:00
}
.into(),
..self.active(style, is_active)
}
}
}
/*
* TODO: Pane Grid
*/
impl pane_grid::StyleSheet for Theme {
type Style = ();
2022-11-10 16:19:13 +01:00
fn picked_split(&self, _style: &Self::Style) -> Option<pane_grid::Line> {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
Some(pane_grid::Line {
2023-02-22 14:06:09 -05:00
color: theme.accent.base.into(),
width: 2.0,
})
}
2022-11-10 16:19:13 +01:00
fn hovered_split(&self, _style: &Self::Style) -> Option<pane_grid::Line> {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
Some(pane_grid::Line {
2023-02-22 14:06:09 -05:00
color: theme.accent.hover.into(),
width: 2.0,
})
}
2023-06-15 11:16:32 -04:00
2023-07-17 11:44:57 -04:00
fn hovered_region(&self, _style: &Self::Style) -> pane_grid::Appearance {
2023-06-15 11:16:32 -04:00
let theme = self.cosmic();
pane_grid::Appearance {
background: Background::Color(theme.bg_color().into()),
border_width: 2.0,
border_color: theme.bg_divider().into(),
border_radius: 0.0.into(),
}
}
}
/*
* TODO: Progress Bar
*/
#[derive(Default)]
pub enum ProgressBar {
#[default]
Primary,
Success,
Danger,
Custom(Box<dyn Fn(&Theme) -> progress_bar::Appearance>),
}
impl ProgressBar {
pub fn custom<F: Fn(&Theme) -> progress_bar::Appearance + 'static>(f: F) -> Self {
Self::Custom(Box::new(f))
}
}
impl progress_bar::StyleSheet for Theme {
type Style = ProgressBar;
2022-11-10 16:19:13 +01:00
fn appearance(&self, style: &Self::Style) -> progress_bar::Appearance {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
match style {
ProgressBar::Primary => progress_bar::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(theme.background.divider).into(),
bar: Color::from(theme.accent.base).into(),
2023-06-15 11:16:32 -04:00
border_radius: 2.0.into(),
},
ProgressBar::Success => progress_bar::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(theme.background.divider).into(),
bar: Color::from(theme.success.base).into(),
2023-06-15 11:16:32 -04:00
border_radius: 2.0.into(),
},
ProgressBar::Danger => progress_bar::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(theme.background.divider).into(),
bar: Color::from(theme.destructive.base).into(),
2023-06-15 11:16:32 -04:00
border_radius: 2.0.into(),
},
ProgressBar::Custom(f) => f(self),
}
}
}
/*
* TODO: Rule
*/
#[derive(Default)]
pub enum Rule {
#[default]
Default,
LightDivider,
HeavyDivider,
Custom(Box<dyn Fn(&Theme) -> rule::Appearance>),
}
impl Rule {
pub fn custom<F: Fn(&Theme) -> rule::Appearance + 'static>(f: F) -> Self {
Self::Custom(Box::new(f))
}
}
impl rule::StyleSheet for Theme {
type Style = Rule;
2022-11-10 16:19:13 +01:00
fn appearance(&self, style: &Self::Style) -> rule::Appearance {
match style {
Rule::Default => rule::Appearance {
2023-02-27 19:56:53 -05:00
color: self.current_container().divider.into(),
width: 1,
2023-06-15 11:16:32 -04:00
radius: 0.0.into(),
fill_mode: rule::FillMode::Full,
},
2023-02-27 19:56:53 -05:00
Rule::LightDivider => rule::Appearance {
color: self.current_container().divider.into(),
width: 1,
2023-06-15 11:16:32 -04:00
radius: 0.0.into(),
2023-02-27 19:56:53 -05:00
fill_mode: rule::FillMode::Padded(10),
},
Rule::HeavyDivider => rule::Appearance {
color: self.current_container().divider.into(),
width: 4,
2023-06-15 11:16:32 -04:00
radius: 4.0.into(),
2023-02-27 19:56:53 -05:00
fill_mode: rule::FillMode::Full,
},
Rule::Custom(f) => f(self),
}
}
}
/*
* TODO: Scrollable
*/
impl scrollable::StyleSheet for Theme {
type Style = ();
2022-11-10 16:19:13 +01:00
fn active(&self, _style: &Self::Style) -> scrollable::Scrollbar {
scrollable::Scrollbar {
2023-02-27 17:42:17 -05:00
background: Some(Background::Color(
2023-02-27 19:56:53 -05:00
self.current_container().component.base.into(),
2023-02-27 17:42:17 -05:00
)),
2023-06-15 11:16:32 -04:00
border_radius: 4.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller {
2023-02-27 19:56:53 -05:00
color: self.current_container().component.divider.into(),
2023-06-15 11:16:32 -04:00
border_radius: 4.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
}
}
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
fn hovered(
&self,
_style: &Self::Style,
_is_mouse_over_scrollbar: bool,
) -> scrollable::Scrollbar {
2023-02-22 14:06:09 -05:00
let theme = self.cosmic();
scrollable::Scrollbar {
2023-02-27 17:42:17 -05:00
background: Some(Background::Color(
2023-02-27 19:56:53 -05:00
self.current_container().component.hover.into(),
2023-02-27 17:42:17 -05:00
)),
2023-06-15 11:16:32 -04:00
border_radius: 4.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller {
2023-02-22 14:06:09 -05:00
color: theme.accent.base.into(),
2023-06-15 11:16:32 -04:00
border_radius: 4.0.into(),
border_width: 0.0,
border_color: Color::TRANSPARENT,
},
}
}
}
#[derive(Clone, Default)]
pub enum Svg {
/// Apply a custom appearance filter
Custom(Rc<dyn Fn(&Theme) -> svg::Appearance>),
/// No filtering is applied
#[default]
Default,
}
impl Svg {
pub fn custom<F: Fn(&Theme) -> svg::Appearance + 'static>(f: F) -> Self {
Self::Custom(Rc::new(f))
}
}
impl svg::StyleSheet for Theme {
type Style = Svg;
2022-12-19 17:03:13 +01:00
fn appearance(&self, style: &Self::Style) -> svg::Appearance {
2022-12-23 15:10:13 +01:00
#[allow(clippy::match_same_arms)]
match style {
Svg::Default => svg::Appearance::default(),
Svg::Custom(appearance) => appearance(self),
}
}
}
/*
* TODO: Text
*/
2022-11-01 18:13:00 +01:00
#[derive(Clone, Copy, Default)]
pub enum Text {
2022-11-01 18:13:00 +01:00
Accent,
#[default]
Default,
Color(Color),
// TODO: Can't use dyn Fn since this must be copy
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
Custom(fn(&Theme) -> iced_widget::text::Appearance),
}
impl From<Color> for Text {
fn from(color: Color) -> Self {
Text::Color(color)
}
}
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
impl iced_widget::text::StyleSheet for Theme {
type Style = Text;
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
fn appearance(&self, style: Self::Style) -> iced_widget::text::Appearance {
match style {
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
Text::Accent => iced_widget::text::Appearance {
2022-11-11 05:06:54 +01:00
color: Some(self.cosmic().accent.base.into()),
2022-11-01 18:13:00 +01:00
},
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
Text::Default => iced_widget::text::Appearance { color: None },
Text::Color(c) => iced_widget::text::Appearance { color: Some(c) },
Text::Custom(f) => f(self),
}
}
}
2023-01-25 04:12:56 +01:00
#[derive(Copy, Clone, Default)]
pub enum TextInput {
#[default]
Default,
Search,
}
/*
* TODO: Text Input
*/
impl text_input::StyleSheet for Theme {
2023-01-25 04:12:56 +01:00
type Style = TextInput;
2023-01-25 04:12:56 +01:00
fn active(&self, style: &Self::Style) -> text_input::Appearance {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
let mut bg = palette.palette.neutral_7;
bg.alpha = 0.25;
2023-01-25 04:12:56 +01:00
match style {
TextInput::Default => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 8.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 1.0,
2023-02-27 19:56:53 -05:00
border_color: self.current_container().component.divider.into(),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
TextInput::Search => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 24.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 0.0,
border_color: Color::TRANSPARENT,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
}
}
2023-01-25 04:12:56 +01:00
fn hovered(&self, style: &Self::Style) -> text_input::Appearance {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
let mut bg = palette.palette.neutral_7;
bg.alpha = 0.25;
2023-01-25 04:12:56 +01:00
match style {
TextInput::Default => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 8.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 1.0,
2023-02-27 17:42:17 -05:00
border_color: palette.accent.base.into(),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
TextInput::Search => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 24.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 0.0,
border_color: Color::TRANSPARENT,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
}
}
2023-01-25 04:12:56 +01:00
fn focused(&self, style: &Self::Style) -> text_input::Appearance {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
let mut bg = palette.palette.neutral_7;
bg.alpha = 0.25;
2023-01-25 04:12:56 +01:00
match style {
TextInput::Default => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 8.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 1.0,
2023-02-22 14:06:09 -05:00
border_color: palette.accent.base.into(),
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
TextInput::Search => text_input::Appearance {
2023-02-27 17:42:17 -05:00
background: Color::from(bg).into(),
2023-06-15 11:16:32 -04:00
border_radius: 24.0.into(),
2023-01-25 04:12:56 +01:00
border_width: 0.0,
border_color: Color::TRANSPARENT,
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
icon_color: self.current_container().on.into(),
2023-01-25 04:12:56 +01:00
},
}
}
2022-11-10 16:19:13 +01:00
fn placeholder_color(&self, _style: &Self::Style) -> Color {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
let mut neutral_9 = palette.palette.neutral_9;
neutral_9.alpha = 0.7;
neutral_9.into()
}
2022-11-10 16:19:13 +01:00
fn value_color(&self, _style: &Self::Style) -> Color {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
palette.palette.neutral_9.into()
}
2022-11-10 16:19:13 +01:00
fn selection_color(&self, _style: &Self::Style) -> Color {
2023-02-22 14:06:09 -05:00
let palette = self.cosmic();
2023-02-27 17:42:17 -05:00
palette.accent.base.into()
}
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
fn disabled_color(&self, _style: &Self::Style) -> Color {
let palette = self.cosmic();
let mut neutral_9 = palette.palette.neutral_9;
neutral_9.alpha = 0.5;
neutral_9.into()
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
}
fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
self.active(style)
Cosmic advanced text (#103) * wip: update to use cosmic-advanced-text * use cosmic-advanced-text branch of iced * fix: line height and spacing for segmented button and update to get svg fix * fix: spin button styling & spacing * update iced to fix segmented button border radius * feat: example improvements * feat: helper for loading fonts * feat: add focus style to button * fix: slider height and iced fixed * feat: hash icon width and height * cleanup * update ci * refactor: always use lazy feature of iced * update iced * update iced * cleanup & update iced * update iced: new slider & tiny-skia quad updates * update iced: fixes for tiny-skia quad rendering with edge case border radius * re-export iced_runtime & iced_widget * merge master * udpate iced * update iced * update iced * update iced * fix: make rectangle_tracker subscription only return update if there is some * feat: derive macro for loading a cosmic-config * feat (cosmic-config): iced subscription * fix (example): update to rectangle tracker subscription * fix (cosmic-config) * refactor(cosmic-config-derive): add support for types with generic parameters * fix (cosmic-config): feature gate updates for subscription helpers * feat: support for custom & system themes + move cosmic-theme to libcosmic * feat: sorta hacky way of creating header bars for libcosmic + update iced to get support for resizable windows in iced-sctk * update iced * update and reexport sctk * fix: applet border radius * feat (cosmic-theme): add id and name methods * fix(cosmic-theme): reexport palette from cosmic-theme * fix(cosmic-config-derive): allow use with reexported cosmic-config * feat: update iced with fix and refactor applet env vars * update iced
2023-05-30 12:03:15 -04:00
}
}
2023-06-12 12:08:14 -04:00
2023-08-03 19:30:08 -04:00
#[must_use]
2023-06-12 12:08:14 -04:00
pub fn theme() -> Theme {
let Ok(helper) = crate::cosmic_config::Config::new(
crate::cosmic_theme::NAME,
crate::cosmic_theme::Theme::<CssColor>::version(),
) else {
return crate::theme::Theme::dark();
};
2023-08-03 19:30:08 -04:00
let t = crate::cosmic_theme::Theme::get_entry(&helper).unwrap_or_else(|(errors, theme)| {
for err in errors {
tracing::error!("{:?}", err);
}
theme
});
crate::theme::Theme::system(Arc::new(t))
2023-06-12 12:08:14 -04:00
}
2023-08-02 11:54:07 +02:00
pub fn subscription(id: u64) -> Subscription<crate::theme::Theme> {
2023-08-03 19:30:08 -04:00
config_subscription::<u64, crate::cosmic_theme::Theme<Srgba>>(
2023-06-12 12:08:14 -04:00
id,
crate::cosmic_theme::NAME.into(),
2023-08-03 19:30:08 -04:00
crate::cosmic_theme::Theme::<Srgba>::version(),
2023-06-12 12:08:14 -04:00
)
.map(|(_, res)| {
2023-08-03 19:30:08 -04:00
let theme = res.unwrap_or_else(|(errors, theme)| {
for err in errors {
tracing::error!("{:?}", err);
}
theme
});
crate::theme::Theme::system(Arc::new(theme))
2023-06-12 12:08:14 -04:00
})
}
2023-07-17 11:44:57 -04:00
impl crate::widget::card::style::StyleSheet for Theme {
fn default(&self) -> crate::widget::card::style::Appearance {
let cosmic = self.cosmic();
match self.layer {
cosmic_theme::Layer::Background => crate::widget::card::style::Appearance {
card_1: Background::Color(cosmic.background.component.hover.into()),
card_2: Background::Color(cosmic.background.component.pressed.into()),
},
cosmic_theme::Layer::Primary => crate::widget::card::style::Appearance {
card_1: Background::Color(cosmic.primary.component.hover.into()),
card_2: Background::Color(cosmic.primary.component.pressed.into()),
},
cosmic_theme::Layer::Secondary => crate::widget::card::style::Appearance {
card_1: Background::Color(cosmic.secondary.component.hover.into()),
card_2: Background::Color(cosmic.secondary.component.pressed.into()),
},
}
}
}