Skip to main content

fret_core/
ids.rs

1use serde::{Deserialize, Serialize};
2use slotmap::new_key_type;
3
4new_key_type! {
5    pub struct AppWindowId;
6    pub struct NodeId;
7    pub struct DockNodeId;
8    pub struct ImageId;
9    pub struct SvgId;
10    pub struct TextBlobId;
11    pub struct PathId;
12    pub struct RenderTargetId;
13    pub struct MaterialId;
14    pub struct EffectId;
15}
16
17/// Window-scoped view identifier used for "dirty view" tracking (GPUI-aligned).
18///
19/// v1: a view is defined at cache boundary granularity (a `ViewCache` root), so `ViewId` wraps the
20/// runtime `NodeId` for that cache root.
21#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
22pub struct ViewId(pub NodeId);
23
24impl From<NodeId> for ViewId {
25    fn from(value: NodeId) -> Self {
26        Self(value)
27    }
28}
29
30impl From<ViewId> for NodeId {
31    fn from(value: ViewId) -> Self {
32        value.0
33    }
34}
35
36/// Stable, portable font identifier used by the UI/runtime.
37///
38/// This is intentionally a semantic identifier (not a font database index) so that it remains
39/// stable across runs and portable to wasm/sandboxed environments.
40#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
41#[serde(rename_all = "snake_case")]
42pub enum FontId {
43    /// Built-in "system UI" font alias (implementation-defined).
44    #[default]
45    Ui,
46    /// Built-in serif font alias (implementation-defined).
47    Serif,
48    /// Built-in monospace font alias (implementation-defined).
49    Monospace,
50    /// A named font family resolved by the backend (best-effort).
51    Family(String),
52}
53
54impl FontId {
55    pub fn ui() -> Self {
56        Self::Ui
57    }
58
59    pub fn serif() -> Self {
60        Self::Serif
61    }
62
63    pub fn monospace() -> Self {
64        Self::Monospace
65    }
66
67    pub fn family(name: impl Into<String>) -> Self {
68        Self::Family(name.into())
69    }
70}
71
72#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
73pub struct FrameId(pub u64);
74
75#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
76pub struct TimerToken(pub u64);
77
78#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
79pub struct ExternalDropToken(pub u64);
80
81#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
82pub struct FileDialogToken(pub u64);
83
84#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
85pub struct ClipboardToken(pub u64);
86
87#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
88pub struct ShareSheetToken(pub u64);
89
90#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
91pub struct IncomingOpenToken(pub u64);
92
93#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
94pub struct ImageUploadToken(pub u64);
95
96#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
97pub struct ImageUpdateToken(pub u64);
98
99/// Stable pointer/contact identifier used for multi-pointer input routing.
100///
101/// `PointerId(0)` is reserved for the mouse pointer.
102#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
103pub struct PointerId(pub u64);