Implement theme styling for PickList and Menu

This commit is contained in:
Héctor Ramón Jiménez 2022-06-07 04:51:44 +02:00
parent 97555e67af
commit 396735b682
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
14 changed files with 168 additions and 247 deletions

View file

@ -1,9 +1,12 @@
use crate::menu;
use iced_core::{Background, Color};
use crate::container;
use crate::menu;
use crate::scrollable;
/// The appearance of a pick list.
#[derive(Debug, Clone, Copy)]
pub struct Style {
pub struct Appearance {
pub text_color: Color,
pub placeholder_color: Color,
pub background: Background,
@ -13,60 +16,14 @@ pub struct Style {
pub icon_size: f32,
}
impl std::default::Default for Style {
fn default() -> Self {
Self {
text_color: Color::BLACK,
placeholder_color: [0.4, 0.4, 0.4].into(),
background: Background::Color([0.87, 0.87, 0.87].into()),
border_radius: 0.0,
border_width: 1.0,
border_color: [0.7, 0.7, 0.7].into(),
icon_size: 0.7,
}
}
}
/// A set of rules that dictate the style of a container.
pub trait StyleSheet {
fn menu(&self) -> menu::Style;
pub trait StyleSheet:
container::StyleSheet + menu::StyleSheet + scrollable::StyleSheet
{
type Style: Default + Copy + Into<<Self as menu::StyleSheet>::Style>;
fn active(&self) -> Style;
fn active(&self, style: <Self as StyleSheet>::Style) -> Appearance;
/// Produces the style of a container.
fn hovered(&self) -> Style;
}
struct Default;
impl StyleSheet for Default {
fn menu(&self) -> menu::Style {
menu::Style::default()
}
fn active(&self) -> Style {
Style::default()
}
fn hovered(&self) -> Style {
Style {
border_color: Color::BLACK,
..self.active()
}
}
}
impl<'a> std::default::Default for Box<dyn StyleSheet + 'a> {
fn default() -> Self {
Box::new(Default)
}
}
impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
where
T: 'a + StyleSheet,
{
fn from(style: T) -> Self {
Box::new(style)
}
fn hovered(&self, style: <Self as StyleSheet>::Style) -> Appearance;
}