refactor(theme): create Container::ContextDrawer style variant
This commit is contained in:
parent
88da3fcc14
commit
db5d989972
4 changed files with 82 additions and 59 deletions
|
|
@ -238,7 +238,6 @@ impl Theme {
|
|||
|
||||
/// get current container
|
||||
/// can be used in a component that is intended to be a child of a `CosmicContainer`
|
||||
#[must_use]
|
||||
pub fn current_container(&self) -> &cosmic_theme::Container {
|
||||
match self.layer {
|
||||
cosmic_theme::Layer::Background => &self.cosmic().background,
|
||||
|
|
|
|||
|
|
@ -369,6 +369,7 @@ pub enum Container {
|
|||
WindowBackground,
|
||||
Background,
|
||||
Card,
|
||||
ContextDrawer,
|
||||
Custom(Box<dyn Fn(&Theme) -> container::Appearance>),
|
||||
Dialog,
|
||||
Dropdown,
|
||||
|
|
@ -384,6 +385,48 @@ impl Container {
|
|||
pub fn custom<F: Fn(&Theme) -> container::Appearance + 'static>(f: F) -> Self {
|
||||
Self::Custom(Box::new(f))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn background(theme: &cosmic_theme::Theme) -> container::Appearance {
|
||||
container::Appearance {
|
||||
icon_color: Some(Color::from(theme.background.on)),
|
||||
text_color: Some(Color::from(theme.background.on)),
|
||||
background: Some(iced::Background::Color(theme.background.base.into())),
|
||||
border: Border {
|
||||
radius: theme.corner_radii.radius_xs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn primary(theme: &cosmic_theme::Theme) -> container::Appearance {
|
||||
container::Appearance {
|
||||
icon_color: Some(Color::from(theme.primary.on)),
|
||||
text_color: Some(Color::from(theme.primary.on)),
|
||||
background: Some(iced::Background::Color(theme.primary.base.into())),
|
||||
border: Border {
|
||||
radius: theme.corner_radii.radius_xs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn secondary(theme: &cosmic_theme::Theme) -> container::Appearance {
|
||||
container::Appearance {
|
||||
icon_color: Some(Color::from(theme.secondary.on)),
|
||||
text_color: Some(Color::from(theme.secondary.on)),
|
||||
background: Some(iced::Background::Color(theme.secondary.base.into())),
|
||||
border: Border {
|
||||
radius: theme.corner_radii.radius_xs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl container::StyleSheet for Theme {
|
||||
|
|
@ -394,7 +437,9 @@ impl container::StyleSheet for Theme {
|
|||
let cosmic = self.cosmic();
|
||||
match style {
|
||||
Container::Transparent => container::Appearance::default(),
|
||||
|
||||
Container::Custom(f) => f(self),
|
||||
|
||||
Container::WindowBackground => container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.background.on)),
|
||||
text_color: Some(Color::from(cosmic.background.on)),
|
||||
|
|
@ -411,56 +456,48 @@ impl container::StyleSheet for Theme {
|
|||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
Container::Background => container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.background.on)),
|
||||
|
||||
Container::HeaderBar => container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.accent.base)),
|
||||
text_color: Some(Color::from(cosmic.background.on)),
|
||||
background: Some(iced::Background::Color(cosmic.background.base.into())),
|
||||
border: Border {
|
||||
radius: cosmic.corner_radii.radius_xs.into(),
|
||||
radius: [
|
||||
cosmic.corner_radii.radius_xs[0],
|
||||
cosmic.corner_radii.radius_xs[1],
|
||||
cosmic.corner_radii.radius_0[2],
|
||||
cosmic.corner_radii.radius_0[3],
|
||||
]
|
||||
.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
Container::HeaderBar => {
|
||||
let header_top = cosmic.background.base;
|
||||
|
||||
container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.accent.base)),
|
||||
text_color: Some(Color::from(cosmic.background.on)),
|
||||
background: Some(iced::Background::Color(header_top.into())),
|
||||
border: Border {
|
||||
radius: [
|
||||
cosmic.corner_radii.radius_xs[0],
|
||||
cosmic.corner_radii.radius_xs[1],
|
||||
cosmic.corner_radii.radius_0[2],
|
||||
cosmic.corner_radii.radius_0[3],
|
||||
]
|
||||
.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
}
|
||||
Container::ContextDrawer => {
|
||||
let mut appearance = crate::style::Container::primary(cosmic);
|
||||
|
||||
appearance.border = Border {
|
||||
color: cosmic.primary.divider.into(),
|
||||
width: 1.0,
|
||||
radius: cosmic.corner_radii.radius_s.into(),
|
||||
};
|
||||
|
||||
appearance.shadow = Shadow {
|
||||
color: cosmic.shade.into(),
|
||||
offset: Vector::new(0.0, 0.0),
|
||||
blur_radius: 16.0,
|
||||
};
|
||||
|
||||
appearance
|
||||
}
|
||||
Container::Primary => container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.primary.on)),
|
||||
text_color: Some(Color::from(cosmic.primary.on)),
|
||||
background: Some(iced::Background::Color(cosmic.primary.base.into())),
|
||||
border: Border {
|
||||
radius: cosmic.corner_radii.radius_xs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
Container::Secondary => container::Appearance {
|
||||
icon_color: Some(Color::from(cosmic.secondary.on)),
|
||||
text_color: Some(Color::from(cosmic.secondary.on)),
|
||||
background: Some(iced::Background::Color(cosmic.secondary.base.into())),
|
||||
border: Border {
|
||||
radius: cosmic.corner_radii.radius_xs.into(),
|
||||
..Default::default()
|
||||
},
|
||||
shadow: Shadow::default(),
|
||||
},
|
||||
|
||||
Container::Background => Container::background(cosmic),
|
||||
|
||||
Container::Primary => Container::primary(cosmic),
|
||||
|
||||
Container::Secondary => Container::secondary(cosmic),
|
||||
|
||||
Container::Dropdown => {
|
||||
let theme = self.cosmic();
|
||||
|
||||
|
|
@ -475,6 +512,7 @@ impl container::StyleSheet for Theme {
|
|||
shadow: Shadow::default(),
|
||||
}
|
||||
}
|
||||
|
||||
Container::Tooltip => container::Appearance {
|
||||
icon_color: None,
|
||||
text_color: None,
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ use crate::{Apply, Element, Renderer, Theme};
|
|||
|
||||
use super::overlay::Overlay;
|
||||
|
||||
use iced_core::alignment;
|
||||
use iced_core::event::{self, Event};
|
||||
use iced_core::widget::{Operation, Tree};
|
||||
use iced_core::{alignment, Border};
|
||||
use iced_core::{
|
||||
layout, mouse, overlay as iced_overlay, renderer, Clipboard, Color, Layout, Length, Padding,
|
||||
Rectangle, Shell, Widget,
|
||||
|
|
@ -85,20 +85,7 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
|
|||
// XXX this is a hack to get around that
|
||||
drawer: container(
|
||||
LayerContainer::new(pane)
|
||||
.style(crate::style::Container::custom(move |theme| {
|
||||
let palette = theme.cosmic();
|
||||
|
||||
container::Appearance {
|
||||
icon_color: Some(Color::from(palette.primary.on)),
|
||||
text_color: Some(Color::from(palette.primary.on)),
|
||||
background: Some(iced::Background::Color(palette.primary.base.into())),
|
||||
border: Border {
|
||||
radius: palette.corner_radii.radius_s.into(),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
}
|
||||
}))
|
||||
.style(crate::style::Container::ContextDrawer)
|
||||
.layer(cosmic_theme::Layer::Primary)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ use crate::{
|
|||
};
|
||||
use derive_setters::Setters;
|
||||
use iced_core::Length;
|
||||
use iced_widget::container;
|
||||
|
||||
/// A settings item aligned in a row
|
||||
#[must_use]
|
||||
|
|
@ -80,7 +79,7 @@ impl<'a, Message: 'static> Item<'a, Message> {
|
|||
contents.push(text(self.title).width(Length::Fill).into());
|
||||
}
|
||||
|
||||
contents.push(widget.into().into());
|
||||
contents.push(widget.into());
|
||||
|
||||
item_row(contents)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue