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
59/// Constructor for [`WindowId`]
60#[derive(Default)]
61pub(crate) struct WindowIdFactory(u32);
62
63impl WindowIdFactory {
64 /// Get the next identifier
65 ///
66 /// TODO(opt): this should recycle used identifiers since Id does not
67 /// efficiently represent large numbers.
68 pub(crate) fn make_next(&mut self) -> WindowId {
69 let id = self.0 + 1;
70 self.0 = id;
71 WindowId(NonZeroU32::new(id).unwrap())
72 }
73}