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/button.rs | 10 +++++----- web/src/widget/checkbox.rs | 4 ++-- web/src/widget/column.rs | 16 ++++++++-------- web/src/widget/container.rs | 14 +++++++------- web/src/widget/image.rs | 4 ++-- web/src/widget/radio.rs | 4 ++-- web/src/widget/row.rs | 16 ++++++++-------- web/src/widget/scrollable.rs | 8 ++++---- web/src/widget/slider.rs | 4 ++-- web/src/widget/space.rs | 8 ++++---- web/src/widget/text.rs | 10 +++++----- web/src/widget/text_input.rs | 10 +++++----- 12 files changed, 54 insertions(+), 54 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index 6fef48ce..f3b3e69a 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -4,7 +4,7 @@ //! //! [`Button`]: struct.Button.html //! [`State`]: struct.State.html -use crate::{style, Background, Bus, Element, Length, Style, Widget}; +use crate::{css, Background, Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; @@ -126,18 +126,18 @@ 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::*; - let width = style::length(self.width); + let width = css::length(self.width); let padding_class = - style_sheet.insert(bump, Style::Padding(self.padding)); + style_sheet.insert(bump, css::Rule::Padding(self.padding)); let background = match self.background { None => String::from("none"), Some(background) => match background { - Background::Color(color) => style::color(color), + Background::Color(color) => css::color(color), }, }; diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index 1e864875..d1d30048 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -1,4 +1,4 @@ -use crate::{style, Bus, Color, Element, Widget}; +use crate::{Bus, Color, Css, Element, Widget}; use dodrio::bumpalo; use std::rc::Rc; @@ -68,7 +68,7 @@ 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::*; diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index 9aa988ff..8e36231a 100644 --- a/web/src/widget/column.rs +++ b/web/src/widget/column.rs @@ -1,4 +1,4 @@ -use crate::{style, Align, Bus, Element, Length, Style, Widget}; +use crate::{css, Align, Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; use std::u32; @@ -112,7 +112,7 @@ impl<'a, Message> Widget for Column<'a, Message> { &self, bump: &'b bumpalo::Bump, publish: &Bus, - style_sheet: &mut style::Sheet<'b>, + style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; @@ -122,18 +122,18 @@ impl<'a, Message> Widget for Column<'a, Message> { .map(|element| element.widget.node(bump, publish, style_sheet)) .collect(); - let column_class = style_sheet.insert(bump, Style::Column); + let column_class = style_sheet.insert(bump, css::Rule::Column); let spacing_class = - style_sheet.insert(bump, Style::Spacing(self.spacing)); + style_sheet.insert(bump, css::Rule::Spacing(self.spacing)); let padding_class = - style_sheet.insert(bump, Style::Padding(self.padding)); + style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); - let align_items = style::align(self.align_items); + let align_items = css::align(self.align_items); // TODO: Complete styling div(bump) diff --git a/web/src/widget/container.rs b/web/src/widget/container.rs index bdc88979..55995795 100644 --- a/web/src/widget/container.rs +++ b/web/src/widget/container.rs @@ -1,4 +1,4 @@ -use crate::{bumpalo, style, Align, Bus, Element, Length, Style, Widget}; +use crate::{bumpalo, css, Align, Bus, Css, Element, Length, Widget}; /// An element decorating some content. /// @@ -94,17 +94,17 @@ 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::*; - let column_class = style_sheet.insert(bump, Style::Column); + let column_class = style_sheet.insert(bump, css::Rule::Column); - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); - let align_items = style::align(self.horizontal_alignment); - let justify_content = style::align(self.vertical_alignment); + let align_items = css::align(self.horizontal_alignment); + let justify_content = css::align(self.vertical_alignment); let node = div(bump) .attr( diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index 413b663e..17e9b0f7 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -1,4 +1,4 @@ -use crate::{style, Bus, Element, Length, Widget}; +use crate::{Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; @@ -57,7 +57,7 @@ impl Widget for Image { &self, bump: &'b bumpalo::Bump, _bus: &Bus, - _style_sheet: &mut style::Sheet<'b>, + _style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index 6dd0ad45..4570639c 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -1,4 +1,4 @@ -use crate::{style, Bus, Color, Element, Widget}; +use crate::{Bus, Color, Css, Element, Widget}; use dodrio::bumpalo; @@ -76,7 +76,7 @@ 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::*; diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs index c26cb91b..6e184cab 100644 --- a/web/src/widget/row.rs +++ b/web/src/widget/row.rs @@ -1,4 +1,4 @@ -use crate::{style, Align, Bus, Element, Length, Style, Widget}; +use crate::{css, Align, Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; use std::u32; @@ -113,7 +113,7 @@ impl<'a, Message> Widget for Row<'a, Message> { &self, bump: &'b bumpalo::Bump, publish: &Bus, - style_sheet: &mut style::Sheet<'b>, + style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; @@ -123,18 +123,18 @@ impl<'a, Message> Widget for Row<'a, Message> { .map(|element| element.widget.node(bump, publish, style_sheet)) .collect(); - let row_class = style_sheet.insert(bump, Style::Row); + let row_class = style_sheet.insert(bump, css::Rule::Row); let spacing_class = - style_sheet.insert(bump, Style::Spacing(self.spacing)); + style_sheet.insert(bump, css::Rule::Spacing(self.spacing)); let padding_class = - style_sheet.insert(bump, Style::Padding(self.padding)); + style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); - let justify_content = style::align(self.align_items); + let justify_content = css::align(self.align_items); // TODO: Complete styling div(bump) diff --git a/web/src/widget/scrollable.rs b/web/src/widget/scrollable.rs index f146e007..19810531 100644 --- a/web/src/widget/scrollable.rs +++ b/web/src/widget/scrollable.rs @@ -1,5 +1,5 @@ //! Navigate an endless amount of content with a scrollbar. -use crate::{bumpalo, style, Align, Bus, Column, Element, Length, Widget}; +use crate::{bumpalo, css, Align, Bus, Column, Css, Element, Length, Widget}; /// A widget that can vertically display an infinite amount of content with a /// scrollbar. @@ -105,12 +105,12 @@ 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::*; - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); let node = div(bump) .attr( diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index 25c57933..843003e6 100644 --- a/web/src/widget/slider.rs +++ b/web/src/widget/slider.rs @@ -4,7 +4,7 @@ //! //! [`Slider`]: struct.Slider.html //! [`State`]: struct.State.html -use crate::{style, Bus, Element, Length, Widget}; +use crate::{Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; use std::{ops::RangeInclusive, rc::Rc}; @@ -88,7 +88,7 @@ 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; diff --git a/web/src/widget/space.rs b/web/src/widget/space.rs index baf4c80b..4ce52595 100644 --- a/web/src/widget/space.rs +++ b/web/src/widget/space.rs @@ -1,4 +1,4 @@ -use crate::{style, Bus, Element, Length, Widget}; +use crate::{css, Bus, Css, Element, Length, Widget}; use dodrio::bumpalo; /// An amount of empty space. @@ -44,12 +44,12 @@ impl<'a, Message> Widget for Space { &self, bump: &'b bumpalo::Bump, _publish: &Bus, - _style_sheet: &mut style::Sheet<'b>, + _css: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); let style = bumpalo::format!( in bump, diff --git a/web/src/widget/text.rs b/web/src/widget/text.rs index 5b0bee55..c5b07747 100644 --- a/web/src/widget/text.rs +++ b/web/src/widget/text.rs @@ -1,5 +1,5 @@ use crate::{ - style, Bus, Color, Element, Font, HorizontalAlignment, Length, + css, Bus, Color, Css, Element, Font, HorizontalAlignment, Length, VerticalAlignment, Widget, }; use dodrio::bumpalo; @@ -112,15 +112,15 @@ impl<'a, Message> Widget for Text { &self, bump: &'b bumpalo::Bump, _publish: &Bus, - _style_sheet: &mut style::Sheet<'b>, + _style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; let content = bumpalo::format!(in bump, "{}", self.content); - let color = style::color(self.color.unwrap_or(Color::BLACK)); + let color = css::color(self.color.unwrap_or(Color::BLACK)); - let width = style::length(self.width); - let height = style::length(self.height); + let width = css::length(self.width); + let height = css::length(self.height); let text_align = match self.horizontal_alignment { HorizontalAlignment::Left => "left", 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 28fd9feb40a024ea29f73fa91c21fc3f2cf01d58 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Feb 2020 01:04:46 +0100 Subject: Support styling for `Button` in `iced_web` --- web/src/widget/button.rs | 57 ++++++++++++++++++++++++++++++------------------ web/src/widget/column.rs | 2 +- web/src/widget/row.rs | 2 +- web/src/widget/text.rs | 5 ++++- 4 files changed, 42 insertions(+), 24 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index f3b3e69a..e47b971d 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -6,6 +6,8 @@ //! [`State`]: struct.State.html use crate::{css, Background, Bus, Css, Element, Length, Widget}; +pub use iced_style::button::{Style, StyleSheet}; + use dodrio::bumpalo; /// A generic widget that produces a message when pressed. @@ -26,10 +28,11 @@ pub struct Button<'a, Message> { content: Element<'a, Message>, on_press: Option, width: Length, + height: Length, min_width: u32, + min_height: u32, padding: u16, - background: Option, - border_radius: u16, + style: Box, } impl<'a, Message> Button<'a, Message> { @@ -46,10 +49,11 @@ impl<'a, Message> Button<'a, Message> { content: content.into(), on_press: None, width: Length::Shrink, + height: Length::Shrink, min_width: 0, - padding: 0, - background: None, - border_radius: 0, + min_height: 0, + padding: 5, + style: Default::default(), } } @@ -61,6 +65,14 @@ impl<'a, Message> Button<'a, Message> { self } + /// Sets the height of the [`Button`]. + /// + /// [`Button`]: struct.Button.html + pub fn height(mut self, height: Length) -> Self { + self.height = height; + self + } + /// Sets the minimum width of the [`Button`]. /// /// [`Button`]: struct.Button.html @@ -69,28 +81,27 @@ impl<'a, Message> Button<'a, Message> { self } - /// Sets the padding of the [`Button`]. + /// Sets the minimum height of the [`Button`]. /// /// [`Button`]: struct.Button.html - pub fn padding(mut self, padding: u16) -> Self { - self.padding = padding; + pub fn min_height(mut self, min_height: u32) -> Self { + self.min_height = min_height; self } - /// Sets the [`Background`] of the [`Button`]. + /// Sets the padding of the [`Button`]. /// /// [`Button`]: struct.Button.html - /// [`Background`]: ../../struct.Background.html - pub fn background>(mut self, background: T) -> Self { - self.background = Some(background.into()); + pub fn padding(mut self, padding: u16) -> Self { + self.padding = padding; self } - /// Sets the border radius of the [`Button`]. + /// Sets the style of the [`Button`]. /// /// [`Button`]: struct.Button.html - pub fn border_radius(mut self, border_radius: u16) -> Self { - self.border_radius = border_radius; + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); self } @@ -130,11 +141,16 @@ where ) -> dodrio::Node<'b> { use dodrio::builder::*; + // TODO: State-based styling + let style = self.style.active(); + let width = css::length(self.width); + let color = css::color(style.text_color); + let padding_class = style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let background = match self.background { + let background = match style.background { None => String::from("none"), Some(background) => match background { Background::Color(color) => css::color(color), @@ -150,11 +166,12 @@ where "style", bumpalo::format!( in bump, - "background: {}; border-radius: {}px; width:{}; min-width: {}px", + "background: {}; border-radius: {}px; width:{}; min-width: {}px; color: {}", background, - self.border_radius, + style.border_radius, width, - self.min_width + self.min_width, + color ) .into_bump_str(), ) @@ -168,8 +185,6 @@ where }); } - // TODO: Complete styling - node.finish() } } diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index 8e36231a..640d3673 100644 --- a/web/src/widget/column.rs +++ b/web/src/widget/column.rs @@ -28,7 +28,7 @@ impl<'a, Message> Column<'a, Message> { Column { spacing: 0, padding: 0, - width: Length::Shrink, + width: Length::Fill, height: Length::Shrink, max_width: u32::MAX, max_height: u32::MAX, diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs index 6e184cab..b360bc45 100644 --- a/web/src/widget/row.rs +++ b/web/src/widget/row.rs @@ -28,7 +28,7 @@ impl<'a, Message> Row<'a, Message> { Row { spacing: 0, padding: 0, - width: Length::Shrink, + width: Length::Fill, height: Length::Shrink, max_width: u32::MAX, max_height: u32::MAX, diff --git a/web/src/widget/text.rs b/web/src/widget/text.rs index c5b07747..46230fef 100644 --- a/web/src/widget/text.rs +++ b/web/src/widget/text.rs @@ -117,7 +117,10 @@ impl<'a, Message> Widget for Text { use dodrio::builder::*; let content = bumpalo::format!(in bump, "{}", self.content); - let color = css::color(self.color.unwrap_or(Color::BLACK)); + let color = self + .color + .map(css::color) + .unwrap_or(String::from("inherit")); let width = css::length(self.width); let height = css::length(self.height); -- cgit From 9a06e481b7f52a9d8e123c909d5614332f607c53 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 5 Feb 2020 04:13:13 +0100 Subject: Add `Handle` and `Data` to `image` in `iced_web` --- web/src/widget/image.rs | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 5 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index 17e9b0f7..4296d0e2 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -1,6 +1,12 @@ -use crate::{Bus, Css, Element, Length, Widget}; +//! Display images in your user interface. +use crate::{Bus, Css, Element, Hasher, Length, Widget}; use dodrio::bumpalo; +use std::{ + hash::{Hash, Hasher as _}, + path::PathBuf, + sync::Arc, +}; /// A frame that displays an image while keeping aspect ratio. /// @@ -14,7 +20,7 @@ use dodrio::bumpalo; #[derive(Debug)] pub struct Image { /// The image path - pub path: String, + pub handle: Handle, /// The width of the image pub width: Length, @@ -27,9 +33,9 @@ impl Image { /// Creates a new [`Image`] with the given path. /// /// [`Image`]: struct.Image.html - pub fn new>(path: T) -> Self { + pub fn new>(handle: T) -> Self { Image { - path: path.into(), + handle: handle.into(), width: Length::Shrink, height: Length::Shrink, } @@ -61,7 +67,9 @@ impl Widget for Image { ) -> dodrio::Node<'b> { use dodrio::builder::*; - let src = bumpalo::format!(in bump, "{}", self.path); + let src = bumpalo::format!(in bump, "{}", match self.handle.data.as_ref() { + Data::Path(path) => path.to_str().unwrap_or("") + }); let mut image = img(bump).attr("src", src.into_bump_str()); @@ -89,3 +97,68 @@ impl<'a, Message> From for Element<'a, Message> { Element::new(image) } } + +/// An [`Image`] handle. +/// +/// [`Image`]: struct.Image.html +#[derive(Debug, Clone)] +pub struct Handle { + id: u64, + data: Arc, +} + +impl Handle { + /// Creates an image [`Handle`] pointing to the image of the given path. + /// + /// [`Handle`]: struct.Handle.html + pub fn from_path>(path: T) -> Handle { + Self::from_data(Data::Path(path.into())) + } + + fn from_data(data: Data) -> Handle { + let mut hasher = Hasher::default(); + data.hash(&mut hasher); + + Handle { + id: hasher.finish(), + data: Arc::new(data), + } + } + + /// Returns the unique identifier of the [`Handle`]. + /// + /// [`Handle`]: struct.Handle.html + pub fn id(&self) -> u64 { + self.id + } + + /// Returns a reference to the image [`Data`]. + /// + /// [`Data`]: enum.Data.html + pub fn data(&self) -> &Data { + &self.data + } +} + +impl From<&str> for Handle { + fn from(path: &str) -> Handle { + Handle::from_path(path) + } +} + +/// The data of an [`Image`]. +/// +/// [`Image`]: struct.Image.html +#[derive(Clone, Hash)] +pub enum Data { + /// A remote image + Path(PathBuf), +} + +impl std::fmt::Debug for Data { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Data::Path(path) => write!(f, "Path({:?})", path), + } + } +} -- cgit From ad13b466d234f04784bf77be0b4cb82acdfa1ea2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:16:59 +0100 Subject: Add `From` for `image::Handle` in `iced_web` --- web/src/widget/image.rs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'web/src/widget') diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs index 4296d0e2..029ab352 100644 --- a/web/src/widget/image.rs +++ b/web/src/widget/image.rs @@ -140,6 +140,12 @@ impl Handle { } } +impl From for Handle { + fn from(path: String) -> Handle { + Handle::from_path(path) + } +} + impl From<&str> for Handle { fn from(path: &str) -> Handle { Handle::from_path(path) -- cgit From c2dad2942916ba30435a8e26ccca17f64c092b44 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:20:55 +0100 Subject: Expose styling types for `slider` in `iced_web` --- web/src/widget/slider.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'web/src/widget') diff --git a/web/src/widget/slider.rs b/web/src/widget/slider.rs index 843003e6..5aa6439e 100644 --- a/web/src/widget/slider.rs +++ b/web/src/widget/slider.rs @@ -6,6 +6,8 @@ //! [`State`]: struct.State.html use crate::{Bus, Css, Element, Length, Widget}; +pub use iced_style::slider::{Handle, HandleShape, Style, StyleSheet}; + use dodrio::bumpalo; use std::{ops::RangeInclusive, rc::Rc}; @@ -38,6 +40,7 @@ pub struct Slider<'a, Message> { value: f32, on_change: Rc Message>>, width: Length, + style: Box, } impl<'a, Message> Slider<'a, Message> { @@ -68,6 +71,7 @@ impl<'a, Message> Slider<'a, Message> { range, on_change: Rc::new(Box::new(on_change)), width: Length::Fill, + style: Default::default(), } } @@ -78,6 +82,14 @@ impl<'a, Message> Slider<'a, Message> { self.width = width; self } + + /// Sets the style of the [`Slider`]. + /// + /// [`Slider`]: struct.Slider.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); + self + } } impl<'a, Message> Widget for Slider<'a, Message> @@ -103,7 +115,7 @@ where let event_bus = bus.clone(); // TODO: Make `step` configurable - // TODO: Complete styling + // TODO: Styling input(bump) .attr("type", "range") .attr("step", "0.01") -- cgit From 9a7f7bfdf5afa329a60beab6556d739cf5d19b50 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:23:44 +0100 Subject: Expose styling types for `scrollable` in `iced_web` --- web/src/widget/scrollable.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/scrollable.rs b/web/src/widget/scrollable.rs index 19810531..07b38aad 100644 --- a/web/src/widget/scrollable.rs +++ b/web/src/widget/scrollable.rs @@ -1,6 +1,8 @@ //! Navigate an endless amount of content with a scrollbar. use crate::{bumpalo, css, Align, Bus, Column, Css, Element, Length, Widget}; +pub use iced_style::scrollable::{Scrollbar, Scroller, StyleSheet}; + /// A widget that can vertically display an infinite amount of content with a /// scrollbar. #[allow(missing_debug_implementations)] @@ -9,6 +11,7 @@ pub struct Scrollable<'a, Message> { height: Length, max_height: u32, content: Column<'a, Message>, + style: Box, } impl<'a, Message> Scrollable<'a, Message> { @@ -24,6 +27,7 @@ impl<'a, Message> Scrollable<'a, Message> { height: Length::Shrink, max_height: u32::MAX, content: Column::new(), + style: Default::default(), } } @@ -85,6 +89,14 @@ impl<'a, Message> Scrollable<'a, Message> { self } + /// Sets the style of the [`Scrollable`] . + /// + /// [`Scrollable`]: struct.Scrollable.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); + self + } + /// Adds an element to the [`Scrollable`]. /// /// [`Scrollable`]: struct.Scrollable.html @@ -112,6 +124,8 @@ where let width = css::length(self.width); let height = css::length(self.height); + // TODO: Scrollbar styling + let node = div(bump) .attr( "style", @@ -126,8 +140,6 @@ where ) .children(vec![self.content.node(bump, bus, style_sheet)]); - // TODO: Complete styling - node.finish() } } -- 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/checkbox.rs | 1 + web/src/widget/container.rs | 1 + web/src/widget/radio.rs | 1 + web/src/widget/text_input.rs | 3 +++ 4 files changed, 6 insertions(+) (limited to 'web/src/widget') diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index d1d30048..7c7b805c 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -1,3 +1,4 @@ +//! Show toggle controls using checkboxes. use crate::{Bus, Color, Css, Element, Widget}; use dodrio::bumpalo; diff --git a/web/src/widget/container.rs b/web/src/widget/container.rs index 55995795..43d9abf7 100644 --- a/web/src/widget/container.rs +++ b/web/src/widget/container.rs @@ -1,3 +1,4 @@ +//! Decorate content and apply alignment. use crate::{bumpalo, css, Align, Bus, Css, Element, Length, Widget}; /// An element decorating some content. diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index 4570639c..e8721cee 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -1,3 +1,4 @@ +//! Create choices using radio buttons. use crate::{Bus, Color, Css, Element, Widget}; use dodrio::bumpalo; 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 abdae3a7ec1413df86fca93699fb2448226e2da5 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:31:52 +0100 Subject: Expose styling types for `checkbox` in `iced_web` --- web/src/widget/checkbox.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index 7c7b805c..5160e221 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -1,5 +1,7 @@ //! Show toggle controls using checkboxes. -use crate::{Bus, Color, Css, Element, Widget}; +use crate::{Bus, Css, Element, Length, Widget}; + +pub use iced_style::checkbox::{Style, StyleSheet}; use dodrio::bumpalo; use std::rc::Rc; @@ -26,7 +28,8 @@ pub struct Checkbox { is_checked: bool, on_toggle: Rc Message>, label: String, - label_color: Option, + width: Length, + style: Box, } impl Checkbox { @@ -48,15 +51,24 @@ impl Checkbox { is_checked, on_toggle: Rc::new(f), label: String::from(label), - label_color: None, + width: Length::Shrink, + style: Default::default(), } } - /// Sets the color of the label of the [`Checkbox`]. + /// Sets the width of the [`Checkbox`]. /// /// [`Checkbox`]: struct.Checkbox.html - pub fn label_color>(mut self, color: C) -> Self { - self.label_color = Some(color.into()); + pub fn width(mut self, width: Length) -> Self { + self.width = width; + self + } + + /// Sets the style of the [`Checkbox`]. + /// + /// [`Checkbox`]: struct.Checkbox.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); self } } @@ -79,7 +91,8 @@ where let on_toggle = self.on_toggle.clone(); let is_checked = self.is_checked; - // TODO: Complete styling + // TODO: Styling + label(bump) .children(vec![ input(bump) -- cgit From b4a8471aa187de511301605a56cf531923dfb6bd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:33:26 +0100 Subject: Expose styling types for `radio` in `iced_web` --- web/src/widget/radio.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/radio.rs b/web/src/widget/radio.rs index e8721cee..e00e26db 100644 --- a/web/src/widget/radio.rs +++ b/web/src/widget/radio.rs @@ -1,5 +1,7 @@ //! Create choices using radio buttons. -use crate::{Bus, Color, Css, Element, Widget}; +use crate::{Bus, Css, Element, Widget}; + +pub use iced_style::radio::{Style, StyleSheet}; use dodrio::bumpalo; @@ -33,7 +35,7 @@ pub struct Radio { is_selected: bool, on_click: Message, label: String, - label_color: Option, + style: Box, } impl Radio { @@ -56,15 +58,15 @@ impl Radio { is_selected: Some(value) == selected, on_click: f(value), label: String::from(label), - label_color: None, + style: Default::default(), } } - /// Sets the `Color` of the label of the [`Radio`]. + /// Sets the style of the [`Radio`] button. /// /// [`Radio`]: struct.Radio.html - pub fn label_color>(mut self, color: C) -> Self { - self.label_color = Some(color.into()); + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); self } } -- cgit From 58a7be0a31793400e5686f8e2af558f2307bebcd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 00:36:00 +0100 Subject: Expose styling types for `container` in `iced_web` --- web/src/widget/container.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'web/src/widget') diff --git a/web/src/widget/container.rs b/web/src/widget/container.rs index 43d9abf7..767fed67 100644 --- a/web/src/widget/container.rs +++ b/web/src/widget/container.rs @@ -1,6 +1,8 @@ //! Decorate content and apply alignment. use crate::{bumpalo, css, Align, Bus, Css, Element, Length, Widget}; +pub use iced_style::container::{Style, StyleSheet}; + /// An element decorating some content. /// /// It is normally used for alignment purposes. @@ -12,6 +14,7 @@ pub struct Container<'a, Message> { max_height: u32, horizontal_alignment: Align, vertical_alignment: Align, + style: Box, content: Element<'a, Message>, } @@ -32,6 +35,7 @@ impl<'a, Message> Container<'a, Message> { max_height: u32::MAX, horizontal_alignment: Align::Start, vertical_alignment: Align::Start, + style: Default::default(), content: content.into(), } } @@ -85,6 +89,14 @@ impl<'a, Message> Container<'a, Message> { self } + + /// Sets the style of the [`Container`]. + /// + /// [`Container`]: struct.Container.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); + self + } } impl<'a, Message> Widget for Container<'a, Message> -- cgit From f5228695a2fcdecd1da9071d477ee34855783b29 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 01:24:40 +0100 Subject: Implement `ProgressBar` widget in `iced_web` --- web/src/widget/progress_bar.rs | 125 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 web/src/widget/progress_bar.rs (limited to 'web/src/widget') diff --git a/web/src/widget/progress_bar.rs b/web/src/widget/progress_bar.rs new file mode 100644 index 00000000..b1fcb4d8 --- /dev/null +++ b/web/src/widget/progress_bar.rs @@ -0,0 +1,125 @@ +//! Provide progress feedback to your users. +use crate::{bumpalo, css, Bus, Css, Element, Length, Widget}; + +pub use iced_style::progress_bar::{Style, StyleSheet}; + +use std::ops::RangeInclusive; + +/// A bar that displays progress. +/// +/// # Example +/// ``` +/// # use iced_native::renderer::Null; +/// # +/// # pub type ProgressBar = iced_native::ProgressBar; +/// let value = 50.0; +/// +/// ProgressBar::new(0.0..=100.0, value); +/// ``` +/// +/// ![Progress bar drawn with `iced_wgpu`](https://user-images.githubusercontent.com/18618951/71662391-a316c200-2d51-11ea-9cef-52758cab85e3.png) +#[allow(missing_debug_implementations)] +pub struct ProgressBar { + range: RangeInclusive, + value: f32, + width: Length, + height: Option, + style: Box, +} + +impl ProgressBar { + /// Creates a new [`ProgressBar`]. + /// + /// It expects: + /// * an inclusive range of possible values + /// * the current value of the [`ProgressBar`] + /// + /// [`ProgressBar`]: struct.ProgressBar.html + pub fn new(range: RangeInclusive, value: f32) -> Self { + ProgressBar { + value: value.max(*range.start()).min(*range.end()), + range, + width: Length::Fill, + height: None, + style: Default::default(), + } + } + + /// Sets the width of the [`ProgressBar`]. + /// + /// [`ProgressBar`]: struct.ProgressBar.html + pub fn width(mut self, width: Length) -> Self { + self.width = width; + self + } + + /// Sets the height of the [`ProgressBar`]. + /// + /// [`ProgressBar`]: struct.ProgressBar.html + pub fn height(mut self, height: Length) -> Self { + self.height = Some(height); + self + } + + /// Sets the style of the [`ProgressBar`]. + /// + /// [`ProgressBar`]: struct.ProgressBar.html + pub fn style(mut self, style: impl Into>) -> Self { + self.style = style.into(); + self + } +} + +impl Widget for ProgressBar { + fn node<'b>( + &self, + bump: &'b bumpalo::Bump, + _bus: &Bus, + _style_sheet: &mut Css<'b>, + ) -> dodrio::Node<'b> { + use dodrio::builder::*; + + let (range_start, range_end) = self.range.clone().into_inner(); + let amount_filled = + (self.value - range_start) / (range_end - range_start).max(1.0); + + let style = self.style.style(); + + let bar = div(bump) + .attr( + "style", + bumpalo::format!( + in bump, + "width: {}%; height: 100%; background: {}", + amount_filled * 100.0, + css::background(style.bar) + ) + .into_bump_str(), + ) + .finish(); + + let node = div(bump).attr( + "style", + bumpalo::format!( + in bump, + "width: {}; height: {}; background: {}; border-radius: {}px; overflow: hidden;", + css::length(self.width), + css::length(self.height.unwrap_or(Length::Units(30))), + css::background(style.background), + style.border_radius + ) + .into_bump_str(), + ).children(vec![bar]); + + node.finish() + } +} + +impl<'a, Message> From for Element<'a, Message> +where + Message: 'static, +{ + fn from(container: ProgressBar) -> Element<'a, Message> { + Element::new(container) + } +} -- cgit From 38a35ab639de3cb14cafa2cecef7ecf56d29b631 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 01:25:03 +0100 Subject: Fix `Button` styling in `iced_web` --- web/src/widget/button.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/button.rs b/web/src/widget/button.rs index e47b971d..3a5afe60 100644 --- a/web/src/widget/button.rs +++ b/web/src/widget/button.rs @@ -144,9 +144,6 @@ where // TODO: State-based styling let style = self.style.active(); - let width = css::length(self.width); - let color = css::color(style.text_color); - let padding_class = style_sheet.insert(bump, css::Rule::Padding(self.padding)); @@ -166,12 +163,12 @@ where "style", bumpalo::format!( in bump, - "background: {}; border-radius: {}px; width:{}; min-width: {}px; color: {}", + "background: {}; border-radius: {}px; width:{}; min-width: {}; color: {}", background, style.border_radius, - width, - self.min_width, - color + css::length(self.width), + css::min_length(self.min_width), + css::color(style.text_color) ) .into_bump_str(), ) -- cgit From 6c8fdfefbe6ea8cd1cc11a4a822285c28c278880 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 01:25:22 +0100 Subject: Fix `Checkbox` styling in `iced_web` --- web/src/widget/checkbox.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/checkbox.rs b/web/src/widget/checkbox.rs index 5160e221..0657ccfb 100644 --- a/web/src/widget/checkbox.rs +++ b/web/src/widget/checkbox.rs @@ -1,5 +1,5 @@ //! Show toggle controls using checkboxes. -use crate::{Bus, Css, Element, Length, Widget}; +use crate::{css, Bus, Css, Element, Length, Widget}; pub use iced_style::checkbox::{Style, StyleSheet}; @@ -81,7 +81,7 @@ where &self, bump: &'b bumpalo::Bump, bus: &Bus, - _style_sheet: &mut Css<'b>, + style_sheet: &mut Css<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; @@ -91,10 +91,23 @@ where let on_toggle = self.on_toggle.clone(); let is_checked = self.is_checked; - // TODO: Styling + let row_class = style_sheet.insert(bump, css::Rule::Row); + + let spacing_class = style_sheet.insert(bump, css::Rule::Spacing(5)); label(bump) + .attr( + "class", + bumpalo::format!(in bump, "{} {}", row_class, spacing_class) + .into_bump_str(), + ) + .attr( + "style", + bumpalo::format!(in bump, "width: {}; align-items: center", css::length(self.width)) + .into_bump_str(), + ) .children(vec![ + // TODO: Checkbox styling input(bump) .attr("type", "checkbox") .bool_attr("checked", self.is_checked) @@ -105,7 +118,8 @@ where vdom.schedule_render(); }) .finish(), - text(checkbox_label.into_bump_str()), + span(bump).children(vec![ + text(checkbox_label.into_bump_str())]).finish(), ]) .finish() } -- cgit From 8e83f3632c7b06370ce47d975750313a56221d28 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 01:25:46 +0100 Subject: Fix `Column` and `Row` styling for `iced_web` --- web/src/widget/column.rs | 17 ++++++----------- web/src/widget/row.rs | 17 ++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/column.rs b/web/src/widget/column.rs index 640d3673..6454ffba 100644 --- a/web/src/widget/column.rs +++ b/web/src/widget/column.rs @@ -130,11 +130,6 @@ impl<'a, Message> Widget for Column<'a, Message> { let padding_class = style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let width = css::length(self.width); - let height = css::length(self.height); - - let align_items = css::align(self.align_items); - // TODO: Complete styling div(bump) .attr( @@ -144,12 +139,12 @@ impl<'a, Message> Widget for Column<'a, Message> { ) .attr("style", bumpalo::format!( in bump, - "width: {}; height: {}; max-width: {}px; max-height: {}px; align-items: {}", - width, - height, - self.max_width, - self.max_height, - align_items + "width: {}; height: {}; max-width: {}; max-height: {}; align-items: {}", + css::length(self.width), + css::length(self.height), + css::max_length(self.max_width), + css::max_length(self.max_height), + css::align(self.align_items) ).into_bump_str() ) .children(children) diff --git a/web/src/widget/row.rs b/web/src/widget/row.rs index b360bc45..02035113 100644 --- a/web/src/widget/row.rs +++ b/web/src/widget/row.rs @@ -131,11 +131,6 @@ impl<'a, Message> Widget for Row<'a, Message> { let padding_class = style_sheet.insert(bump, css::Rule::Padding(self.padding)); - let width = css::length(self.width); - let height = css::length(self.height); - - let justify_content = css::align(self.align_items); - // TODO: Complete styling div(bump) .attr( @@ -145,12 +140,12 @@ impl<'a, Message> Widget for Row<'a, Message> { ) .attr("style", bumpalo::format!( in bump, - "width: {}; height: {}; max-width: {}px; max-height: {}px; justify-content: {}", - width, - height, - self.max_width, - self.max_height, - justify_content + "width: {}; height: {}; max-width: {}; max-height: {}; align-items: {}", + css::length(self.width), + css::length(self.height), + css::max_length(self.max_width), + css::max_length(self.max_height), + css::align(self.align_items) ).into_bump_str() ) .children(children) -- 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') 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 cf3ca442104994411529dfe21f7dced08f4ee1fb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 02:24:18 +0100 Subject: Implement `Container` styling in `iced_web` --- web/src/widget/container.rs | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/container.rs b/web/src/widget/container.rs index 767fed67..8e4318f9 100644 --- a/web/src/widget/container.rs +++ b/web/src/widget/container.rs @@ -14,7 +14,7 @@ pub struct Container<'a, Message> { max_height: u32, horizontal_alignment: Align, vertical_alignment: Align, - style: Box, + style_sheet: Box, content: Element<'a, Message>, } @@ -35,7 +35,7 @@ impl<'a, Message> Container<'a, Message> { max_height: u32::MAX, horizontal_alignment: Align::Start, vertical_alignment: Align::Start, - style: Default::default(), + style_sheet: Default::default(), content: content.into(), } } @@ -94,7 +94,7 @@ impl<'a, Message> Container<'a, Message> { /// /// [`Container`]: struct.Container.html pub fn style(mut self, style: impl Into>) -> Self { - self.style = style.into(); + self.style_sheet = style.into(); self } } @@ -113,11 +113,7 @@ where let column_class = style_sheet.insert(bump, css::Rule::Column); - let width = css::length(self.width); - let height = css::length(self.height); - - let align_items = css::align(self.horizontal_alignment); - let justify_content = css::align(self.vertical_alignment); + let style = self.style_sheet.style(); let node = div(bump) .attr( @@ -128,12 +124,17 @@ where "style", bumpalo::format!( in bump, - "width: {}; height: {}; max-width: {}px; align-items: {}; justify-content: {}", - width, - height, - self.max_width, - align_items, - justify_content + "width: {}; height: {}; max-width: {}; align-items: {}; justify-content: {}; background: {}; color: {}; border-width: {}px; border-color: {}; border-radius: {}px", + css::length(self.width), + css::length(self.height), + css::max_length(self.max_width), + css::align(self.horizontal_alignment), + css::align(self.vertical_alignment), + style.background.map(css::background).unwrap_or(String::from("initial")), + style.text_color.map(css::color).unwrap_or(String::from("inherit")), + style.border_width, + css::color(style.border_color), + style.border_radius ) .into_bump_str(), ) -- cgit From 07e62ae5dacdab6a9bb7d4c32844286764753acc Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 02:29:19 +0100 Subject: Fix `ProgressBar` doc example in `iced_web` --- web/src/widget/progress_bar.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/progress_bar.rs b/web/src/widget/progress_bar.rs index b1fcb4d8..856203c0 100644 --- a/web/src/widget/progress_bar.rs +++ b/web/src/widget/progress_bar.rs @@ -9,15 +9,14 @@ use std::ops::RangeInclusive; /// /// # Example /// ``` -/// # use iced_native::renderer::Null; -/// # -/// # pub type ProgressBar = iced_native::ProgressBar; +/// use iced_web::ProgressBar; +/// /// let value = 50.0; /// /// ProgressBar::new(0.0..=100.0, value); /// ``` /// -/// ![Progress bar drawn with `iced_wgpu`](https://user-images.githubusercontent.com/18618951/71662391-a316c200-2d51-11ea-9cef-52758cab85e3.png) +/// ![Progress bar](https://user-images.githubusercontent.com/18618951/71662391-a316c200-2d51-11ea-9cef-52758cab85e3.png) #[allow(missing_debug_implementations)] pub struct ProgressBar { range: RangeInclusive, -- 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') 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') 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 From f719ba3f4efebdf29cd5922d9e083f8dea96c486 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 6 Feb 2020 05:03:11 +0100 Subject: Add `font-family` to `Text` style in `iced_web` --- web/src/widget/text.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'web/src/widget') diff --git a/web/src/widget/text.rs b/web/src/widget/text.rs index 46230fef..3ec565a8 100644 --- a/web/src/widget/text.rs +++ b/web/src/widget/text.rs @@ -133,12 +133,16 @@ impl<'a, Message> Widget for Text { let style = bumpalo::format!( in bump, - "width: {}; height: {}; font-size: {}px; color: {}; text-align: {}", + "width: {}; height: {}; font-size: {}px; color: {}; text-align: {}; font-family: {}", width, height, self.size.unwrap_or(20), color, - text_align + text_align, + match self.font { + Font::Default => "inherit", + Font::External { name, .. } => name, + } ); // TODO: Complete styling -- cgit