From 0030bcbd33f5c4db60aac826552042e46b51c691 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Feb 2020 00:23:22 +0100 Subject: Rename module `style` to `css` in `iced_web` --- web/src/widget/text_input.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 078e05b2..1fea787a 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -4,7 +4,7 @@ //! //! [`TextInput`]: struct.TextInput.html //! [`State`]: struct.State.html -use crate::{bumpalo, style, Bus, Element, Length, Style, Widget}; +use crate::{bumpalo, css, Bus, Css, Element, Length, Widget}; use std::rc::Rc; /// A field that can be filled with text. @@ -133,15 +133,15 @@ where &self, bump: &'b bumpalo::Bump, bus: &Bus, - style_sheet: &mut style::Sheet<'b>, + style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; use wasm_bindgen::JsCast; - let width = style::length(self.width); - let max_width = style::length(self.max_width); + let width = css::length(self.width); + let max_width = css::length(self.max_width); let padding_class = - style_sheet.insert(bump, Style::Padding(self.padding)); + style_sheet.insert(bump, css::Rule::Padding(self.padding)); let on_change = self.on_change.clone(); let event_bus = bus.clone(); -- cgit From ce45ecc23546efd85f04a76fcb1a3a691d259129 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:28:25 +0100 Subject: Expose missing widget modules in `iced_web` --- web/src/widget/text_input.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 1fea787a..2b22b93f 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -5,6 +5,9 @@ //! [`TextInput`]: struct.TextInput.html //! [`State`]: struct.State.html use crate::{bumpalo, css, Bus, Css, Element, Length, Widget}; + +pub use iced_style::text_input::{Style, StyleSheet}; + use std::rc::Rc; /// A field that can be filled with text. -- cgit From e953733323c1c2a50cc511408167c7982f84bf06 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 01:26:08 +0100 Subject: Add style to `TextInput` in `iced_web` --- web/src/widget/text_input.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 2b22b93f..c1034e43 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -42,6 +42,7 @@ pub struct TextInput<'a, Message> { size: Option, on_change: Rc Message>>, on_submit: Option, + style: Box, } impl<'a, Message> TextInput<'a, Message> { @@ -75,6 +76,7 @@ impl<'a, Message> TextInput<'a, Message> { size: None, on_change: Rc::new(Box::new(on_change)), on_submit: None, + style: Default::default(), } } @@ -126,6 +128,14 @@ impl<'a, Message> TextInput<'a, Message> { self.on_submit = Some(message); self } + + /// Sets the style of the [`TextInput`]. + /// + /// [`TextInput`]: struct.TextInput.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); + self + } } impl<'a, Message> Widget for TextInput<'a, Message> -- cgit From 282ae1dc9e4d0aa4dec4cee575b5eaa5f9a90b8d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 02:37:49 +0100 Subject: Implement `TextInput` styling in `iced_web` --- web/src/widget/text_input.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index c1034e43..0992208b 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -8,7 +8,7 @@ use crate::{bumpalo, css, Bus, Css, Element, Length, Widget}; pub use iced_style::text_input::{Style, StyleSheet}; -use std::rc::Rc; +use std::{rc::Rc, u32}; /// A field that can be filled with text. /// @@ -37,12 +37,12 @@ pub struct TextInput<'a, Message> { value: String, is_secure: bool, width: Length, - max_width: Length, + max_width: u32, padding: u16, size: Option, on_change: Rc Message>>, on_submit: Option, - style: Box, + style_sheet: Box, } impl<'a, Message> TextInput<'a, Message> { @@ -71,12 +71,12 @@ impl<'a, Message> TextInput<'a, Message> { value: String::from(value), is_secure: false, width: Length::Fill, - max_width: Length::Shrink, + max_width: u32::MAX, padding: 0, size: None, on_change: Rc::new(Box::new(on_change)), on_submit: None, - style: Default::default(), + style_sheet: Default::default(), } } @@ -99,7 +99,7 @@ impl<'a, Message> TextInput<'a, Message> { /// Sets the maximum width of the [`TextInput`]. /// /// [`TextInput`]: struct.TextInput.html - pub fn max_width(mut self, max_width: Length) -> Self { + pub fn max_width(mut self, max_width: u32) -> Self { self.max_width = max_width; self } @@ -133,7 +133,7 @@ impl<'a, Message> TextInput<'a, Message> { /// /// [`TextInput`]: struct.TextInput.html pub fn style(mut self, style: impl Into>) -> Self { - self.style = style.into(); + self.style_sheet = style.into(); self } } @@ -151,13 +151,12 @@ where use dodrio::builder::*; use wasm_bindgen::JsCast; - let width = css::length(self.width); - let max_width = css::length(self.max_width); let padding_class = style_sheet.insert(bump, css::Rule::Padding(self.padding)); let on_change = self.on_change.clone(); let event_bus = bus.clone(); + let style = self.style_sheet.active(); input(bump) .attr( @@ -168,10 +167,15 @@ where "style", bumpalo::format!( in bump, - "width: {}; max-width: {}; font-size: {}px", - width, - max_width, - self.size.unwrap_or(20) + "width: {}; max-width: {}; font-size: {}px; background: {}; border-width: {}px; border-color: {}; border-radius: {}px; color: {}", + css::length(self.width), + css::max_length(self.max_width), + self.size.unwrap_or(20), + css::background(style.background), + style.border_width, + css::color(style.border_color), + style.border_radius, + css::color(self.style_sheet.value_color()) ) .into_bump_str(), ) -- cgit From 57aed1d5c61a14fa6337e9f838fc519efdd75e06 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 03:06:06 +0100 Subject: Implement `TextInput::on_submit` support in `iced_web` --- web/src/widget/text_input.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'web/src/widget/text_input.rs') diff --git a/web/src/widget/text_input.rs b/web/src/widget/text_input.rs index 0992208b..3fa458bd 100644 --- a/web/src/widget/text_input.rs +++ b/web/src/widget/text_input.rs @@ -155,7 +155,9 @@ where style_sheet.insert(bump, css::Rule::Padding(self.padding)); let on_change = self.on_change.clone(); - let event_bus = bus.clone(); + let on_submit = self.on_submit.clone(); + let input_event_bus = bus.clone(); + let submit_event_bus = bus.clone(); let style = self.style_sheet.active(); input(bump) @@ -200,7 +202,17 @@ where Some(text_input) => text_input, }; - event_bus.publish(on_change(text_input.value())); + input_event_bus.publish(on_change(text_input.value())); + }) + .on("keypress", move |_root, _vdom, event| { + if let Some(on_submit) = on_submit.clone() { + let event = event.unchecked_into::(); + + match event.key_code() { + 13 => { submit_event_bus.publish(on_submit); } + _ => {} + } + } }) .finish() } @@ -228,4 +240,12 @@ impl State { pub fn new() -> Self { Self::default() } + + /// Creates a new [`State`], representing a focused [`TextInput`]. + /// + /// [`State`]: struct.State.html + pub fn focused() -> Self { + // TODO + Self::default() + } } -- cgit