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
12impl_scope! {
13    /// A separator
14    ///
15    /// This widget draws a bar when in a list.
16    #[autoimpl(Clone, Debug, Default)]
17    #[widget {
18        Data = A;
19    }]
20    pub struct Separator<A> {
21        core: widget_core!(),
22        _pd: PhantomData<A>,
23    }
24
25    impl Self {
26        /// Construct a frame, with void message type
27        #[inline]
28        pub fn new() -> Self {
29            Separator {
30                core: Default::default(),
31                _pd: PhantomData,
32            }
33        }
34    }
35
36    impl Layout for Self {
37        fn size_rules(&mut self, sizer: SizeCx, axis: AxisInfo) -> SizeRules {
38            sizer.feature(kas::theme::Feature::Separator, axis)
39        }
40
41        fn draw(&mut self, mut draw: DrawCx) {
42            draw.separator(self.rect());
43        }
44    }
45
46    /// A separator is a valid menu widget
47    impl Menu for Self {}
48}