Introduce StyleSheet for Text widget

This commit is contained in:
Héctor Ramón Jiménez 2022-06-29 10:51:01 +02:00
parent c807abdfd7
commit 1dd1a2f97f
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
28 changed files with 183 additions and 87 deletions

View file

@ -21,6 +21,7 @@ pub mod radio;
pub mod rule;
pub mod scrollable;
pub mod slider;
pub mod text;
pub mod text_input;
pub mod theme;
pub mod toggler;

18
style/src/text.rs Normal file
View file

@ -0,0 +1,18 @@
use iced_core::Color;
pub trait StyleSheet {
type Style: Default + Copy;
fn appearance(&self, style: Self::Style) -> Appearance;
}
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
pub color: Option<Color>,
}
impl Default for Appearance {
fn default() -> Self {
Self { color: None }
}
}

View file

@ -14,6 +14,7 @@ use crate::radio;
use crate::rule;
use crate::scrollable;
use crate::slider;
use crate::text;
use crate::text_input;
use crate::toggler;
@ -601,6 +602,40 @@ impl scrollable::StyleSheet for Theme {
}
}
/*
* Text
*/
#[derive(Clone, Copy)]
pub enum Text {
Default,
Color(Color),
Custom(fn(&Theme) -> text::Appearance),
}
impl Default for Text {
fn default() -> Self {
Self::Default
}
}
impl From<Color> for Text {
fn from(color: Color) -> Self {
Text::Color(color)
}
}
impl text::StyleSheet for Theme {
type Style = Text;
fn appearance(&self, style: Self::Style) -> text::Appearance {
match style {
Text::Default => Default::default(),
Text::Color(c) => text::Appearance { color: Some(c) },
Text::Custom(f) => f(self),
}
}
}
/*
* Text Input
*/