summaryrefslogtreecommitdiffstats
path: root/web/src/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-05 01:04:46 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-05 01:04:46 +0100
commit28fd9feb40a024ea29f73fa91c21fc3f2cf01d58 (patch)
treee1df3d67f8e293b15940c447acb37a3ed0155b36 /web/src/widget
parent0030bcbd33f5c4db60aac826552042e46b51c691 (diff)
downloadiced-28fd9feb40a024ea29f73fa91c21fc3f2cf01d58.tar.gz
iced-28fd9feb40a024ea29f73fa91c21fc3f2cf01d58.tar.bz2
iced-28fd9feb40a024ea29f73fa91c21fc3f2cf01d58.zip
Support styling for `Button` in `iced_web`
Diffstat (limited to 'web/src/widget')
-rw-r--r--web/src/widget/button.rs57
-rw-r--r--web/src/widget/column.rs2
-rw-r--r--web/src/widget/row.rs2
-rw-r--r--web/src/widget/text.rs5
4 files changed, 42 insertions, 24 deletions
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<Message>,
width: Length,
+ height: Length,
min_width: u32,
+ min_height: u32,
padding: u16,
- background: Option<Background>,
- border_radius: u16,
+ style: Box<dyn StyleSheet>,
}
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<T: Into<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<Box<dyn StyleSheet>>) -> 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<Message> 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);