Simplify theming for TextInput widget
This commit is contained in:
parent
d681aaa57e
commit
704ec9cb5c
9 changed files with 855 additions and 1056 deletions
|
|
@ -27,7 +27,6 @@ pub mod rule;
|
|||
pub mod slider;
|
||||
pub mod svg;
|
||||
pub mod text_editor;
|
||||
pub mod text_input;
|
||||
pub mod theme;
|
||||
pub mod toggler;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
//! Change the appearance of a text input.
|
||||
use iced_core::{Background, Border, Color};
|
||||
|
||||
/// The appearance of a text input.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Appearance {
|
||||
/// The [`Background`] of the text input.
|
||||
pub background: Background,
|
||||
/// The [`Border`] of the text input.
|
||||
pub border: Border,
|
||||
/// The icon [`Color`] of the text input.
|
||||
pub icon_color: Color,
|
||||
}
|
||||
|
||||
/// A set of rules that dictate the style of a text input.
|
||||
pub trait StyleSheet {
|
||||
/// The supported style of the [`StyleSheet`].
|
||||
type Style: Default;
|
||||
|
||||
/// Produces the style of an active text input.
|
||||
fn active(&self, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the style of a focused text input.
|
||||
fn focused(&self, style: &Self::Style) -> Appearance;
|
||||
|
||||
/// Produces the [`Color`] of the placeholder of a text input.
|
||||
fn placeholder_color(&self, style: &Self::Style) -> Color;
|
||||
|
||||
/// Produces the [`Color`] of the value of a text input.
|
||||
fn value_color(&self, style: &Self::Style) -> Color;
|
||||
|
||||
/// Produces the [`Color`] of the value of a disabled text input.
|
||||
fn disabled_color(&self, style: &Self::Style) -> Color;
|
||||
|
||||
/// Produces the [`Color`] of the selection of a text input.
|
||||
fn selection_color(&self, style: &Self::Style) -> Color;
|
||||
|
||||
/// Produces the style of an hovered text input.
|
||||
fn hovered(&self, style: &Self::Style) -> Appearance {
|
||||
self.focused(style)
|
||||
}
|
||||
|
||||
/// Produces the style of a disabled text input.
|
||||
fn disabled(&self, style: &Self::Style) -> Appearance;
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ use crate::rule;
|
|||
use crate::slider;
|
||||
use crate::svg;
|
||||
use crate::text_editor;
|
||||
use crate::text_input;
|
||||
use crate::toggler;
|
||||
|
||||
use crate::core::{Background, Border, Color};
|
||||
|
|
@ -793,130 +792,6 @@ impl svg::StyleSheet for fn(&Theme) -> svg::Appearance {
|
|||
|
||||
impl text::StyleSheet for Theme {}
|
||||
|
||||
/// The style of a text input.
|
||||
#[derive(Default)]
|
||||
pub enum TextInput {
|
||||
/// The default style.
|
||||
#[default]
|
||||
Default,
|
||||
/// A custom style.
|
||||
Custom(Box<dyn text_input::StyleSheet<Style = Theme>>),
|
||||
}
|
||||
|
||||
impl text_input::StyleSheet for Theme {
|
||||
type Style = TextInput;
|
||||
|
||||
fn active(&self, style: &Self::Style) -> text_input::Appearance {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.active(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
text_input::Appearance {
|
||||
background: palette.background.base.color.into(),
|
||||
border: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
color: palette.background.strong.color,
|
||||
},
|
||||
icon_color: palette.background.weak.text,
|
||||
}
|
||||
}
|
||||
|
||||
fn hovered(&self, style: &Self::Style) -> text_input::Appearance {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.hovered(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
text_input::Appearance {
|
||||
background: palette.background.base.color.into(),
|
||||
border: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
color: palette.background.base.text,
|
||||
},
|
||||
icon_color: palette.background.weak.text,
|
||||
}
|
||||
}
|
||||
|
||||
fn focused(&self, style: &Self::Style) -> text_input::Appearance {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.focused(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
text_input::Appearance {
|
||||
background: palette.background.base.color.into(),
|
||||
border: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
color: palette.primary.strong.color,
|
||||
},
|
||||
icon_color: palette.background.weak.text,
|
||||
}
|
||||
}
|
||||
|
||||
fn placeholder_color(&self, style: &Self::Style) -> Color {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.placeholder_color(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
palette.background.strong.color
|
||||
}
|
||||
|
||||
fn value_color(&self, style: &Self::Style) -> Color {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.value_color(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
palette.background.base.text
|
||||
}
|
||||
|
||||
fn selection_color(&self, style: &Self::Style) -> Color {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.selection_color(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
palette.primary.weak.color
|
||||
}
|
||||
|
||||
fn disabled(&self, style: &Self::Style) -> text_input::Appearance {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.disabled(self);
|
||||
}
|
||||
|
||||
let palette = self.extended_palette();
|
||||
|
||||
text_input::Appearance {
|
||||
background: palette.background.weak.color.into(),
|
||||
border: Border {
|
||||
radius: 2.0.into(),
|
||||
width: 1.0,
|
||||
color: palette.background.strong.color,
|
||||
},
|
||||
icon_color: palette.background.strong.color,
|
||||
}
|
||||
}
|
||||
|
||||
fn disabled_color(&self, style: &Self::Style) -> Color {
|
||||
if let TextInput::Custom(custom) = style {
|
||||
return custom.disabled_color(self);
|
||||
}
|
||||
|
||||
self.placeholder_color(style)
|
||||
}
|
||||
}
|
||||
|
||||
/// The style of a text input.
|
||||
#[derive(Default)]
|
||||
pub enum TextEditor {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue