From d0f79d2779d00752eef78cd98b6904cd888d59e3 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 23 Nov 2019 20:23:38 +0100 Subject: Make `tour` work with `iced_web` again :tada: - Implements `TextInput`, `Scrollable`, and `Container` - Adds basic style generation --- web/src/widget/text.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'web/src/widget/text.rs') diff --git a/web/src/widget/text.rs b/web/src/widget/text.rs index 1183a3cd..6194a12e 100644 --- a/web/src/widget/text.rs +++ b/web/src/widget/text.rs @@ -1,6 +1,6 @@ use crate::{ - Bus, Color, Element, Font, HorizontalAlignment, Length, VerticalAlignment, - Widget, + style, Bus, Color, Element, Font, HorizontalAlignment, Length, + VerticalAlignment, Widget, }; use dodrio::bumpalo; @@ -112,15 +112,30 @@ impl<'a, Message> Widget for Text { &self, bump: &'b bumpalo::Bump, _publish: &Bus, + _style_sheet: &mut style::Sheet<'b>, ) -> dodrio::Node<'b> { use dodrio::builder::*; let content = bumpalo::format!(in bump, "{}", self.content); - let size = bumpalo::format!(in bump, "font-size: {}px", self.size.unwrap_or(20)); + let color = style::color(self.color.unwrap_or(Color::BLACK)); + + let text_align = match self.horizontal_alignment { + HorizontalAlignment::Left => "left", + HorizontalAlignment::Center => "center", + HorizontalAlignment::Right => "right", + }; + + let style = bumpalo::format!( + in bump, + "font-size: {}px; color: {}; text-align: {}", + self.size.unwrap_or(20), + color, + text_align + ); // TODO: Complete styling p(bump) - .attr("style", size.into_bump_str()) + .attr("style", style.into_bump_str()) .children(vec![text(content.into_bump_str())]) .finish() } -- cgit