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