Skip to main content

kas_core/window/
mod.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//! Special window widgets
7
8mod popup;
9mod window;
10
11#[cfg(feature = "accesskit")]
12#[doc(inline)]
13pub(crate) use popup::POPUP_INNER_INDEX;
14#[doc(inline)] pub use popup::Popup;
15#[doc(inline)] pub(crate) use popup::PopupDescriptor;
16pub use window::*;
17pub use winit::icon;
18pub use winit::window::ResizeDirection;
19
20use std::num::NonZeroU32;
21
22/// Available decoration modes
23///
24/// See [`Window::decorations`].
25#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
26pub enum Decorations {
27    /// No decorations
28    ///
29    /// The root widget is drawn as a simple rectangle with no borders.
30    None,
31    /// Add a simple themed border to the widget
32    ///
33    /// Probably looks better if [`Window::transparent`] is true.
34    Border,
35    /// Toolkit-drawn decorations
36    ///
37    /// Decorations will match the toolkit theme, not the platform theme.
38    /// These decorations may not have all the same capabilities.
39    ///
40    /// Probably looks better if [`Window::transparent`] is true.
41    Toolkit,
42    /// Server-side decorations
43    ///
44    /// Decorations are drawn by the window manager, if available.
45    Server,
46}
47
48/// Identifier for a window or pop-up
49///
50/// Identifiers should always be unique.
51#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
52pub struct WindowId(NonZeroU32);
53
54impl WindowId {
55    pub(crate) fn get(self) -> u32 {
56        self.0.get()
57    }
58
59    pub(crate) fn try_from(index: u32) -> Option<Self> {
60        NonZeroU32::new(index).map(WindowId)
61    }
62}
63
64/// Constructor for [`WindowId`]
65#[derive(Default)]
66pub(crate) struct WindowIdFactory(u32);
67
68impl WindowIdFactory {
69    /// Get the next identifier
70    ///
71    /// TODO(opt): this should recycle used identifiers since Id does not
72    /// efficiently represent large numbers.
73    pub(crate) fn make_next(&mut self) -> WindowId {
74        let id = self.0 + 1;
75        self.0 = id;
76        WindowId(NonZeroU32::new(id).unwrap())
77    }
78}