summaryrefslogtreecommitdiffstats
path: root/web/src/widget
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-31 11:37:41 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-12-31 11:37:41 +0100
commite98471d5b60d34e54defaba6e5979ff881e380e6 (patch)
tree428d923a092bc710697762e048d7a95505cc7085 /web/src/widget
parentfb9cc0262b30a953e8188897b74abb5106ea1fd8 (diff)
parent26de688e68347e1f6e388d01014eac89cea71afa (diff)
downloadiced-e98471d5b60d34e54defaba6e5979ff881e380e6.tar.gz
iced-e98471d5b60d34e54defaba6e5979ff881e380e6.tar.bz2
iced-e98471d5b60d34e54defaba6e5979ff881e380e6.zip
Merge branch 'master' into feature/custom-styling
Diffstat (limited to 'web/src/widget')
-rw-r--r--web/src/widget/image.rs2
-rw-r--r--web/src/widget/space.rs69
2 files changed, 70 insertions, 1 deletions
diff --git a/web/src/widget/image.rs b/web/src/widget/image.rs
index ed8b7ecf..413b663e 100644
--- a/web/src/widget/image.rs
+++ b/web/src/widget/image.rs
@@ -67,7 +67,7 @@ impl<Message> Widget<Message> for Image {
match self.width {
Length::Shrink => {}
- Length::Fill => {
+ Length::Fill | Length::FillPortion(_) => {
image = image.attr("width", "100%");
}
Length::Units(px) => {
diff --git a/web/src/widget/space.rs b/web/src/widget/space.rs
new file mode 100644
index 00000000..baf4c80b
--- /dev/null
+++ b/web/src/widget/space.rs
@@ -0,0 +1,69 @@
+use crate::{style, Bus, Element, Length, Widget};
+use dodrio::bumpalo;
+
+/// An amount of empty space.
+///
+/// It can be useful if you want to fill some space with nothing.
+#[derive(Debug)]
+pub struct Space {
+ width: Length,
+ height: Length,
+}
+
+impl Space {
+ /// Creates an amount of empty [`Space`] with the given width and height.
+ ///
+ /// [`Space`]: struct.Space.html
+ pub fn new(width: Length, height: Length) -> Self {
+ Space { width, height }
+ }
+
+ /// Creates an amount of horizontal [`Space`].
+ ///
+ /// [`Space`]: struct.Space.html
+ pub fn with_width(width: Length) -> Self {
+ Space {
+ width,
+ height: Length::Shrink,
+ }
+ }
+
+ /// Creates an amount of vertical [`Space`].
+ ///
+ /// [`Space`]: struct.Space.html
+ pub fn with_height(height: Length) -> Self {
+ Space {
+ width: Length::Shrink,
+ height,
+ }
+ }
+}
+
+impl<'a, Message> Widget<Message> for Space {
+ fn node<'b>(
+ &self,
+ bump: &'b bumpalo::Bump,
+ _publish: &Bus<Message>,
+ _style_sheet: &mut style::Sheet<'b>,
+ ) -> dodrio::Node<'b> {
+ use dodrio::builder::*;
+
+ let width = style::length(self.width);
+ let height = style::length(self.height);
+
+ let style = bumpalo::format!(
+ in bump,
+ "width: {}; height: {};",
+ width,
+ height
+ );
+
+ div(bump).attr("style", style.into_bump_str()).finish()
+ }
+}
+
+impl<'a, Message> From<Space> for Element<'a, Message> {
+ fn from(space: Space) -> Element<'a, Message> {
+ Element::new(space)
+ }
+}