From ce53d3933c860cd958636cce415ac97c04aee746 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 01:11:35 +0200 Subject: Implement theme styling for `TextInput` --- pure/src/helpers.rs | 1 + pure/src/widget/text_input.rs | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) (limited to 'pure') diff --git a/pure/src/helpers.rs b/pure/src/helpers.rs index ebc8f14b..1d020b3c 100644 --- a/pure/src/helpers.rs +++ b/pure/src/helpers.rs @@ -142,6 +142,7 @@ pub fn text_input<'a, Message, Renderer>( where Message: Clone, Renderer: iced_native::text::Renderer, + Renderer::Theme: widget::text_input::StyleSheet, { widget::TextInput::new(placeholder, value, on_change) } diff --git a/pure/src/widget/text_input.rs b/pure/src/widget/text_input.rs index 7d768513..d3e642a5 100644 --- a/pure/src/widget/text_input.rs +++ b/pure/src/widget/text_input.rs @@ -10,7 +10,7 @@ use iced_native::text; use iced_native::widget::text_input; 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. /// @@ -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) #[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, value: text_input::Value, is_secure: bool, @@ -43,13 +47,14 @@ pub struct TextInput<'a, Message, Renderer: text::Renderer> { size: Option, on_change: Box Message + 'a>, on_submit: Option, - style_sheet: Box, + style: ::Style, } impl<'a, Message, Renderer> TextInput<'a, Message, Renderer> where Message: Clone, Renderer: text::Renderer, + Renderer::Theme: StyleSheet, { /// Creates a new [`TextInput`]. /// @@ -71,7 +76,7 @@ where size: None, on_change: Box::new(on_change), on_submit: None, - style_sheet: Default::default(), + style: Default::default(), } } @@ -83,7 +88,7 @@ where /// 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 { self.font = font; self @@ -116,9 +121,9 @@ where /// Sets the style of the [`TextInput`]. pub fn style( mut self, - style_sheet: impl Into>, + style: impl Into<::Style>, ) -> Self { - self.style_sheet = style_sheet.into(); + self.style = style.into(); self } } @@ -127,7 +132,8 @@ impl<'a, Message, Renderer> Widget for TextInput<'a, Message, Renderer> where Message: Clone, - Renderer: iced_native::text::Renderer, + Renderer: text::Renderer, + Renderer::Theme: StyleSheet, { fn tag(&self) -> tree::Tag { tree::Tag::of::() @@ -198,6 +204,7 @@ where ) { text_input::draw( renderer, + theme, layout, cursor_position, tree.state.downcast_ref::(), @@ -206,7 +213,7 @@ where self.size, &self.font, self.is_secure, - self.style_sheet.as_ref(), + self.style, ) } @@ -227,6 +234,7 @@ impl<'a, Message, Renderer> From> where Message: 'a + Clone, Renderer: 'a + text::Renderer, + Renderer::Theme: StyleSheet, { fn from( text_input: TextInput<'a, Message, Renderer>, -- cgit