plugin_interfaces/pluginui/
components.rs

1//! UI component definitions for the new framework
2
3use serde::{Deserialize, Serialize};
4
5/// Response from UI interactions
6pub struct Response {
7    pub clicked: bool,
8    pub changed: bool,
9    pub hovered: bool,
10    /// Component ID for event handling
11    pub component_id: Option<String>,
12}
13
14impl Response {
15    pub fn new() -> Self {
16        Self {
17            clicked: false,
18            changed: false,
19            hovered: false,
20            component_id: None,
21        }
22    }
23
24    pub fn new_with_component_and_state(
25        component_id: String,
26        clicked: bool,
27        changed: bool,
28    ) -> Self {
29        Self {
30            clicked,
31            changed,
32            hovered: false,
33            component_id: Some(component_id),
34        }
35    }
36
37    pub fn clicked(&self) -> bool {
38        self.clicked
39    }
40
41    pub fn changed(&self) -> bool {
42        self.changed
43    }
44
45    pub fn hovered(&self) -> bool {
46        self.hovered
47    }
48
49    pub fn with_clicked() -> Self {
50        Self {
51            clicked: true,
52            changed: false,
53            hovered: false,
54            component_id: None,
55        }
56    }
57
58    pub fn with_changed() -> Self {
59        Self {
60            clicked: false,
61            changed: true,
62            hovered: false,
63            component_id: None,
64        }
65    }
66}
67
68/// Internal component representation for serialization
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct UiComponent {
71    pub id: String,
72    pub component: UiComponentType,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(tag = "type")]
77pub enum UiComponentType {
78    Label {
79        text: String,
80    },
81    Button {
82        text: String,
83        enabled: bool,
84    },
85    TextEdit {
86        value: String,
87        hint: String,
88    },
89    SelectableValue {
90        options: Vec<String>,
91        selected: usize,
92    },
93    ComboBox {
94        options: Vec<String>,
95        selected: Option<usize>,
96        placeholder: String,
97    },
98    Toggle {
99        value: bool,
100    },
101    Horizontal {
102        children: Vec<UiComponent>,
103    },
104    Vertical {
105        children: Vec<UiComponent>,
106    },
107}