Add additional helpers to css module in iced_web
This commit is contained in:
parent
58a7be0a31
commit
fb8dc41f6d
1 changed files with 31 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
//! Style your widgets.
|
//! Style your widgets.
|
||||||
use crate::{bumpalo, Align, Color, Length};
|
use crate::{bumpalo, Align, Background, Color, Length};
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
||||||
|
|
@ -119,7 +119,7 @@ impl<'a> Css<'a> {
|
||||||
declarations.push(text(
|
declarations.push(text(
|
||||||
"body { height: 100%; margin: 0; padding: 0; font-family: sans-serif }",
|
"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(
|
declarations.push(text(
|
||||||
"button { border: none; cursor: pointer; outline: none }",
|
"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`].
|
/// Returns the style value for the given [`Color`].
|
||||||
///
|
///
|
||||||
/// [`Color`]: ../struct.Color.html
|
/// [`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)
|
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`].
|
/// Returns the style value for the given [`Align`].
|
||||||
///
|
///
|
||||||
/// [`Align`]: ../enum.Align.html
|
/// [`Align`]: ../enum.Align.html
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue