summaryrefslogtreecommitdiffstats
path: root/web
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-06 01:21:53 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-06 01:21:53 +0100
commitfb8dc41f6dee6976395b03cc1fce3d21edb1038a (patch)
treed7fd69b21f9bdddd3f127a4c074b243d7e1a52d9 /web
parent58a7be0a31793400e5686f8e2af558f2307bebcd (diff)
downloadiced-fb8dc41f6dee6976395b03cc1fce3d21edb1038a.tar.gz
iced-fb8dc41f6dee6976395b03cc1fce3d21edb1038a.tar.bz2
iced-fb8dc41f6dee6976395b03cc1fce3d21edb1038a.zip
Add additional helpers to `css` module in `iced_web`
Diffstat (limited to 'web')
-rw-r--r--web/src/css.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/web/src/css.rs b/web/src/css.rs
index df0938da..6a307770 100644
--- a/web/src/css.rs
+++ b/web/src/css.rs
@@ -1,5 +1,5 @@
//! Style your widgets.
-use crate::{bumpalo, Align, Color, Length};
+use crate::{bumpalo, Align, Background, Color, Length};
use std::collections::BTreeMap;
@@ -119,7 +119,7 @@ impl<'a> Css<'a> {
declarations.push(text(
"body { height: 100%; margin: 0; padding: 0; font-family: sans-serif }",
));
- declarations.push(text("p { margin: 0 }"));
+ declarations.push(text("* { margin: 0; padding: 0 }"));
declarations.push(text(
"button { border: none; cursor: pointer; outline: none }",
));
@@ -143,6 +143,26 @@ pub fn length(length: Length) -> String {
}
}
+/// Returns the style value for the given maximum length in units.
+pub fn max_length(units: u32) -> String {
+ use std::u32;
+
+ if units == u32::MAX {
+ String::from("initial")
+ } else {
+ format!("{}px", units)
+ }
+}
+
+/// Returns the style value for the given minimum length in units.
+pub fn min_length(units: u32) -> String {
+ if units == 0 {
+ String::from("initial")
+ } else {
+ format!("{}px", units)
+ }
+}
+
/// Returns the style value for the given [`Color`].
///
/// [`Color`]: ../struct.Color.html
@@ -150,6 +170,15 @@ pub fn color(Color { r, g, b, a }: Color) -> String {
format!("rgba({}, {}, {}, {})", 255.0 * r, 255.0 * g, 255.0 * b, a)
}
+/// Returns the style value for the given [`Background`].
+///
+/// [`Background`]: ../struct.Background.html
+pub fn background(background: Background) -> String {
+ match background {
+ Background::Color(c) => color(c),
+ }
+}
+
/// Returns the style value for the given [`Align`].
///
/// [`Align`]: ../enum.Align.html