1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
//     https://www.apache.org/licenses/LICENSE-2.0

//! Filler widget

use kas::prelude::*;

impl_scope! {
    /// A space filler
    ///
    /// This widget has zero minimum size but can expand according to the given
    /// stretch priority.
    #[derive(Clone, Debug, Default)]
    #[widget]
    pub struct Filler {
        core: widget_core!(),
        horiz: Stretch,
        vert: Stretch,
    }

    impl Layout for Filler {
        fn size_rules(&mut self, _: SizeMgr, axis: AxisInfo) -> SizeRules {
            let stretch = if axis.is_horizontal() { self.horiz } else { self.vert };
            SizeRules::empty(stretch)
        }

        fn draw(&mut self, _: DrawMgr) {}
    }
}

impl Filler {
    /// Construct a filler with priority [`Stretch::Filler`]
    pub fn new() -> Self {
        Filler::with(Stretch::Filler)
    }

    /// Construct a filler with priority [`Stretch::Low`]
    pub fn low() -> Self {
        Filler::with(Stretch::Low)
    }

    /// Construct a filler with priority [`Stretch::High`]
    pub fn high() -> Self {
        Filler::with(Stretch::High)
    }

    /// Construct a filler with priority [`Stretch::Maximize`]
    pub fn maximize() -> Self {
        Filler::with(Stretch::Maximize)
    }

    /// Construct with a custom stretch priority
    pub fn with(stretch: Stretch) -> Self {
        Filler::with_hv(stretch, stretch)
    }

    /// Construct with custom horizontal and vertical priorities
    pub fn with_hv(horiz: Stretch, vert: Stretch) -> Self {
        let core = Default::default();
        Filler { core, horiz, vert }
    }
}