feat: Themable SVGs, applied to window controls
This commit is contained in:
parent
947532413a
commit
4a899189e6
4 changed files with 35 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ use iced_style::radio;
|
|||
use iced_style::rule;
|
||||
use iced_style::scrollable;
|
||||
use iced_style::slider;
|
||||
use iced_style::svg;
|
||||
use iced_style::text;
|
||||
use iced_style::text_input;
|
||||
use iced_style::toggler;
|
||||
|
|
@ -665,6 +666,31 @@ impl scrollable::StyleSheet for Theme {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default, Clone, Copy)]
|
||||
pub enum Svg {
|
||||
Custom(fn(&Theme) -> svg::Appearance),
|
||||
#[default]
|
||||
Default,
|
||||
Accent,
|
||||
}
|
||||
|
||||
impl svg::StyleSheet for Theme {
|
||||
type Style = Svg;
|
||||
|
||||
fn appearance(&self, style: Self::Style) -> svg::Appearance {
|
||||
let cosmic = self.cosmic();
|
||||
|
||||
match style {
|
||||
Svg::Default => Default::default(),
|
||||
Svg::Custom(appearance) => appearance(self),
|
||||
Svg::Accent => svg::Appearance {
|
||||
fill: Some(cosmic.accent.base.into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Text
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -108,8 +108,9 @@ impl<Message: Clone> Component<Message, Renderer> for HeaderBar<Message> {
|
|||
|
||||
let icon = |name, size, on_press| {
|
||||
super::icon(name, size)
|
||||
.style(crate::theme::Svg::Accent)
|
||||
.apply(widget::button)
|
||||
.style(theme::Button::Primary)
|
||||
.style(theme::Button::Text)
|
||||
.on_press(on_press)
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
use iced::{widget::svg, Length};
|
||||
|
||||
pub fn icon(name: &str, size: u16) -> svg::Svg {
|
||||
pub fn icon<Renderer>(name: &str, size: u16) -> svg::Svg<Renderer>
|
||||
where
|
||||
Renderer: iced_native::svg::Renderer,
|
||||
Renderer::Theme: iced_native::svg::StyleSheet,
|
||||
{
|
||||
let handle = match freedesktop_icons::lookup(name)
|
||||
.with_size(size)
|
||||
.with_theme("Pop")
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@ where
|
|||
<<Renderer as iced_native::Renderer>::Theme as container::StyleSheet>::Style:
|
||||
From<theme::Container>,
|
||||
<<Renderer as iced_native::Renderer>::Theme as text::StyleSheet>::Style: From<theme::Text>,
|
||||
Renderer::Theme: iced_native::svg::StyleSheet
|
||||
{
|
||||
type State = NavBarState;
|
||||
type Event = NavBarEvent;
|
||||
|
|
@ -231,6 +232,7 @@ where
|
|||
<<Renderer as iced_native::Renderer>::Theme as container::StyleSheet>::Style:
|
||||
From<theme::Container>,
|
||||
<<Renderer as iced_native::Renderer>::Theme as text::StyleSheet>::Style: From<theme::Text>,
|
||||
Renderer::Theme: iced_native::svg::StyleSheet
|
||||
{
|
||||
fn from(nav_bar: NavBar<'a, Message>) -> Self {
|
||||
iced_lazy::component(nav_bar)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue