2019-12-30 19:20:59 +01:00
|
|
|
//! Distribute content vertically.
|
2021-10-18 15:19:04 +07:00
|
|
|
use crate::layout;
|
|
|
|
|
use crate::renderer;
|
2022-07-27 06:49:20 +02:00
|
|
|
use crate::widget::Tree;
|
2022-02-22 14:10:49 +07:00
|
|
|
use crate::{Element, Layout, Length, Point, Rectangle, Size, Widget};
|
2019-12-30 19:20:59 +01:00
|
|
|
|
|
|
|
|
/// An amount of empty space.
|
|
|
|
|
///
|
|
|
|
|
/// It can be useful if you want to fill some space with nothing.
|
|
|
|
|
#[derive(Debug)]
|
2019-12-30 21:32:21 +01:00
|
|
|
pub struct Space {
|
2019-12-30 19:20:59 +01:00
|
|
|
width: Length,
|
|
|
|
|
height: Length,
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 21:32:21 +01:00
|
|
|
impl Space {
|
|
|
|
|
/// Creates an amount of empty [`Space`] with the given width and height.
|
|
|
|
|
pub fn new(width: Length, height: Length) -> Self {
|
|
|
|
|
Space { width, height }
|
2019-12-30 19:20:59 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-30 21:32:21 +01:00
|
|
|
/// Creates an amount of horizontal [`Space`].
|
|
|
|
|
pub fn with_width(width: Length) -> Self {
|
|
|
|
|
Space {
|
|
|
|
|
width,
|
|
|
|
|
height: Length::Shrink,
|
|
|
|
|
}
|
2019-12-30 19:20:59 +01:00
|
|
|
}
|
|
|
|
|
|
2019-12-30 21:32:21 +01:00
|
|
|
/// Creates an amount of vertical [`Space`].
|
|
|
|
|
pub fn with_height(height: Length) -> Self {
|
|
|
|
|
Space {
|
|
|
|
|
width: Length::Shrink,
|
|
|
|
|
height,
|
|
|
|
|
}
|
2019-12-30 19:20:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-10 02:01:30 +02:00
|
|
|
impl<Message, Renderer> Widget<Message, Renderer> for Space
|
2019-12-30 19:20:59 +01:00
|
|
|
where
|
2021-10-14 16:07:22 +07:00
|
|
|
Renderer: crate::Renderer,
|
2019-12-30 19:20:59 +01:00
|
|
|
{
|
|
|
|
|
fn width(&self) -> Length {
|
|
|
|
|
self.width
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn height(&self) -> Length {
|
|
|
|
|
self.height
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn layout(
|
|
|
|
|
&self,
|
|
|
|
|
_renderer: &Renderer,
|
|
|
|
|
limits: &layout::Limits,
|
|
|
|
|
) -> layout::Node {
|
|
|
|
|
let limits = limits.width(self.width).height(self.height);
|
|
|
|
|
|
|
|
|
|
layout::Node::new(limits.resolve(Size::ZERO))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn draw(
|
|
|
|
|
&self,
|
2022-07-27 06:49:20 +02:00
|
|
|
_state: &Tree,
|
2021-10-28 20:18:57 +07:00
|
|
|
_renderer: &mut Renderer,
|
2022-05-14 01:47:55 +02:00
|
|
|
_theme: &Renderer::Theme,
|
2021-10-28 20:18:57 +07:00
|
|
|
_style: &renderer::Style,
|
|
|
|
|
_layout: Layout<'_>,
|
2019-12-30 19:20:59 +01:00
|
|
|
_cursor_position: Point,
|
2020-08-18 03:37:32 +02:00
|
|
|
_viewport: &Rectangle,
|
2021-10-14 16:07:22 +07:00
|
|
|
) {
|
2019-12-30 19:20:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-30 21:32:21 +01:00
|
|
|
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
|
2019-12-30 19:20:59 +01:00
|
|
|
where
|
2021-10-14 16:07:22 +07:00
|
|
|
Renderer: crate::Renderer,
|
2020-03-30 06:30:22 +08:00
|
|
|
Message: 'a,
|
2019-12-30 19:20:59 +01:00
|
|
|
{
|
2019-12-30 21:32:21 +01:00
|
|
|
fn from(space: Space) -> Element<'a, Message, Renderer> {
|
|
|
|
|
Element::new(space)
|
2019-12-30 19:20:59 +01:00
|
|
|
}
|
|
|
|
|
}
|