Skip to main content

fret_core/
panels.rs

1use serde::{Deserialize, Serialize};
2
3/// Stable panel identity used for docking persistence and plugin registration.
4///
5/// This must remain stable across runs and should be namespaced (e.g. `core.scene`, `plugin.foo.panel`).
6#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
7pub struct PanelKind(pub String);
8
9impl PanelKind {
10    pub fn new(kind: impl Into<String>) -> Self {
11        Self(kind.into())
12    }
13}
14
15/// Stable identity for a specific dockable panel instance.
16///
17/// Most panels will be singletons and keep `instance = None`.
18#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
19pub struct PanelKey {
20    pub kind: PanelKind,
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub instance: Option<String>,
23}
24
25impl PanelKey {
26    pub fn new(kind: impl Into<String>) -> Self {
27        Self {
28            kind: PanelKind::new(kind),
29            instance: None,
30        }
31    }
32
33    pub fn with_instance(kind: impl Into<String>, instance: impl Into<String>) -> Self {
34        Self {
35            kind: PanelKind::new(kind),
36            instance: Some(instance.into()),
37        }
38    }
39}