forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

common.rs386 lines, 14.7 KiBHistoryRawDownload
1//! The row atoms and helpers every property card shares: what a row's label,
2//! value and step glyph paint in the darkroom (DESIGN §3/§4), and the card head.
3
4use crate::layout::redesign as r;
5use crate::ui::hitmap;
6use crate::ui::icons::{Icon, IconSize};
7use crate::ui::kit::{Button, ButtonSize, ButtonStyle};
8use crate::ui::theme::tokens;
9use crate::ui::type_scale::{self, Typeset};
10use crate::ui::widgets::*;
11use crate::*;
12
13/// DESIGN §3/§4 atoms shared by every param/setting card below (colour,
14/// transform, speed, EQ, silence, mix, subtitle style): what a row's label
15/// and value paint in the darkroom, so the seven card bodies each pick
16/// tokens rather than reimplement the same font/colour swap seven times.
17///
18/// A row label is what the room says about the control -- Archivo, §3's
19/// label-row size, `ink2` at rest / `ink1` picked (no permanent pill: the
20/// picked state is a 1px `ink1` rule, §4's focus ring, not a fill).
21pub(super) fn dark_row_label(text: impl Into<SharedString>, picked: bool) -> Div {
22 div()
23 .type_style(type_scale::body())
24 .text_color(rgb(if picked { tokens().ink1 } else { tokens().ink2 }))
25 .child(text.into())
26}
27
28/// A transform row's value with its unit: degrees for rotation, `×` for
29/// scale (a multiplier, not a fraction of the frame), percent for
30/// position/crop (both are a fraction of the frame's own size) -- the bare
31/// `{value:.2}` this used to print could not tell a percent from a
32/// multiplier apart.
33pub(super) fn transform_row_value(band: usize, value: f32) -> String {
34 if band == ROTATE_BAND {
35 format!("{value:.0}°")
36 } else if band == SCALE_BAND {
37 format!("{value:.2}×")
38 } else {
39 format!("{:.0}%", value * 100.)
40 }
41}
42
43/// A row's value -- what the film/the setting *says*, mono per §3. Ink1 once
44/// it is changed from its default, ink3 while it sits there (DESIGN §9.1).
45pub(super) fn dark_row_value(text: impl Into<SharedString>, changed: bool) -> Div {
46 div()
47 .type_style(type_scale::caption())
48 .text_color(rgb(if changed { tokens().ink1 } else { tokens().ink2 }))
49 .child(text.into())
50}
51
52
53/// A card's own head line: the verb in Archivo (§3 section-head casing) and,
54/// where there is one, the clip it names in mono beside it -- "which clip"
55/// is metadata about the footage, not the room's own voice. `help`, when
56/// given, is the card's own how-to sentence -- it used to sit under the
57/// head as a permanent line (a terminal-screen row of prose the user named
58/// directly); now it rides a `?` glyph beside the head and only shows on
59/// hover, the same hover-only convention [`dock_stance::ghost_verb`]
60/// already uses for a verb's own description.
61/// `maximize` is `None` for the one card this head builds that is not one of
62/// the seven param cards (the export progress sheet): everything else passes
63/// `Some(self.card_maximized)` and gets the affordance this session's
64/// complaint asked for -- worn on the head (DESIGN.md:91's "chord is worn"),
65/// so it never was a keyboard-only option (the repeated "some options are
66/// only reachable via keyboard shortcut" complaint). A double-click anywhere
67/// on the head does the same thing the glyph's click and the `m` chord do
68/// ([`Player::toggle_maximize`]) -- mouse and key reach the same switch.
69// `+ use<>` (edition 2024 precise capturing): without it, the elided
70// lifetime on `cx` would be captured into the returned opaque type by
71// default, so a hoisted `let head = true.then(|| dark_card_head(..., cx));`
72// would keep `cx` borrowed until `head` is finally consumed -- fighting
73// every other `cx.listener(...)` call built in between, which is exactly
74// the E0500/E0501 chain this card's own hoist is here to avoid.
75pub(super) fn dark_card_head(
76 verb: &str,
77 meta: Option<SharedString>,
78 help: Option<SharedString>,
79 maximize: Option<bool>,
80 cx: &mut Context<Player>,
81) -> impl IntoElement + use<> {
82 dark_card_head_reset(verb, meta, help, maximize, None, cx)
83}
84
85/// [`dark_card_head`] with the `Reset all` slot (DESIGN §9.1): the button shows
86/// only when the card hands it a `reset`, and presses it through the card.
87pub(super) fn dark_card_head_reset(
88 _verb: &str,
89 _meta: Option<SharedString>,
90 help: Option<SharedString>,
91 _maximize: Option<bool>,
92 reset: Option<fn(&mut Player, &mut Context<Player>)>,
93 cx: &mut Context<Player>,
94) -> impl IntoElement + use<> {
95 // REDESIGN §3.9: the card lives under its own section head in the Clip
96 // inspector, so the verb, the clip name, the back arrow and the close
97 // cross are gone (the section head names it, and clicking the head folds
98 // it). What stays is what only the card knows: its how-to sentence behind
99 // a `circle-help` icon and the `Reset all` ghost button.
100 let t = tokens();
101 let any = help.is_some() || reset.is_some();
102 div()
103 .id("card-head")
104 .flex_none()
105 .when(any, |d| d.h(px(r::CONTROL_S)))
106 .flex()
107 .items_center()
108 .gap(px(CARD_GAP))
109 .child(div().flex_1())
110 .children(help.map(|h| {
111 div()
112 .id("card-head-help")
113 .flex_none()
114 .size(px(r::CONTROL_S))
115 .flex()
116 .items_center()
117 .justify_center()
118 .tooltip(move |_, cx| cx.new(|_| OverlayTip(h.clone())).into())
119 .child(Icon::CircleHelp.el(IconSize::Inline, t.ink3))
120 }))
121 .children(reset.map(|reset| {
122 Button::new("card-head-reset-all")
123 .label("Reset all")
124 .icon(Icon::RotateCcw)
125 .style(ButtonStyle::Ghost)
126 .size(ButtonSize::Small)
127 .build()
128 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
129 reset(this, cx);
130 cx.notify();
131 }))
132 }))
133}
134
135/// A card's section header row: the section's `title` on the left (`section`
136/// type, `ink2`), and on the right the `?` help (its sentence on hover) and
137/// the `Reset all` ghost button. Each of the two is drawn only when given, and
138/// the row is drawn only when there is something to put in it, so a card never
139/// shows an empty bar with a lone `?`. `reset` is pressed through the card.
140#[allow(dead_code, reason = "the cards adopt it next")]
141pub(super) fn section_header_row(
142 title: &str,
143 help: Option<SharedString>,
144 reset: Option<fn(&mut Player, &mut Context<Player>)>,
145 cx: &mut Context<Player>,
146) -> impl IntoElement + use<> {
147 let t = tokens();
148 let title: SharedString = title.to_string().into();
149 div()
150 .id("card-section-header")
151 .flex_none()
152 .w_full()
153 .h(px(r::CONTROL_S))
154 .flex()
155 .items_center()
156 .gap(px(4.))
157 .child(
158 div()
159 .flex_1()
160 .min_w(px(0.))
161 .truncate()
162 .type_style(type_scale::section())
163 .text_color(rgb(t.ink2))
164 .child(title),
165 )
166 .children(help.map(|h| {
167 div()
168 .id("card-section-help")
169 .flex_none()
170 .size(px(r::CONTROL_S))
171 .flex()
172 .items_center()
173 .justify_center()
174 .tooltip(move |_, cx| cx.new(|_| OverlayTip(h.clone())).into())
175 .child(Icon::CircleHelp.el(IconSize::Inline, t.ink3))
176 }))
177 .children(reset.map(|reset| {
178 Button::new("card-section-reset-all")
179 .label("Reset all")
180 .icon(Icon::RotateCcw)
181 .style(ButtonStyle::Ghost)
182 .size(ButtonSize::Small)
183 .build()
184 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
185 reset(this, cx);
186 cx.notify();
187 }))
188 }))
189}
190
191/// A disclosure row ("More"): a chevron (right when closed, down when open)
192/// and the label, one 28px click target; `ink2` at rest, `ink1` under the
193/// pointer. `on_toggle` flips the card's own open flag. The chevron is the
194/// Lucide icon, never a text glyph.
195#[allow(dead_code, reason = "the cards adopt it next")]
196pub(super) fn disclosure_row(
197 id: &'static str,
198 label: impl Into<SharedString>,
199 open: bool,
200 on_toggle: fn(&mut Player, &mut Context<Player>),
201 cx: &mut Context<Player>,
202) -> Stateful<Div> {
203 let t = tokens();
204 div()
205 .id(id)
206 .flex_none()
207 .w_full()
208 .h(px(r::CONTROL_M))
209 .flex()
210 .items_center()
211 .gap(px(4.))
212 .cursor_pointer()
213 .type_style(type_scale::body_strong())
214 .text_color(rgb(t.ink2))
215 .hover(|s| s.text_color(rgb(tokens().ink1)))
216 .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| {
217 on_toggle(this, cx);
218 cx.notify();
219 }))
220 .child(if open { Icon::ChevronDown } else { Icon::ChevronRight }.el(IconSize::Inline, t.ink3))
221 .child(label.into())
222}
223
224/// Gap between a card's head, rows and sections: one for every card.
225pub(crate) const CARD_GAP: f32 = 6.;
226
227impl Player {
228 /// The outer element of every clip card. Docked (the normal case) it is a
229 /// plain column in the Clip tab, in flow, so every card opens in the same
230 /// place; only a maximized card still takes the window-space scrim.
231 pub(super) fn card_outer(&self, viewport: Size<Pixels>, cx: &Context<Self>) -> Div {
232 match self.card_maximized {
233 false => div().w_full().flex_none().flex().flex_col(),
234 true => drag_scrim(cx)
235 .flex()
236 .justify_center()
237 .items_center()
238 .bg(rgba(SCRIM()))
239 .top(px(crate::ui::stance::maximized_card_top(
240 f32::from(viewport.height),
241 self.split_px(Split::Bench, viewport),
242 )))
243 // Click away closes it, as on every card here.
244 .on_mouse_down(
245 MouseButton::Left,
246 cx.listener(|this, _: &MouseDownEvent, _, cx| {
247 this.close_card();
248 cx.notify();
249 cx.stop_propagation();
250 }),
251 ),
252 }
253 }
254
255 /// The panel inside [`Self::card_outer`]: bare in the dock, the bordered
256 /// plate when maximized.
257 pub(super) fn card_surface<S: Styled>(&self, d: S) -> S {
258 match self.card_maximized {
259 false => d,
260 true => d
261 .p(px(12.))
262 .rounded(px(6.))
263 .bg(rgb(DARK_PANEL()))
264 .border_1()
265 .border_color(rgba(DARK_SEAM())),
266 }
267 }
268}
269
270/// The help/status line under a card's head: what the keys do, which is
271/// metadata about the room's controls -- mono, §3.
272pub(super) fn dark_help(text: impl Into<SharedString>) -> Div {
273 div()
274 .w_full()
275 .min_w(px(0.))
276 .type_style(type_scale::caption())
277 .text_color(rgb(tokens().ink3))
278 .child(text.into())
279}
280
281/// A ghost action row (DESIGN §4): borderless label + its chord, never a
282/// filled box -- the shape every card's Reset/Flatten/Add/Remove/toggle
283/// button takes now that "boxes are commitments" and Export is the one box
284/// in the room. `active` is a toggle's own held-on state (EQ's spectrum
285/// switch), not hover -- it keeps the fill and brightens the ink the same
286/// way a picked param row's ring does.
287pub(super) fn dark_ghost_button(
288 id: impl Into<gpui::ElementId>,
289 text: impl Into<SharedString>,
290 chord: &str,
291 active: bool,
292 on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
293) -> impl IntoElement {
294 let id = id.into();
295 let text: SharedString = text.into();
296 let t = tokens();
297 let hitmap = hitmap::enabled().then(|| {
298 let id = id.to_string();
299 let label = text.clone();
300 hitmap::dynamic(move || (format!("card.{id}"), label.to_string()), true)
301 });
302 // REDESIGN §1.5: a secondary button (`e2`, `line` border), `e3` and `ink1`
303 // while it is the one that is on. Keys live in the tooltip, never on it.
304 div()
305 .id(id)
306 .flex_1()
307 .flex()
308 .h(px(r::CONTROL_M))
309 .items_center()
310 .justify_center()
311 .gap(px(6.))
312 .rounded(px(r::R_CONTROL))
313 .border_1()
314 .border_color(rgba(t.line))
315 .bg(rgb(if active { t.e3 } else { t.e2 }))
316 .cursor_pointer()
317 .hover(move |s| s.bg(rgb(t.e3)))
318 .active(move |s| s.bg(rgb(t.e4)))
319 .on_click(on_click)
320 // A tooltip that only repeats the label is noise: only a chord earns one.
321 .when(!chord.is_empty(), |d| {
322 d.tooltip(crate::ui::widgets::overlay_tip_hover(&text, chord, None))
323 })
324 .children(hitmap.flatten())
325 .child(
326 div()
327 .type_style(type_scale::body_strong())
328 .text_color(rgb(if active { t.ink1 } else { t.ink2 }))
329 .child(text),
330 )
331}
332
333/// A two-state toggle button (Mute, Solo): when `on` it takes a fill and a border of `tint` and
334/// its label in `tint`, so the held state reads at a glance; off, it is the plain ghost button.
335/// The border is drawn either way, so the button is the same size on and off. `tip` says what the
336/// switch does, in plain words, on hover.
337pub(super) fn dark_toggle_button(
338 id: impl Into<gpui::ElementId>,
339 text: impl Into<SharedString>,
340 on: bool,
341 tint: u32,
342 tip: &'static str,
343 on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
344) -> impl IntoElement {
345 let id = id.into();
346 let text: SharedString = text.into();
347 let t = tokens();
348 let hitmap = hitmap::enabled().then(|| {
349 let id = id.to_string();
350 let label = text.clone();
351 hitmap::dynamic(move || (format!("card.{id}"), label.to_string()), true)
352 });
353 let fill = match on {
354 true => crate::ui::theme::mix(t.e2, tint, 0.22),
355 false => t.e2,
356 };
357 div()
358 .id(id)
359 .flex_1()
360 .flex()
361 .h(px(r::CONTROL_M))
362 .items_center()
363 .justify_center()
364 .rounded(px(r::R_CONTROL))
365 .border_1()
366 .border_color(match on {
367 true => rgb(tint),
368 false => rgba(t.line),
369 })
370 .bg(rgb(fill))
371 .cursor_pointer()
372 .hover(move |s| s.bg(rgb(match on {
373 true => crate::ui::theme::mix(t.e3, tint, 0.22),
374 false => t.e3,
375 })))
376 .active(move |s| s.bg(rgb(t.e4)))
377 .tooltip(crate::ui::widgets::overlay_tip_hover(&text, "", Some(tip)))
378 .on_click(on_click)
379 .children(hitmap.flatten())
380 .child(
381 div()
382 .type_style(type_scale::body_strong())
383 .text_color(rgb(if on { tint } else { t.ink2 }))
384 .child(text),
385 )
386}