Skip to main content

floem/views/
empty.rs

1use crate::{view::View, view::ViewId};
2
3/// An empty View.
4///
5/// This view can still have a size, background, border radius, and outline.
6/// It can be used as a simple placeholder view when another view requires a child element but
7/// there is no meaningful child element to be provided.
8pub struct Empty {
9    pub(crate) id: ViewId,
10}
11
12impl Empty {
13    /// Creates a new empty view.
14    ///
15    /// ## Example
16    /// ```rust
17    /// use floem::views::Empty;
18    ///
19    /// let placeholder = Empty::new();
20    /// ```
21    pub fn new() -> Self {
22        Empty { id: ViewId::new() }
23    }
24
25    /// Creates a new empty view with a pre-existing [`ViewId`].
26    ///
27    /// This is useful for lazy view construction where the `ViewId` is created
28    /// before the view itself.
29    pub fn with_id(id: ViewId) -> Self {
30        Empty { id }
31    }
32}
33
34impl Default for Empty {
35    fn default() -> Self {
36        Self::new()
37    }
38}
39
40/// An empty View. This view can still have a size, background, border radius, and outline.
41///
42/// This view can be used as a simple placeholder view when another view requires a child element but
43/// there is no meaningful child element to be provided.
44#[deprecated(since = "0.2.0", note = "Use Empty::new() instead")]
45pub fn empty() -> Empty {
46    Empty::new()
47}
48
49impl View for Empty {
50    fn id(&self) -> ViewId {
51        self.id
52    }
53}