kas_widgets/
filler.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License in the LICENSE-APACHE file or at:
4//     https://www.apache.org/licenses/LICENSE-2.0
5
6//! Filler widget
7
8use kas::prelude::*;
9
10#[impl_self]
11mod Filler {
12    /// A space filler
13    ///
14    /// This widget has zero minimum size but can expand according to the given
15    /// stretch priority.
16    #[derive(Clone, Debug, Default)]
17    #[widget]
18    pub struct Filler {
19        core: widget_core!(),
20        horiz: Stretch,
21        vert: Stretch,
22    }
23
24    impl Layout for Filler {
25        fn size_rules(&mut self, _: SizeCx, axis: AxisInfo) -> SizeRules {
26            let stretch = if axis.is_horizontal() { self.horiz } else { self.vert };
27            SizeRules::empty(stretch)
28        }
29
30        fn draw(&self, _: DrawCx) {}
31    }
32
33    impl Tile for Self {
34        fn role(&self, _: &mut dyn RoleCx) -> Role<'_> {
35            Role::None
36        }
37    }
38}
39
40impl Filler {
41    /// Construct a filler with priority [`Stretch::Filler`]
42    pub fn new() -> Self {
43        Filler::with(Stretch::Filler)
44    }
45
46    /// Construct a filler with priority [`Stretch::Low`]
47    pub fn low() -> Self {
48        Filler::with(Stretch::Low)
49    }
50
51    /// Construct a filler with priority [`Stretch::High`]
52    pub fn high() -> Self {
53        Filler::with(Stretch::High)
54    }
55
56    /// Construct a filler with priority [`Stretch::Maximize`]
57    pub fn maximize() -> Self {
58        Filler::with(Stretch::Maximize)
59    }
60
61    /// Construct with a custom stretch priority
62    pub fn with(stretch: Stretch) -> Self {
63        Filler::with_hv(stretch, stretch)
64    }
65
66    /// Construct with custom horizontal and vertical priorities
67    pub fn with_hv(horiz: Stretch, vert: Stretch) -> Self {
68        let core = Default::default();
69        Filler { core, horiz, vert }
70    }
71}