1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
//! Descriptions module.
//!
//! This public module implements the Liora description-list component for structured key/value details. It keeps the reusable
//! component logic inside `liora-components` rather than Gallery or Docs so
//! downstream GPUI applications can compose the same behavior with their own
//! app state, assets, and release policy.
//!
//! ## Usage model
//!
//! Components in this module render native GPUI element trees. Stateless builder
//! values can be constructed inline, while controls with focus, selection,
//! popup, drag, or editing state should be stored as `gpui::Entity<T>` fields in
//! the parent view so state survives GPUI render passes.
//!
//! ## Design contract
//!
//! The implementation should use Liora theme tokens from `liora-core` and
//! `liora-theme`, keep accessibility-oriented keyboard/pointer behavior close to
//! the component, and avoid app-specific Gallery/Docs resources in this SDK
//! crate.
use gpui::{AnyElement, App, IntoElement, RenderOnce, SharedString, Window, div, prelude::*, px};
use liora_core::Config;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
/// Options that control descriptions direction behavior.
pub enum DescriptionsDirection {
#[default]
/// Lays out content in the horizontal direction.
Horizontal,
/// Lays out content in the vertical direction.
Vertical,
}
/// Data model used by description item rendering.
pub struct DescriptionItem {
/// User-facing label rendered for this item.
pub label: SharedString,
/// Machine-readable value represented by this item.
pub value: AnyElement,
/// Number of columns occupied by this descriptions item.
pub span: u32,
}
/// Fluent native GPUI component for rendering Liora descriptions.
pub struct Descriptions {
title: Option<SharedString>,
extra: Option<AnyElement>,
column: u32,
direction: DescriptionsDirection,
border: bool,
items: Vec<DescriptionItem>,
}
impl Descriptions {
/// Creates `Descriptions` with default theme-driven styling and no optional callbacks attached.
pub fn new() -> Self {
Self {
title: None,
extra: None,
column: 3,
direction: DescriptionsDirection::Horizontal,
border: false,
items: vec![],
}
}
/// Sets the primary title text displayed by the component.
pub fn title(mut self, title: impl Into<SharedString>) -> Self {
self.title = Some(title.into());
self
}
/// Sets the extra value used by the component.
pub fn extra(mut self, extra: impl IntoElement) -> Self {
self.extra = Some(extra.into_any_element());
self
}
/// Sets the column value used by the component.
pub fn column(mut self, c: u32) -> Self {
self.column = c.max(1);
self
}
/// Selects the layout or animation direction.
pub fn direction(mut self, d: DescriptionsDirection) -> Self {
self.direction = d;
self
}
/// Toggles or applies the component border treatment.
pub fn border(mut self, b: bool) -> Self {
self.border = b;
self
}
/// Performs the item operation used by this component.
pub fn item(
mut self,
label: impl Into<SharedString>,
value: impl IntoElement,
span: u32,
) -> Self {
self.items.push(DescriptionItem {
label: label.into(),
value: value.into_any_element(),
span: span.max(1),
});
self
}
}
impl RenderOnce for Descriptions {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let theme = cx.global::<Config>().theme.clone();
let column = self.column;
let border = self.border;
let direction = self.direction;
// Group items into rows
let mut rows: Vec<Vec<DescriptionItem>> = vec![];
let mut current_row: Vec<DescriptionItem> = vec![];
let mut current_span = 0;
for item in self.items {
let item_span = item.span.min(column);
if current_span + item_span > column {
if let Some(last) = current_row.last_mut() {
last.span += column - current_span;
}
rows.push(current_row);
current_row = vec![];
current_span = 0;
}
current_span += item_span;
current_row.push(item);
}
if !current_row.is_empty() {
if let Some(last) = current_row.last_mut() {
last.span += column - current_span;
}
rows.push(current_row);
}
div()
.flex()
.flex_col()
.w_full()
.gap_4()
.when(self.title.is_some() || self.extra.is_some(), |s| {
s.child(
div()
.flex()
.flex_row()
.items_center()
.justify_between()
.when_some(self.title, |s, t| {
s.child(
div()
.text_lg()
.font_weight(gpui::FontWeight::BOLD)
.text_color(theme.neutral.text_1)
.child(t),
)
})
.when_some(self.extra, |s, e| s.child(e)),
)
})
.child(
div()
.flex()
.flex_col()
.when(border, |s| {
s.border_1()
.border_color(theme.neutral.border)
.rounded(px(theme.radius.sm))
.overflow_hidden()
})
.children(rows.into_iter().enumerate().map(|(row_idx, row)| {
div()
.flex()
.flex_row()
.w_full()
.when(border && row_idx > 0, |s| {
s.border_t_1().border_color(theme.neutral.border)
})
.children(row.into_iter().enumerate().map(|(col_idx, item)| {
let width = gpui::relative(item.span as f32 / column as f32);
let cell = div().w(width).flex().when(border && col_idx > 0, |s| {
s.border_l_1().border_color(theme.neutral.border)
});
match direction {
DescriptionsDirection::Horizontal => {
if border {
cell.flex_row()
.items_start()
.child(
div()
.p_3()
.bg(theme.neutral.hover)
.border_r_1()
.border_color(theme.neutral.border)
.flex()
.items_center()
.child(
div()
.text_sm()
.font_weight(gpui::FontWeight::BOLD)
.text_color(theme.neutral.text_2)
.child(item.label),
),
)
.child(
div()
.flex_1()
.p_3()
.flex()
.items_center()
.child(
div()
.text_sm()
.text_color(theme.neutral.text_1)
.child(item.value),
),
)
} else {
cell.flex_row()
.items_center()
.gap_2()
.p_1()
.child(
div()
.text_sm()
.text_color(theme.neutral.text_3)
.child(format!("{}:", item.label)),
)
.child(
div()
.text_sm()
.text_color(theme.neutral.text_1)
.child(item.value),
)
}
}
DescriptionsDirection::Vertical => {
if border {
cell.flex_col()
.child(
div()
.p_3()
.bg(theme.neutral.hover)
.border_b_1()
.border_color(theme.neutral.border)
.child(
div()
.text_sm()
.font_weight(gpui::FontWeight::BOLD)
.text_color(theme.neutral.text_2)
.child(item.label),
),
)
.child(
div().p_3().child(
div()
.text_sm()
.text_color(theme.neutral.text_1)
.child(item.value),
),
)
} else {
cell.flex_col()
.gap_1()
.p_1()
.child(
div()
.text_xs()
.text_color(theme.neutral.text_3)
.child(item.label),
)
.child(
div()
.text_sm()
.text_color(theme.neutral.text_1)
.child(item.value),
)
}
}
}
}))
})),
)
}
}
impl IntoElement for Descriptions {
type Element = gpui::Component<Self>;
fn into_element(self) -> Self::Element {
gpui::Component::new(self)
}
}