1use crate::{UiId, UiLayer, UiRect};
7
8crate::set! {
9 #[doc = crate::_tags!(ui set)]
10 #[doc = crate::_doc_meta! {
12 location("ui/view", struct UiViewFlags),
13 test_size_of(UiViewFlags = 1|8; niche !Option),
14 }]
15 #[must_use]
16 #[repr(transparent)]
17 pub struct UiViewFlags(u8) {
18 HIDDEN = 0;
20
21 CLIPPED = 1;
23
24 OPAQUE = 2;
26 }
27}
28
29#[doc = crate::_tags!(ui)]
30#[doc = crate::_doc_meta! {
32 location("ui/view", struct UiView),
33 #[cfg(target_pointer_width = "32")]
34 test_size_of(UiView = 28|224; niche Option),
35 #[cfg(target_pointer_width = "64")]
36 test_size_of(UiView = 32|256; niche Option),
37}]
38#[must_use]
41#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
42pub struct UiView {
43 id: UiId,
44 rect: UiRect,
45 layer: UiLayer,
46 flags: UiViewFlags,
47}
48#[rustfmt::skip]
49impl UiView {
50 pub const fn new(id: UiId, rect: UiRect) -> Self {
54 Self { id, rect, layer: UiLayer::BASE, flags: UiViewFlags::new() }
55 }
56
57 pub const fn from_parts(id: UiId, rect: UiRect, layer: UiLayer, flags: UiViewFlags)
59 -> Self { Self { id, rect, layer, flags } }
60
61 pub const fn id(&self) -> UiId { self.id }
65
66 pub const fn rect(&self) -> UiRect { self.rect }
68
69 pub const fn layer(&self) -> UiLayer { self.layer }
71
72 pub const fn flags(&self) -> UiViewFlags { self.flags }
74
75 #[must_use]
77 pub const fn is_hidden(&self) -> bool { self.flags.has(UiViewFlags::HIDDEN) }
78 #[must_use]
80 pub const fn is_visible(&self) -> bool { !self.is_hidden() }
81
82 pub const fn with_rect(self, rect: UiRect) -> Self { Self { rect, ..self } }
86 pub const fn with_layer(self, layer: UiLayer) -> Self { Self { layer, ..self } }
88
89
90 pub const fn replace_flags(self, flags: UiViewFlags) -> Self { Self { flags, ..self } }
92 pub const fn with_flags(self, flags: UiViewFlags) -> Self {
94 Self { flags: self.flags.with(flags), ..self }
95 }
96 pub const fn without_flags(self, flags: UiViewFlags) -> Self {
98 Self { flags: self.flags.without(flags), ..self }
99 }
100}