kas_widgets/
separator.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//! A separator
7
8use crate::menu::Menu;
9use kas::prelude::*;
10use std::marker::PhantomData;
11
12#[impl_self]
13mod Separator {
14    /// A separator
15    ///
16    /// This widget draws a bar when in a list.
17    #[autoimpl(Clone, Debug, Default)]
18    #[widget]
19    pub struct Separator<A> {
20        core: widget_core!(),
21        _pd: PhantomData<A>,
22    }
23
24    impl Self {
25        /// Construct a frame, with void message type
26        #[inline]
27        pub fn new() -> Self {
28            Separator {
29                core: Default::default(),
30                _pd: PhantomData,
31            }
32        }
33    }
34
35    impl Layout for Self {
36        fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
37            sizer.feature(kas::theme::Feature::Separator, axis)
38        }
39
40        fn draw(&self, mut draw: DrawCx) {
41            draw.separator(self.rect());
42        }
43    }
44
45    impl Tile for Self {
46        fn role(&self, _: &mut dyn RoleCx) -> Role<'_> {
47            Role::Border
48        }
49    }
50
51    impl Events for Self {
52        type Data = A;
53    }
54
55    /// A separator is a valid menu widget
56    impl Menu for Self {}
57}