Implement theme styling for TextInput

This commit is contained in:
Héctor Ramón Jiménez 2022-06-07 01:11:35 +02:00
parent 835877fc63
commit ce53d3933c
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
12 changed files with 145 additions and 183 deletions

View file

@ -95,7 +95,7 @@ mod numeric_input {
for NumericInput<'a, Message> for NumericInput<'a, Message>
where where
Renderer: 'a + text::Renderer, Renderer: 'a + text::Renderer,
Renderer::Theme: button::StyleSheet, Renderer::Theme: button::StyleSheet + text_input::StyleSheet,
{ {
type Event = Event; type Event = Event;
@ -173,7 +173,7 @@ mod numeric_input {
where where
Message: 'a, Message: 'a,
Renderer: text::Renderer + 'a, Renderer: text::Renderer + 'a,
Renderer::Theme: button::StyleSheet, Renderer::Theme: button::StyleSheet + text_input::StyleSheet,
{ {
fn from(numeric_input: NumericInput<'a, Message>) -> Self { fn from(numeric_input: NumericInput<'a, Message>) -> Self {
component::view(numeric_input) component::view(numeric_input)

View file

@ -89,7 +89,8 @@ mod numeric_input {
impl<Message, Renderer> Component<Message, Renderer> for NumericInput<Message> impl<Message, Renderer> Component<Message, Renderer> for NumericInput<Message>
where where
Renderer: text::Renderer + 'static, Renderer: text::Renderer + 'static,
Renderer::Theme: widget::button::StyleSheet, Renderer::Theme:
widget::button::StyleSheet + widget::text_input::StyleSheet,
{ {
type State = (); type State = ();
type Event = Event; type Event = Event;
@ -160,7 +161,8 @@ mod numeric_input {
where where
Message: 'a, Message: 'a,
Renderer: 'static + text::Renderer, Renderer: 'static + text::Renderer,
Renderer::Theme: widget::button::StyleSheet, Renderer::Theme:
widget::button::StyleSheet + widget::text_input::StyleSheet,
{ {
fn from(numeric_input: NumericInput<Message>) -> Self { fn from(numeric_input: NumericInput<Message>) -> Self {
pure::component(numeric_input) pure::component(numeric_input)

View file

@ -43,12 +43,6 @@ mod dark {
0x3F as f32 / 255.0, 0x3F as f32 / 255.0,
); );
const SURFACE: Color = Color::from_rgb(
0x40 as f32 / 255.0,
0x44 as f32 / 255.0,
0x4B as f32 / 255.0,
);
const ACCENT: Color = Color::from_rgb( const ACCENT: Color = Color::from_rgb(
0x6F as f32 / 255.0, 0x6F as f32 / 255.0,
0xFF as f32 / 255.0, 0xFF as f32 / 255.0,

View file

@ -77,8 +77,7 @@ impl Sandbox for Styling {
Message::InputChanged, Message::InputChanged,
) )
.padding(10) .padding(10)
.size(20) .size(20);
.style(self.theme);
let button = Button::new(&mut self.button, Text::new("Submit")) let button = Button::new(&mut self.button, Text::new("Submit"))
.padding(10) .padding(10)
@ -157,7 +156,7 @@ impl Sandbox for Styling {
} }
mod style { mod style {
use iced::{scrollable, text_input}; use iced::scrollable;
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Theme { pub enum Theme {
@ -175,15 +174,6 @@ mod style {
} }
} }
impl<'a> From<Theme> for Box<dyn text_input::StyleSheet + 'a> {
fn from(theme: Theme) -> Self {
match theme {
Theme::Light => Default::default(),
Theme::Dark => dark::TextInput.into(),
}
}
}
impl<'a> From<Theme> for Box<dyn scrollable::StyleSheet + 'a> { impl<'a> From<Theme> for Box<dyn scrollable::StyleSheet + 'a> {
fn from(theme: Theme) -> Self { fn from(theme: Theme) -> Self {
match theme { match theme {
@ -194,7 +184,7 @@ mod style {
} }
mod dark { mod dark {
use iced::{scrollable, text_input, Color}; use iced::{scrollable, Color};
const SURFACE: Color = Color::from_rgb( const SURFACE: Color = Color::from_rgb(
0x40 as f32 / 255.0, 0x40 as f32 / 255.0,
@ -202,12 +192,6 @@ mod style {
0x4B as f32 / 255.0, 0x4B as f32 / 255.0,
); );
const ACCENT: Color = Color::from_rgb(
0x6F as f32 / 255.0,
0xFF as f32 / 255.0,
0xE9 as f32 / 255.0,
);
const ACTIVE: Color = Color::from_rgb( const ACTIVE: Color = Color::from_rgb(
0x72 as f32 / 255.0, 0x72 as f32 / 255.0,
0x89 as f32 / 255.0, 0x89 as f32 / 255.0,
@ -220,47 +204,6 @@ mod style {
0xC4 as f32 / 255.0, 0xC4 as f32 / 255.0,
); );
pub struct TextInput;
impl text_input::StyleSheet for TextInput {
fn active(&self) -> text_input::Style {
text_input::Style {
background: SURFACE.into(),
border_radius: 2.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
fn focused(&self) -> text_input::Style {
text_input::Style {
border_width: 1.0,
border_color: ACCENT,
..self.active()
}
}
fn hovered(&self) -> text_input::Style {
text_input::Style {
border_width: 1.0,
border_color: Color { a: 0.3, ..ACCENT },
..self.focused()
}
}
fn placeholder_color(&self) -> Color {
Color::from_rgb(0.4, 0.4, 0.4)
}
fn value_color(&self) -> Color {
Color::WHITE
}
fn selection_color(&self) -> Color {
ACTIVE
}
}
pub struct Scrollable; pub struct Scrollable;
impl scrollable::StyleSheet for Scrollable { impl scrollable::StyleSheet for Scrollable {

View file

@ -24,7 +24,7 @@ use crate::{
Shell, Size, Vector, Widget, Shell, Size, Vector, Widget,
}; };
pub use iced_style::text_input::{Style, StyleSheet}; pub use iced_style::text_input::{Appearance, StyleSheet};
/// A field that can be filled with text. /// A field that can be filled with text.
/// ///
@ -52,7 +52,11 @@ pub use iced_style::text_input::{Style, StyleSheet};
/// ``` /// ```
/// ![Text input drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text_input.png?raw=true) /// ![Text input drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text_input.png?raw=true)
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct TextInput<'a, Message, Renderer: text::Renderer> { pub struct TextInput<'a, Message, Renderer>
where
Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{
state: &'a mut State, state: &'a mut State,
placeholder: String, placeholder: String,
value: Value, value: Value,
@ -63,13 +67,14 @@ pub struct TextInput<'a, Message, Renderer: text::Renderer> {
size: Option<u16>, size: Option<u16>,
on_change: Box<dyn Fn(String) -> Message + 'a>, on_change: Box<dyn Fn(String) -> Message + 'a>,
on_submit: Option<Message>, on_submit: Option<Message>,
style_sheet: Box<dyn StyleSheet + 'a>, style: <Renderer::Theme as StyleSheet>::Style,
} }
impl<'a, Message, Renderer> TextInput<'a, Message, Renderer> impl<'a, Message, Renderer> TextInput<'a, Message, Renderer>
where where
Message: Clone, Message: Clone,
Renderer: text::Renderer, Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{ {
/// Creates a new [`TextInput`]. /// Creates a new [`TextInput`].
/// ///
@ -98,7 +103,7 @@ where
size: None, size: None,
on_change: Box::new(on_change), on_change: Box::new(on_change),
on_submit: None, on_submit: None,
style_sheet: Default::default(), style: Default::default(),
} }
} }
@ -143,9 +148,9 @@ where
/// Sets the style of the [`TextInput`]. /// Sets the style of the [`TextInput`].
pub fn style( pub fn style(
mut self, mut self,
style_sheet: impl Into<Box<dyn StyleSheet + 'a>>, style: impl Into<<Renderer::Theme as StyleSheet>::Style>,
) -> Self { ) -> Self {
self.style_sheet = style_sheet.into(); self.style = style.into();
self self
} }
@ -161,12 +166,14 @@ where
pub fn draw( pub fn draw(
&self, &self,
renderer: &mut Renderer, renderer: &mut Renderer,
theme: &Renderer::Theme,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
value: Option<&Value>, value: Option<&Value>,
) { ) {
draw( draw(
renderer, renderer,
theme,
layout, layout,
cursor_position, cursor_position,
&self.state, &self.state,
@ -175,7 +182,7 @@ where
self.size, self.size,
&self.font, &self.font,
self.is_secure, self.is_secure,
self.style_sheet.as_ref(), self.style,
) )
} }
} }
@ -575,6 +582,7 @@ where
/// [`Renderer`]: text::Renderer /// [`Renderer`]: text::Renderer
pub fn draw<Renderer>( pub fn draw<Renderer>(
renderer: &mut Renderer, renderer: &mut Renderer,
theme: &Renderer::Theme,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
state: &State, state: &State,
@ -583,9 +591,10 @@ pub fn draw<Renderer>(
size: Option<u16>, size: Option<u16>,
font: &Renderer::Font, font: &Renderer::Font,
is_secure: bool, is_secure: bool,
style_sheet: &dyn StyleSheet, style: <Renderer::Theme as StyleSheet>::Style,
) where ) where
Renderer: text::Renderer, Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{ {
let secure_value = is_secure.then(|| value.secure()); let secure_value = is_secure.then(|| value.secure());
let value = secure_value.as_ref().unwrap_or(&value); let value = secure_value.as_ref().unwrap_or(&value);
@ -595,22 +604,22 @@ pub fn draw<Renderer>(
let is_mouse_over = bounds.contains(cursor_position); let is_mouse_over = bounds.contains(cursor_position);
let style = if state.is_focused() { let appearance = if state.is_focused() {
style_sheet.focused() theme.focused(style)
} else if is_mouse_over { } else if is_mouse_over {
style_sheet.hovered() theme.hovered(style)
} else { } else {
style_sheet.active() theme.active(style)
}; };
renderer.fill_quad( renderer.fill_quad(
renderer::Quad { renderer::Quad {
bounds, bounds,
border_radius: style.border_radius, border_radius: appearance.border_radius,
border_width: style.border_width, border_width: appearance.border_width,
border_color: style.border_color, border_color: appearance.border_color,
}, },
style.background, appearance.background,
); );
let text = value.to_string(); let text = value.to_string();
@ -642,7 +651,7 @@ pub fn draw<Renderer>(
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
style_sheet.value_color(), theme.value_color(style),
)), )),
offset, offset,
) )
@ -686,7 +695,7 @@ pub fn draw<Renderer>(
border_width: 0.0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
style_sheet.selection_color(), theme.selection_color(style),
)), )),
if end == right { if end == right {
right_offset right_offset
@ -714,9 +723,9 @@ pub fn draw<Renderer>(
renderer.fill_text(Text { renderer.fill_text(Text {
content: if text.is_empty() { placeholder } else { &text }, content: if text.is_empty() { placeholder } else { &text },
color: if text.is_empty() { color: if text.is_empty() {
style_sheet.placeholder_color() theme.placeholder_color(style)
} else { } else {
style_sheet.value_color() theme.value_color(style)
}, },
font: font.clone(), font: font.clone(),
bounds: Rectangle { bounds: Rectangle {
@ -756,6 +765,7 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
where where
Message: Clone, Message: Clone,
Renderer: text::Renderer, Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{ {
fn width(&self) -> Length { fn width(&self) -> Length {
self.width self.width
@ -812,13 +822,13 @@ where
fn draw( fn draw(
&self, &self,
renderer: &mut Renderer, renderer: &mut Renderer,
_theme: &Renderer::Theme, theme: &Renderer::Theme,
_style: &renderer::Style, _style: &renderer::Style,
layout: Layout<'_>, layout: Layout<'_>,
cursor_position: Point, cursor_position: Point,
_viewport: &Rectangle, _viewport: &Rectangle,
) { ) {
self.draw(renderer, layout, cursor_position, None) self.draw(renderer, theme, layout, cursor_position, None)
} }
} }
@ -827,6 +837,7 @@ impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>>
where where
Message: 'a + Clone, Message: 'a + Clone,
Renderer: 'a + text::Renderer, Renderer: 'a + text::Renderer,
Renderer::Theme: StyleSheet,
{ {
fn from( fn from(
text_input: TextInput<'a, Message, Renderer>, text_input: TextInput<'a, Message, Renderer>,

View file

@ -142,6 +142,7 @@ pub fn text_input<'a, Message, Renderer>(
where where
Message: Clone, Message: Clone,
Renderer: iced_native::text::Renderer, Renderer: iced_native::text::Renderer,
Renderer::Theme: widget::text_input::StyleSheet,
{ {
widget::TextInput::new(placeholder, value, on_change) widget::TextInput::new(placeholder, value, on_change)
} }

View file

@ -10,7 +10,7 @@ use iced_native::text;
use iced_native::widget::text_input; use iced_native::widget::text_input;
use iced_native::{Clipboard, Length, Padding, Point, Rectangle, Shell}; use iced_native::{Clipboard, Length, Padding, Point, Rectangle, Shell};
pub use iced_style::text_input::{Style, StyleSheet}; pub use iced_style::text_input::{Appearance, StyleSheet};
/// A field that can be filled with text. /// A field that can be filled with text.
/// ///
@ -33,7 +33,11 @@ pub use iced_style::text_input::{Style, StyleSheet};
/// ``` /// ```
/// ![Text input drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text_input.png?raw=true) /// ![Text input drawn by `iced_wgpu`](https://github.com/iced-rs/iced/blob/7760618fb112074bc40b148944521f312152012a/docs/images/text_input.png?raw=true)
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct TextInput<'a, Message, Renderer: text::Renderer> { pub struct TextInput<'a, Message, Renderer>
where
Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{
placeholder: String, placeholder: String,
value: text_input::Value, value: text_input::Value,
is_secure: bool, is_secure: bool,
@ -43,13 +47,14 @@ pub struct TextInput<'a, Message, Renderer: text::Renderer> {
size: Option<u16>, size: Option<u16>,
on_change: Box<dyn Fn(String) -> Message + 'a>, on_change: Box<dyn Fn(String) -> Message + 'a>,
on_submit: Option<Message>, on_submit: Option<Message>,
style_sheet: Box<dyn StyleSheet + 'a>, style: <Renderer::Theme as StyleSheet>::Style,
} }
impl<'a, Message, Renderer> TextInput<'a, Message, Renderer> impl<'a, Message, Renderer> TextInput<'a, Message, Renderer>
where where
Message: Clone, Message: Clone,
Renderer: text::Renderer, Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{ {
/// Creates a new [`TextInput`]. /// Creates a new [`TextInput`].
/// ///
@ -71,7 +76,7 @@ where
size: None, size: None,
on_change: Box::new(on_change), on_change: Box::new(on_change),
on_submit: None, on_submit: None,
style_sheet: Default::default(), style: Default::default(),
} }
} }
@ -83,7 +88,7 @@ where
/// Sets the [`Font`] of the [`TextInput`]. /// Sets the [`Font`] of the [`TextInput`].
/// ///
/// [`Font`]: iced_native::text::Renderer::Font /// [`Font`]: text::Renderer::Font
pub fn font(mut self, font: Renderer::Font) -> Self { pub fn font(mut self, font: Renderer::Font) -> Self {
self.font = font; self.font = font;
self self
@ -116,9 +121,9 @@ where
/// Sets the style of the [`TextInput`]. /// Sets the style of the [`TextInput`].
pub fn style( pub fn style(
mut self, mut self,
style_sheet: impl Into<Box<dyn StyleSheet + 'a>>, style: impl Into<<Renderer::Theme as StyleSheet>::Style>,
) -> Self { ) -> Self {
self.style_sheet = style_sheet.into(); self.style = style.into();
self self
} }
} }
@ -127,7 +132,8 @@ impl<'a, Message, Renderer> Widget<Message, Renderer>
for TextInput<'a, Message, Renderer> for TextInput<'a, Message, Renderer>
where where
Message: Clone, Message: Clone,
Renderer: iced_native::text::Renderer, Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{ {
fn tag(&self) -> tree::Tag { fn tag(&self) -> tree::Tag {
tree::Tag::of::<text_input::State>() tree::Tag::of::<text_input::State>()
@ -198,6 +204,7 @@ where
) { ) {
text_input::draw( text_input::draw(
renderer, renderer,
theme,
layout, layout,
cursor_position, cursor_position,
tree.state.downcast_ref::<text_input::State>(), tree.state.downcast_ref::<text_input::State>(),
@ -206,7 +213,7 @@ where
self.size, self.size,
&self.font, &self.font,
self.is_secure, self.is_secure,
self.style_sheet.as_ref(), self.style,
) )
} }
@ -227,6 +234,7 @@ impl<'a, Message, Renderer> From<TextInput<'a, Message, Renderer>>
where where
Message: 'a + Clone, Message: 'a + Clone,
Renderer: 'a + text::Renderer, Renderer: 'a + text::Renderer,
Renderer::Theme: StyleSheet,
{ {
fn from( fn from(
text_input: TextInput<'a, Message, Renderer>, text_input: TextInput<'a, Message, Renderer>,

View file

@ -120,7 +120,7 @@ pub mod text_input {
//! Display fields that can be filled with text. //! Display fields that can be filled with text.
use crate::Renderer; use crate::Renderer;
pub use iced_pure::widget::text_input::{Style, StyleSheet}; pub use iced_pure::widget::text_input::{Appearance, StyleSheet};
/// A field that can be filled with text. /// A field that can be filled with text.
pub type TextInput<'a, Message, Theme> = pub type TextInput<'a, Message, Theme> =

View file

@ -140,7 +140,7 @@ pub mod text_input {
//! A [`TextInput`] has some local [`State`]. //! A [`TextInput`] has some local [`State`].
use crate::Renderer; use crate::Renderer;
pub use iced_native::widget::text_input::{State, Style, StyleSheet}; pub use iced_native::widget::text_input::{Appearance, State, StyleSheet};
/// A field that can be filled with text. /// A field that can be filled with text.
pub type TextInput<'a, Message, Theme> = pub type TextInput<'a, Message, Theme> =

View file

@ -3,87 +3,31 @@ use iced_core::{Background, Color};
/// The appearance of a text input. /// The appearance of a text input.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Style { pub struct Appearance {
pub background: Background, pub background: Background,
pub border_radius: f32, pub border_radius: f32,
pub border_width: f32, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
impl std::default::Default for Style {
fn default() -> Self {
Self {
background: Background::Color(Color::WHITE),
border_radius: 0.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
}
/// A set of rules that dictate the style of a text input. /// A set of rules that dictate the style of a text input.
pub trait StyleSheet { pub trait StyleSheet {
type Style: Default + Copy;
/// Produces the style of an active text input. /// Produces the style of an active text input.
fn active(&self) -> Style; fn active(&self, style: Self::Style) -> Appearance;
/// Produces the style of a focused text input. /// Produces the style of a focused text input.
fn focused(&self) -> Style; fn focused(&self, style: Self::Style) -> Appearance;
fn placeholder_color(&self) -> Color; fn placeholder_color(&self, style: Self::Style) -> Color;
fn value_color(&self) -> Color; fn value_color(&self, style: Self::Style) -> Color;
fn selection_color(&self) -> Color; fn selection_color(&self, style: Self::Style) -> Color;
/// Produces the style of an hovered text input. /// Produces the style of an hovered text input.
fn hovered(&self) -> Style { fn hovered(&self, style: Self::Style) -> Appearance {
self.focused() self.focused(style)
}
}
struct Default;
impl StyleSheet for Default {
fn active(&self) -> Style {
Style {
background: Background::Color(Color::WHITE),
border_radius: 5.0,
border_width: 1.0,
border_color: Color::from_rgb(0.7, 0.7, 0.7),
}
}
fn focused(&self) -> Style {
Style {
border_color: Color::from_rgb(0.5, 0.5, 0.5),
..self.active()
}
}
fn placeholder_color(&self) -> Color {
Color::from_rgb(0.7, 0.7, 0.7)
}
fn value_color(&self) -> Color {
Color::from_rgb(0.3, 0.3, 0.3)
}
fn selection_color(&self) -> Color {
Color::from_rgb(0.8, 0.8, 1.0)
}
}
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: StyleSheet + 'a,
{
fn from(style_sheet: T) -> Self {
Box::new(style_sheet)
} }
} }

View file

@ -10,6 +10,7 @@ use crate::progress_bar;
use crate::radio; use crate::radio;
use crate::rule; use crate::rule;
use crate::slider; use crate::slider;
use crate::text_input;
use crate::toggler; use crate::toggler;
use iced_core::{Background, Color}; use iced_core::{Background, Color};
@ -152,22 +153,22 @@ impl checkbox::StyleSheet for Theme {
match style { match style {
Checkbox::Primary => checkbox_appearance( Checkbox::Primary => checkbox_appearance(
palette.background.weak, palette.background.base,
palette.primary.strong, palette.primary.strong,
is_checked, is_checked,
), ),
Checkbox::Secondary => checkbox_appearance( Checkbox::Secondary => checkbox_appearance(
palette.background.weak, palette.background.base,
palette.background.base, palette.background.base,
is_checked, is_checked,
), ),
Checkbox::Success => checkbox_appearance( Checkbox::Success => checkbox_appearance(
palette.background.weak, palette.background.base,
palette.success.base, palette.success.base,
is_checked, is_checked,
), ),
Checkbox::Danger => checkbox_appearance( Checkbox::Danger => checkbox_appearance(
palette.background.weak, palette.background.base,
palette.danger.base, palette.danger.base,
is_checked, is_checked,
), ),
@ -183,23 +184,23 @@ impl checkbox::StyleSheet for Theme {
match style { match style {
Checkbox::Primary => checkbox_appearance( Checkbox::Primary => checkbox_appearance(
palette.background.strong, palette.background.weak,
palette.primary.strong, palette.primary.base,
is_checked, is_checked,
), ),
Checkbox::Secondary => checkbox_appearance( Checkbox::Secondary => checkbox_appearance(
palette.background.strong, palette.background.weak,
palette.background.strong, palette.background.base,
is_checked, is_checked,
), ),
Checkbox::Success => checkbox_appearance( Checkbox::Success => checkbox_appearance(
palette.background.strong, palette.background.weak,
palette.success.strong, palette.success.base,
is_checked, is_checked,
), ),
Checkbox::Danger => checkbox_appearance( Checkbox::Danger => checkbox_appearance(
palette.background.strong, palette.background.weak,
palette.danger.strong, palette.danger.base,
is_checked, is_checked,
), ),
} }
@ -410,7 +411,7 @@ impl progress_bar::StyleSheet for Theme {
let palette = self.extended_palette(); let palette = self.extended_palette();
let from_palette = |bar: Color| progress_bar::Appearance { let from_palette = |bar: Color| progress_bar::Appearance {
background: palette.background.weak.color.into(), background: palette.background.strong.color.into(),
bar: bar.into(), bar: bar.into(),
border_radius: 2.0, border_radius: 2.0,
}; };
@ -456,3 +457,61 @@ impl rule::StyleSheet for Theme {
} }
} }
} }
/*
* Text Input
*/
impl text_input::StyleSheet for Theme {
type Style = ();
fn active(&self, _style: Self::Style) -> text_input::Appearance {
let palette = self.extended_palette();
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0,
border_width: 1.0,
border_color: palette.background.strong.color,
}
}
fn hovered(&self, _style: Self::Style) -> text_input::Appearance {
let palette = self.extended_palette();
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0,
border_width: 1.0,
border_color: palette.background.base.text,
}
}
fn focused(&self, _style: Self::Style) -> text_input::Appearance {
let palette = self.extended_palette();
text_input::Appearance {
background: palette.background.base.color.into(),
border_radius: 2.0,
border_width: 1.0,
border_color: palette.primary.strong.color,
}
}
fn placeholder_color(&self, _style: Self::Style) -> Color {
let palette = self.extended_palette();
palette.background.strong.color
}
fn value_color(&self, _style: Self::Style) -> Color {
let palette = self.extended_palette();
palette.background.base.text
}
fn selection_color(&self, _style: Self::Style) -> Color {
let palette = self.extended_palette();
palette.primary.weak.color
}
}

View file

@ -120,7 +120,7 @@ pub struct Background {
impl Background { impl Background {
pub fn new(base: Color, text: Color) -> Self { pub fn new(base: Color, text: Color) -> Self {
let weak = mix(base, text, 0.15); let weak = mix(base, text, 0.15);
let strong = mix(base, text, 0.25); let strong = mix(base, text, 0.40);
Self { Self {
base: Pair::new(base, text), base: Pair::new(base, text),