Centralize native palettes, presets, typography, controls, menus, calendar rendering, and icon assets in ferese-theme. Reuse the shared components across the shell, settings, lock screen, authentication prompt, and screen-sharing chooser. Attach themed dialogs to compositor-owned materials, correct backdrop capture and sampling across output transforms, smooth patterned backgrounds, and prevent clipped picker buttons with the configured shell font.
54 lines
1.7 KiB
Rust
54 lines
1.7 KiB
Rust
use crate::{composite, foreground};
|
|
use cosmic::{
|
|
iced::{Background, Color},
|
|
theme,
|
|
widget::button,
|
|
};
|
|
|
|
#[derive(Clone, Copy)]
|
|
pub(crate) enum State {
|
|
Active,
|
|
Hovered,
|
|
Pressed,
|
|
Disabled,
|
|
}
|
|
|
|
pub(crate) fn accent_button_style(
|
|
theme: &cosmic::Theme,
|
|
state: State,
|
|
focused: bool,
|
|
) -> button::Style {
|
|
let native = theme.cosmic();
|
|
let component = &native.accent_button;
|
|
let fill: Color = match state {
|
|
State::Active => component.base.into(),
|
|
State::Hovered => component.hover.into(),
|
|
State::Pressed => component.pressed.into(),
|
|
State::Disabled => Color {
|
|
a: 0.5,
|
|
..component.base.into()
|
|
},
|
|
};
|
|
let background = composite(fill, native.primary(false).base.into());
|
|
let foreground = foreground(background, component.on.into());
|
|
button::Style {
|
|
background: Some(Background::Color(background)),
|
|
text_color: Some(foreground),
|
|
icon_color: Some(foreground),
|
|
border_radius: native.corner_radii.radius_xl.into(),
|
|
outline_width: if focused { 1. } else { 0. },
|
|
outline_color: foreground,
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
/// Filled accent buttons and selected rows share this per-state contrast policy.
|
|
pub fn accent_button() -> theme::Button {
|
|
theme::Button::Custom {
|
|
active: Box::new(|focused, theme| accent_button_style(theme, State::Active, focused)),
|
|
hovered: Box::new(|focused, theme| accent_button_style(theme, State::Hovered, focused)),
|
|
pressed: Box::new(|focused, theme| accent_button_style(theme, State::Pressed, focused)),
|
|
disabled: Box::new(|theme| accent_button_style(theme, State::Disabled, false)),
|
|
}
|
|
}
|