aetna_core/tree/semantics.rs
1//! Semantic node and paint roles carried by [`El`](crate::El).
2
3use std::panic::Location;
4
5/// Semantic identity of an element. Roughly an HTML tag.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub enum Kind {
8 /// A bare layout container with no inherent visuals.
9 Group,
10 Card,
11 Button,
12 Badge,
13 Text,
14 Heading,
15 Spacer,
16 Divider,
17 Overlay,
18 Scrim,
19 Modal,
20 /// A vertically scrollable region.
21 Scroll,
22 /// Vertically scrollable region whose children are produced lazily.
23 VirtualList,
24 /// Block whose direct children flow inline.
25 Inlines,
26 /// Forced line break inside a `Kind::Inlines` block.
27 HardBreak,
28 /// Raster image element.
29 Image,
30 /// App-owned GPU texture composited into the paint stream. Backed
31 /// by [`crate::surface::AppTexture`] and the [`crate::tree::surface`]
32 /// builder; the backend samples the texture during paint instead
33 /// of uploading pixels.
34 ///
35 /// The texture stretches across the resolved rect with bilinear
36 /// filtering — source pixel dimensions and rendered size are
37 /// independent. See [`crate::tree::surface`] for the full sizing /
38 /// aspect-ratio contract.
39 Surface,
40 /// App-supplied vector asset. Backed by
41 /// [`crate::vector::VectorAsset`] and the [`crate::tree::vector`]
42 /// builder; callers explicitly choose painted vector rendering or
43 /// one-colour mask rendering. Unlike [`Kind::Image`] (icon-styled,
44 /// square-shaped), this is the general-purpose path for arbitrary-
45 /// aspect vector content — commit-graph curves, Gantt connectors,
46 /// custom chart marks.
47 Vector,
48 /// Escape hatch for app-defined components.
49 Custom(&'static str),
50}
51
52/// Semantic paint role for rect-shaped surfaces.
53///
54/// Each variant maps to a theme-applied recipe at paint time. Roles are
55/// either *decorative* (set stroke + shadow on top of whatever fill the
56/// node already carries) or *fill-providing* (default a fill from the
57/// palette when the node has none). The split matters: setting a
58/// decorative role on a node with no fill produces an "invisible
59/// surface" — only a thin border over the parent's background. For
60/// panel-shaped containers, prefer the dedicated widget (`card()`,
61/// `sidebar()`, `dialog()`, `popover()`) which bundles role + fill +
62/// stroke + radius + shadow correctly.
63#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
64pub enum SurfaceRole {
65 /// No special semantic role. Theme fallback applies.
66 #[default]
67 None,
68 /// **Decorative.** Border + small drop shadow. *Does not paint a
69 /// fill* — the node must supply one (e.g. `tokens::CARD`) or sit
70 /// inside a widget like `card()` / `sidebar()` that does.
71 Panel,
72 /// **Decorative.** Border + half-strength shadow, suggesting one
73 /// elevation step above its parent. Like `Panel`, no fill.
74 Raised,
75 /// **Fill-providing.** Slightly darker variant of `MUTED` (palette
76 /// `darken(0.08)`) with input-toned border. Use for inset bands —
77 /// search wells, segmented-control tracks, recessed list headers.
78 Sunken,
79 /// **Decorative.** Input-toned border + large drop shadow for
80 /// floating panels. Used by `popover()` and friends; bring your
81 /// own fill (typically `tokens::POPOVER`).
82 Popover,
83 /// **Fill-providing.** PRIMARY-tinted alpha 28 fill +
84 /// PRIMARY-tinted alpha 110 border. The selected item inside a
85 /// collection. Prefer the `.selected()` chainable, which sets this
86 /// role plus content color in one call.
87 Selected,
88 /// **Fill-providing.** Solid `ACCENT` fill + neutral border for
89 /// the current page / nav item. Prefer the `.current()` chainable,
90 /// which also bumps font weight and content color.
91 Current,
92 /// **Fill-providing.** Same recipe as `Sunken` — used by text
93 /// inputs and other editable surfaces.
94 Input,
95 /// **Decorative.** Destructive-toned border, no shadow. Pair with
96 /// a tint fill (e.g. `tokens::DESTRUCTIVE.with_alpha(40)`) for the
97 /// classic "danger" band in a form or section header.
98 Danger,
99}
100
101impl SurfaceRole {
102 pub fn name(self) -> &'static str {
103 match self {
104 SurfaceRole::None => "none",
105 SurfaceRole::Panel => "panel",
106 SurfaceRole::Raised => "raised",
107 SurfaceRole::Sunken => "sunken",
108 SurfaceRole::Popover => "popover",
109 SurfaceRole::Selected => "selected",
110 SurfaceRole::Current => "current",
111 SurfaceRole::Input => "input",
112 SurfaceRole::Danger => "danger",
113 }
114 }
115
116 pub fn uniform_id(self) -> f32 {
117 match self {
118 SurfaceRole::None => 0.0,
119 SurfaceRole::Panel => 1.0,
120 SurfaceRole::Raised => 2.0,
121 SurfaceRole::Sunken => 3.0,
122 SurfaceRole::Popover => 4.0,
123 SurfaceRole::Selected => 5.0,
124 SurfaceRole::Current => 6.0,
125 SurfaceRole::Input => 7.0,
126 SurfaceRole::Danger => 8.0,
127 }
128 }
129}
130
131/// Interaction state, applied as a render-time visual delta.
132#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
133#[non_exhaustive]
134pub enum InteractionState {
135 #[default]
136 Default,
137 Hover,
138 Press,
139 Focus,
140 Disabled,
141 Loading,
142}
143
144/// Recorded source location for an element. Set automatically via
145/// `#[track_caller]` on every constructor.
146///
147/// `from_library` distinguishes Els constructed inside aetna's own
148/// widget closures (where the closure boundary defeats
149/// `#[track_caller]` and the recorded location lands inside aetna-core
150/// instead of at the user's call site) from Els constructed in user
151/// code. The lint pass uses this to gate user-facing findings and to
152/// walk blame attribution upward to the nearest user-source ancestor.
153/// Set explicitly via [`crate::tree::El::from_library`] at the few
154/// closure-builder sites that need it.
155#[derive(Clone, Copy, Debug, Default)]
156#[non_exhaustive]
157pub struct Source {
158 pub file: &'static str,
159 pub line: u32,
160 pub from_library: bool,
161}
162
163impl Source {
164 pub fn from_caller(loc: &'static Location<'static>) -> Self {
165 Self {
166 file: loc.file(),
167 line: loc.line(),
168 from_library: false,
169 }
170 }
171}