edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching·0 forks·Rust·18.3 MiB·ff99ad6·Tahinli·6 days ago·1055 commits
| 1 | //! The component gallery: every token, type role, icon and component of the |
| 2 | //! redesign kit painted in every state on one scrolling page. It is the P1 |
| 3 | //! exit test (captured headless at 1920x1080 and 1280x720) and the place to |
| 4 | //! look when a later phase restyles a region and wants to know what a state |
| 5 | //! is *supposed* to look like. |
| 6 | //! |
| 7 | //! Reach it from the command palette (Ctrl+K), typing `component gallery` |
| 8 | //! and pressing Enter; Escape or the Close button leaves. It is not an |
| 9 | //! action: it has no menu entry, no key and no place in the keymap. |
| 10 | |
| 11 | use crate::layout::redesign as r; |
| 12 | use crate::ui::icons::{Icon, IconSize}; |
| 13 | use crate::ui::kit::{ |
| 14 | self, Button, ButtonSize, ButtonStyle, Look, ScrubLook, Segment, keycap, scrub_field, |
| 15 | section_head, segmented, switch, |
| 16 | }; |
| 17 | use crate::ui::theme::{ClipKind, tokens}; |
| 18 | use crate::ui::type_scale::{self, Typeset}; |
| 19 | use crate::*; |
| 20 | use gpui::{Hsla, SharedString}; |
| 21 | use std::sync::atomic::AtomicUsize; |
| 22 | |
| 23 | static OPEN: AtomicBool = AtomicBool::new(false); |
| 24 | static SEG: AtomicUsize = AtomicUsize::new(1); |
| 25 | static SWITCH: AtomicBool = AtomicBool::new(true); |
| 26 | static TOGGLE: AtomicBool = AtomicBool::new(true); |
| 27 | |
| 28 | /// What the palette types to reach the gallery. |
| 29 | pub(crate) const PALETTE_PHRASE: &str = "component gallery"; |
| 30 | |
| 31 | pub(crate) fn is_open() -> bool { |
| 32 | OPEN.load(Ordering::Relaxed) |
| 33 | } |
| 34 | |
| 35 | pub(crate) fn set_open(open: bool) { |
| 36 | OPEN.store(open, Ordering::Relaxed); |
| 37 | } |
| 38 | |
| 39 | fn c(x: u32) -> Hsla { |
| 40 | rgb(x).into() |
| 41 | } |
| 42 | |
| 43 | fn panel(title: &str) -> Div { |
| 44 | div() |
| 45 | .flex_none() |
| 46 | .w(px(400.)) |
| 47 | .p(px(12.)) |
| 48 | .flex() |
| 49 | .flex_col() |
| 50 | .gap(px(8.)) |
| 51 | .rounded(px(r::R_CARD)) |
| 52 | .bg(c(tokens().e1)) |
| 53 | .child(section_head(title.to_string(), None)) |
| 54 | } |
| 55 | |
| 56 | /// Keeps a child at its own width inside a column panel (columns stretch). |
| 57 | fn left(el: impl IntoElement) -> Div { |
| 58 | div().flex().child(el) |
| 59 | } |
| 60 | |
| 61 | fn row() -> Div { |
| 62 | div().flex().flex_wrap().items_center().gap(px(8.)) |
| 63 | } |
| 64 | |
| 65 | fn note(text: &str) -> Div { |
| 66 | div() |
| 67 | .type_style(type_scale::caption()) |
| 68 | .text_color(c(tokens().ink3)) |
| 69 | .child(text.to_string()) |
| 70 | } |
| 71 | |
| 72 | fn swatch(name: &str, fill: u32, ink: u32) -> Div { |
| 73 | div() |
| 74 | .flex_none() |
| 75 | .w(px(86.)) |
| 76 | .h(px(40.)) |
| 77 | .px(px(6.)) |
| 78 | .flex() |
| 79 | .items_center() |
| 80 | .rounded(px(r::R_CONTROL)) |
| 81 | .bg(c(fill)) |
| 82 | .border_1() |
| 83 | .border_color(c(tokens().edge)) |
| 84 | .type_style(type_scale::caption()) |
| 85 | .text_color(c(ink)) |
| 86 | .child(name.to_string()) |
| 87 | } |
| 88 | |
| 89 | fn state_label(text: &str) -> Div { |
| 90 | note(text).w(px(64.)) |
| 91 | } |
| 92 | |
| 93 | const LOOKS: [(&str, Option<Look>); 4] = [ |
| 94 | ("Rest", None), |
| 95 | ("Hover", Some(Look::Hover)), |
| 96 | ("Pressed", Some(Look::Pressed)), |
| 97 | ("Focus", Some(Look::Focus)), |
| 98 | ]; |
| 99 | |
| 100 | fn type_panel() -> Div { |
| 101 | let t = tokens(); |
| 102 | let line = |style: type_scale::TypeStyle, text: &str, ink: u32| { |
| 103 | div().type_style(style).text_color(c(ink)).child(text.to_string()) |
| 104 | }; |
| 105 | panel("Type") |
| 106 | .child(line(type_scale::title(), "Title 16/22 Inter 600", t.ink1)) |
| 107 | .child(line(type_scale::emph(), "Emphasis 14/20 Inter 500", t.ink1)) |
| 108 | .child(line(type_scale::body(), "Body 13/18 Inter 400, H.264 \u{b7} 1280\u{d7}720 \u{b7} 25 fps", t.ink1)) |
| 109 | .child(line(type_scale::body_strong(), "Body that acts 13/18 Inter 500", t.ink1)) |
| 110 | .child(line(type_scale::caption(), "Caption 12/16 Inter 400 0123456789", t.ink2)) |
| 111 | .child(line(type_scale::caption_strong(), "Clip name 12/16 Inter 500", t.ink1)) |
| 112 | .child(line(type_scale::section(), "Section head 12/16 Inter 600", t.ink2)) |
| 113 | .child(line(type_scale::timecode(), "00:00:02:22", t.ink1)) |
| 114 | .child(line(type_scale::body(), "\u{414}\u{43e}\u{431}\u{440}\u{43e} \u{3b5}\u{3bb}\u{3bb}\u{3b7}\u{3bd}\u{3b9}\u{3ba}\u{3ac} \u{c5}ngstr\u{f6}m \u{15f}\u{11f}\u{131}", t.ink3)) |
| 115 | } |
| 116 | |
| 117 | fn surface_panel() -> Div { |
| 118 | let t = tokens(); |
| 119 | panel("Surfaces and ink") |
| 120 | .child( |
| 121 | row() |
| 122 | .child(swatch("e0 window", t.e0, t.ink1)) |
| 123 | .child(swatch("e1 panel", t.e1, t.ink1)) |
| 124 | .child(swatch("e2 raised", t.e2, t.ink1)) |
| 125 | .child(swatch("e3 hover", t.e3, t.ink1)) |
| 126 | .child(swatch("e4 pressed", t.e4, t.ink1)) |
| 127 | .child(swatch("well", t.well, t.ink1)) |
| 128 | .child(swatch("matte", t.matte, t.ink1)) |
| 129 | .child(swatch("edge", t.edge, t.e0)), |
| 130 | ) |
| 131 | .child( |
| 132 | row() |
| 133 | .child(swatch("ink1", t.e1, t.ink1)) |
| 134 | .child(swatch("ink2", t.e1, t.ink2)) |
| 135 | .child(swatch("ink3", t.e1, t.ink3)) |
| 136 | .child(swatch("ink4 off", t.e1, t.ink4)), |
| 137 | ) |
| 138 | .child( |
| 139 | row() |
| 140 | .child(swatch("accent", t.accent, t.e0)) |
| 141 | .child(swatch("hover", t.accent_hover, t.e0)) |
| 142 | .child(swatch("press", t.accent_press, t.on_accent)) |
| 143 | .child(swatch("fill", t.accent_fill, t.on_accent)), |
| 144 | ) |
| 145 | .child( |
| 146 | row() |
| 147 | .child(swatch("err", t.e1, t.err)) |
| 148 | .child(swatch("warn", t.e1, t.warn)) |
| 149 | .child(swatch("ok", t.e1, t.ok)), |
| 150 | ) |
| 151 | } |
| 152 | |
| 153 | fn clip_panel() -> Div { |
| 154 | let t = tokens(); |
| 155 | let names = [ |
| 156 | ("Video", Icon::Film), |
| 157 | ("Image", Icon::Image), |
| 158 | ("Audio", Icon::AudioWaveform), |
| 159 | ("Title", Icon::Type), |
| 160 | ("Caption", Icon::Captions), |
| 161 | ("Compound", Icon::Layers), |
| 162 | ("Multicam", Icon::Clapperboard), |
| 163 | ]; |
| 164 | let mut p = panel("Clip colours by media type"); |
| 165 | for (kind, (name, icon)) in ClipKind::ALL.into_iter().zip(names) { |
| 166 | let tone = t.clip(kind); |
| 167 | p = p.child( |
| 168 | div() |
| 169 | .h(px(32.)) |
| 170 | .flex() |
| 171 | .items_center() |
| 172 | .rounded(px(r::R_CLIP)) |
| 173 | .overflow_hidden() |
| 174 | .bg(c(tone.body)) |
| 175 | .child( |
| 176 | div() |
| 177 | .h_full() |
| 178 | .w(px(3.)) |
| 179 | .bg(c(t.clip(ClipKind::Video).ink)), |
| 180 | ) |
| 181 | .child( |
| 182 | div() |
| 183 | .h_full() |
| 184 | .w(px(120.)) |
| 185 | .px(px(8.)) |
| 186 | .flex() |
| 187 | .items_center() |
| 188 | .gap(px(6.)) |
| 189 | .bg(c(tone.strip)) |
| 190 | .type_style(type_scale::caption_strong()) |
| 191 | .text_color(c(tone.label)) |
| 192 | .child(icon.el(IconSize::Inline, tone.label)) |
| 193 | .child(name.to_string()), |
| 194 | ) |
| 195 | .child( |
| 196 | div() |
| 197 | .px(px(8.)) |
| 198 | .type_style(type_scale::caption()) |
| 199 | .text_color(c(tone.ink)) |
| 200 | .child("waveform / glyph ink"), |
| 201 | ), |
| 202 | ); |
| 203 | } |
| 204 | p |
| 205 | } |
| 206 | |
| 207 | fn button_panel() -> Div { |
| 208 | let mut p = panel("Buttons: primary, secondary, ghost"); |
| 209 | for (name, style) in [ |
| 210 | ("Primary", ButtonStyle::Primary), |
| 211 | ("Secondary", ButtonStyle::Secondary), |
| 212 | ("Ghost", ButtonStyle::Ghost), |
| 213 | ] { |
| 214 | let mut r_ = row().child(state_label(name)); |
| 215 | for (i, (_, look)) in LOOKS.iter().enumerate() { |
| 216 | let mut b = Button::new(Box::leak(format!("g-btn-{name}-{i}").into_boxed_str())) |
| 217 | .label("Export") |
| 218 | .style(style); |
| 219 | if let Some(look) = look { |
| 220 | b = b.look(*look); |
| 221 | } |
| 222 | r_ = r_.child(b.build()); |
| 223 | } |
| 224 | r_ = r_.child( |
| 225 | Button::new(Box::leak(format!("g-btn-{name}-dis").into_boxed_str())) |
| 226 | .label("Disabled") |
| 227 | .style(style) |
| 228 | .enabled(false) |
| 229 | .build(), |
| 230 | ); |
| 231 | p = p.child(r_); |
| 232 | } |
| 233 | let mut sizes = row().child(state_label("Sizes")); |
| 234 | for (i, (label, size)) in [ |
| 235 | ("24", ButtonSize::Small), |
| 236 | ("28", ButtonSize::Default), |
| 237 | ("32", ButtonSize::Large), |
| 238 | ("36", ButtonSize::Hero), |
| 239 | ] |
| 240 | .into_iter() |
| 241 | .enumerate() |
| 242 | { |
| 243 | sizes = sizes.child( |
| 244 | Button::new(Box::leak(format!("g-size-{i}").into_boxed_str())) |
| 245 | .icon(Icon::Upload) |
| 246 | .label(label) |
| 247 | .size(size) |
| 248 | .build(), |
| 249 | ); |
| 250 | } |
| 251 | p.child(sizes) |
| 252 | } |
| 253 | |
| 254 | fn icon_button_panel(cx: &mut Context<Player>) -> Div { |
| 255 | let on = TOGGLE.load(Ordering::Relaxed); |
| 256 | let mut icons = row().child(state_label("Icon only")); |
| 257 | for (i, (_, look)) in LOOKS.iter().enumerate() { |
| 258 | let mut b = Button::new(Box::leak(format!("g-ib-{i}").into_boxed_str())) |
| 259 | .icon(Icon::Play) |
| 260 | .style(ButtonStyle::Ghost) |
| 261 | .size(ButtonSize::Large); |
| 262 | if let Some(look) = look { |
| 263 | b = b.look(*look); |
| 264 | } |
| 265 | icons = icons.child(b.build()); |
| 266 | } |
| 267 | icons = icons.child( |
| 268 | Button::new("g-ib-dis") |
| 269 | .icon(Icon::Play) |
| 270 | .style(ButtonStyle::Ghost) |
| 271 | .size(ButtonSize::Large) |
| 272 | .enabled(false) |
| 273 | .build(), |
| 274 | ); |
| 275 | let toggles = row() |
| 276 | .child(state_label("Toggle")) |
| 277 | .child( |
| 278 | Button::new("g-tg-off") |
| 279 | .icon(Icon::Magnet) |
| 280 | .label("Snap") |
| 281 | .style(ButtonStyle::Ghost) |
| 282 | .size(ButtonSize::Large) |
| 283 | .build(), |
| 284 | ) |
| 285 | .child( |
| 286 | Button::new("g-tg-on") |
| 287 | .icon(Icon::Magnet) |
| 288 | .label("Snap") |
| 289 | .style(ButtonStyle::Ghost) |
| 290 | .size(ButtonSize::Large) |
| 291 | .on(true) |
| 292 | .build(), |
| 293 | ) |
| 294 | .child( |
| 295 | Button::new("g-tg-on-hover") |
| 296 | .icon(Icon::Magnet) |
| 297 | .label("Snap") |
| 298 | .style(ButtonStyle::Ghost) |
| 299 | .size(ButtonSize::Large) |
| 300 | .on(true) |
| 301 | .look(Look::Hover) |
| 302 | .build(), |
| 303 | ); |
| 304 | let live = row().child(state_label("Live")).child( |
| 305 | Button::new("g-tg-live") |
| 306 | .icon(if on { Icon::Volume2 } else { Icon::VolumeX }) |
| 307 | .label(if on { "Sound on" } else { "Muted" }) |
| 308 | .style(ButtonStyle::Ghost) |
| 309 | .size(ButtonSize::Large) |
| 310 | .min_w(112.) |
| 311 | .on(on) |
| 312 | .build() |
| 313 | .on_click(cx.listener(|_, _, _, cx| { |
| 314 | TOGGLE.fetch_xor(true, Ordering::Relaxed); |
| 315 | cx.notify(); |
| 316 | })), |
| 317 | ); |
| 318 | panel("Icon buttons and toggles") |
| 319 | .child(icons) |
| 320 | .child(toggles) |
| 321 | .child(live) |
| 322 | .child(note("A toggle swaps the icon shape and the tint; the box never moves.")) |
| 323 | } |
| 324 | |
| 325 | fn segmented_panel(cx: &mut Context<Player>) -> Div { |
| 326 | let sel = SEG.load(Ordering::Relaxed); |
| 327 | let items = |names: &[&str]| names.iter().map(|n| Segment::text(n.to_string())).collect::<Vec<_>>(); |
| 328 | let live = segmented( |
| 329 | "g-seg-live", |
| 330 | &items(&["Histogram", "Waveform", "Vector", "Parade"]), |
| 331 | sel, |
| 332 | true, |
| 333 | None, |
| 334 | { |
| 335 | let entity = cx.entity(); |
| 336 | move |i, _, cx| { |
| 337 | SEG.store(i, Ordering::Relaxed); |
| 338 | entity.update(cx, |_, cx| cx.notify()); |
| 339 | } |
| 340 | }, |
| 341 | ); |
| 342 | let live = left(live); |
| 343 | let noop = |_: usize, _: &mut Window, _: &mut App| {}; |
| 344 | panel("Segmented control and switch") |
| 345 | .child(note("Live (click)")) |
| 346 | .child(live) |
| 347 | .child(note("Hover on an unselected pill")) |
| 348 | .child(left(segmented("g-seg-hover", &items(&["Off", "On"]), 1, true, Some((0, Look::Hover)), noop))) |
| 349 | .child(note("Focus on the selected pill")) |
| 350 | .child(left(segmented("g-seg-focus", &items(&["Off", "On"]), 1, true, Some((1, Look::Focus)), noop))) |
| 351 | .child(note("Disabled")) |
| 352 | .child(left(segmented("g-seg-dis", &items(&["Fit", "50%", "100%"]), 0, false, None, noop))) |
| 353 | .child( |
| 354 | row() |
| 355 | .child(state_label("Switch")) |
| 356 | .child(switch("g-sw-off", false, true, None)) |
| 357 | .child(switch("g-sw-on", true, true, None)) |
| 358 | .child(switch("g-sw-hover", false, true, Some(Look::Hover))) |
| 359 | .child(switch("g-sw-onhover", true, true, Some(Look::Hover))) |
| 360 | .child(switch("g-sw-focus", true, true, Some(Look::Focus))) |
| 361 | .child(switch("g-sw-dis", true, false, None)), |
| 362 | ) |
| 363 | .child( |
| 364 | row().child(state_label("Live")).child( |
| 365 | switch("g-sw-live", SWITCH.load(Ordering::Relaxed), true, None).on_click(cx.listener( |
| 366 | |_, _, _, cx| { |
| 367 | SWITCH.fetch_xor(true, Ordering::Relaxed); |
| 368 | cx.notify(); |
| 369 | }, |
| 370 | )), |
| 371 | ), |
| 372 | ) |
| 373 | } |
| 374 | |
| 375 | fn field_panel() -> Div { |
| 376 | let t = tokens(); |
| 377 | let labelled = |name: &str, field: Stateful<Div>| { |
| 378 | row() |
| 379 | .child(div().w(px(64.)).type_style(type_scale::body()).text_color(c(t.ink2)).child(name.to_string())) |
| 380 | .child(field) |
| 381 | }; |
| 382 | panel("Scrub-number fields, section head, keycaps") |
| 383 | .child(labelled("Rest", scrub_field("g-sf-rest", 88., "1.00", Some("\u{d7}"), true, None))) |
| 384 | .child(labelled("Hover", scrub_field("g-sf-hover", 88., "1.00", Some("\u{d7}"), true, Some(ScrubLook::Hover)))) |
| 385 | .child(labelled("Typing", scrub_field("g-sf-type", 88., "0.75", Some("\u{d7}"), true, Some(ScrubLook::Typing)))) |
| 386 | .child(labelled("Disabled", scrub_field("g-sf-dis", 88., "1.00", Some("\u{d7}"), false, None))) |
| 387 | .child(section_head( |
| 388 | "Speed", |
| 389 | Some( |
| 390 | Button::new("g-reset") |
| 391 | .icon(Icon::RotateCcw) |
| 392 | .style(ButtonStyle::Ghost) |
| 393 | .size(ButtonSize::Small) |
| 394 | .build() |
| 395 | .into_any_element(), |
| 396 | ), |
| 397 | )) |
| 398 | .child( |
| 399 | row() |
| 400 | .child(state_label("Keycaps")) |
| 401 | .child(keycap("Space")) |
| 402 | .child(keycap("Ctrl")) |
| 403 | .child(keycap("K")) |
| 404 | .child(keycap("\u{2190}")), |
| 405 | ) |
| 406 | } |
| 407 | |
| 408 | static COLOUR: AtomicUsize = AtomicUsize::new(0x7c5cff); |
| 409 | static DROP: AtomicUsize = AtomicUsize::new(1); |
| 410 | |
| 411 | /// The card components: equal and wrapping segmented rows, switch rows, value |
| 412 | /// pills with the reserved reset slot, number fields, swatches with a custom |
| 413 | /// colour, a card dropdown, ghost icon buttons and keycaps. |
| 414 | fn card_panel(cx: &mut Context<Player>) -> Div { |
| 415 | let items = |names: &[&str]| names.iter().map(|n| Segment::text(n.to_string())).collect::<Vec<_>>(); |
| 416 | let noop = |_: usize, _: &mut Window, _: &mut App| {}; |
| 417 | let nop = |_: &mut Window, _: &mut App| {}; |
| 418 | let me = cx.entity(); |
| 419 | let colour = COLOUR.load(Ordering::Relaxed) as u32; |
| 420 | let drop_items: Vec<SharedString> = ["Fit", "Fill", "Stretch"].iter().map(|s| SharedString::from(*s)).collect(); |
| 421 | panel("Card components") |
| 422 | .child(note("Equal-width segmented")) |
| 423 | .child(kit::segmented_equal("g-seg-eq", &items(&["Left", "Centre", "Right"]), 1, true, None, noop)) |
| 424 | .child(note("Wrapping segmented (never clips a label)")) |
| 425 | .child(div().w(px(220.)).child(kit::segmented_wrap( |
| 426 | "g-seg-wrap", |
| 427 | &items(&["Cinematic", "Documentary", "Vivid", "Muted", "Black and white"]), |
| 428 | 2, |
| 429 | true, |
| 430 | None, |
| 431 | noop, |
| 432 | ))) |
| 433 | .child(note("Switch rows: on, with a description, disabled with a reason")) |
| 434 | .child(kit::switch_row("g-swr-1", "Loop playback", None, true, None, nop)) |
| 435 | .child(kit::switch_row("g-swr-2", "Burn captions", Some("Draw the captions into the picture".into()), false, None, nop)) |
| 436 | .child(kit::switch_row("g-swr-3", "Hardware encoding", Some("Faster export".into()), false, Some("No supported graphics card found"), nop)) |
| 437 | .child(note("Value pills: fixed width, reset slot always reserved")) |
| 438 | .child(row().child(kit::value_pill("g-vp-1", 64., "1.00", Some("\u{d7}"), false, nop)).child(kit::value_pill("g-vp-2", 64., "1.25", Some("\u{d7}"), true, nop))) |
| 439 | .child(note("Number field: rest, typing (drag scrubs, click types, Enter commits, Esc cancels)")) |
| 440 | .child(row() |
| 441 | .child(kit::number_field("g-nf-1", 88., "1.00", Some("\u{d7}"), None, true)) |
| 442 | .child(kit::number_field("g-nf-2", 88., "", Some("\u{d7}"), Some(&kit::NumberEdit::begin("0.75")), true)) |
| 443 | .child(kit::reset_slot("g-nf-reset", true, nop))) |
| 444 | .child(note("Swatches: ring on the current colour; a custom one is added to the row")) |
| 445 | .child(kit::swatch_row( |
| 446 | "g-sw-row", |
| 447 | &[0xff5c5c, 0xffb84d, 0x4dd47c, 0x4d9fff], |
| 448 | colour, |
| 449 | None, |
| 450 | { |
| 451 | let me = me.clone(); |
| 452 | move |rgb, _, cx| { |
| 453 | COLOUR.store(rgb as usize, Ordering::Relaxed); |
| 454 | me.update(cx, |_, cx| cx.notify()); |
| 455 | } |
| 456 | }, |
| 457 | nop, |
| 458 | )) |
| 459 | .child(note("Card dropdown (click)")) |
| 460 | .child(div().w(px(220.)).child(kit::dropdown_field("g-dd", drop_items[DROP.load(Ordering::Relaxed)].clone(), true).on_click(cx.listener(|_, _, _, cx| { |
| 461 | DROP.store((DROP.load(Ordering::Relaxed) + 1) % 3, Ordering::Relaxed); |
| 462 | cx.notify(); |
| 463 | })))) |
| 464 | .child(div().w(px(220.)).child(kit::choice_list("g-dd-list", 220., &drop_items, DROP.load(Ordering::Relaxed), nop_pick))) |
| 465 | .child(note("Ghost icon buttons: move up, move down (disabled, with reason), remove")) |
| 466 | .child(row() |
| 467 | .child(kit::icon_ghost("g-ig-up", Icon::ChevronUp, "Move up", None, nop)) |
| 468 | .child(kit::icon_ghost("g-ig-down", Icon::ChevronDown, "Move down", Some("Already last"), nop)) |
| 469 | .child(kit::icon_ghost("g-ig-rm", Icon::Trash2, "Remove", None, nop))) |
| 470 | .child(note("Keycaps from a chord")) |
| 471 | .child(row().child(kit::keycaps("Ctrl+Shift+R")).child(kit::keycaps("Ctrl++")).child(kit::keycaps("Space"))) |
| 472 | } |
| 473 | |
| 474 | fn nop_pick(_: usize, _: &mut Window, _: &mut App) {} |
| 475 | |
| 476 | /// The dialog shell, drawn inline (the real one is a scrim over the window). |
| 477 | fn dialog_panel() -> Div { |
| 478 | panel("Dialog shell") |
| 479 | .child( |
| 480 | kit::dialog("g-dialog", 360.) |
| 481 | .child(kit::dialog_title("Save changes?")) |
| 482 | .child(kit::dialog_text("Body text sits at ink2 and wraps inside the plate.")) |
| 483 | .child( |
| 484 | kit::dialog_actions() |
| 485 | .child(Button::new("g-dlg-no").label("Cancel").build()) |
| 486 | .child(Button::new("g-dlg-yes").label("Save").style(ButtonStyle::Primary).build()), |
| 487 | ), |
| 488 | ) |
| 489 | } |
| 490 | |
| 491 | fn popup_panel() -> Div { |
| 492 | let t = tokens(); |
| 493 | let menu_row = |icon: Option<Icon>, label: &str, key: &str, look: Option<Look>, enabled: bool| { |
| 494 | let ink = if enabled { t.ink1 } else { t.ink4 }; |
| 495 | let mut d = div() |
| 496 | .id(Box::leak(format!("g-mr-{label}").into_boxed_str()) as &'static str) |
| 497 | .h(px(r::MENU_ROW_H)) |
| 498 | .px(px(12.)) |
| 499 | .flex() |
| 500 | .items_center() |
| 501 | .gap(px(8.)) |
| 502 | .type_style(type_scale::body_strong()) |
| 503 | .text_color(c(ink)) |
| 504 | .child(div().w(px(16.)).flex_none().children(icon.map(|i| i.el(IconSize::Inline, if enabled { t.ink2 } else { t.ink4 })))) |
| 505 | .child(div().flex_1().child(label.to_string())) |
| 506 | .child(div().type_style(type_scale::caption()).text_color(c(t.ink3)).child(key.to_string())); |
| 507 | d = kit::states(d, kit::Fills::ghost(), enabled, look); |
| 508 | d |
| 509 | }; |
| 510 | panel("One popup look: plate and menu rows") |
| 511 | .child( |
| 512 | kit::plate(r::R_CARD) |
| 513 | .w(px(280.)) |
| 514 | .py(px(4.)) |
| 515 | .flex() |
| 516 | .flex_col() |
| 517 | .child(menu_row(Some(Icon::Scissors), "Split", "S", None, true)) |
| 518 | .child(menu_row(Some(Icon::Trash2), "Delete", "X", Some(Look::Hover), true)) |
| 519 | .child(menu_row(Some(Icon::Eraser), "Lift", "Shift+X", Some(Look::Pressed), true)) |
| 520 | .child(div().h(px(1.)).mx(px(8.)).my(px(4.)).bg(Hsla::from(rgba(t.line)))) |
| 521 | .child(menu_row(None, "Paste", "Ctrl+V", None, false)), |
| 522 | ) |
| 523 | .child(left( |
| 524 | kit::plate(r::R_CARD) |
| 525 | .px(px(8.)) |
| 526 | .py(px(6.)) |
| 527 | .flex() |
| 528 | .items_center() |
| 529 | .gap(px(8.)) |
| 530 | .type_style(type_scale::caption()) |
| 531 | .text_color(c(t.ink1)) |
| 532 | .child("Play / Pause") |
| 533 | .child(keycap("Space")), |
| 534 | )) |
| 535 | } |
| 536 | |
| 537 | fn icon_panel() -> Div { |
| 538 | let t = tokens(); |
| 539 | let mut grid = row().gap(px(10.)); |
| 540 | for icon in Icon::ALL { |
| 541 | grid = grid.child(icon.el(IconSize::Inline, t.ink2)); |
| 542 | } |
| 543 | let mut big = row().gap(px(12.)); |
| 544 | for icon in [Icon::Play, Icon::Scissors, Icon::Magnet, Icon::Upload, Icon::Settings] { |
| 545 | big = big.child(icon.el(IconSize::Toolbar, t.ink1)); |
| 546 | } |
| 547 | big = big.child(Icon::Clapperboard.el(IconSize::Hero, t.ink3)); |
| 548 | panel(&format!("Icons: {} Lucide at 16, 20 and 40", Icon::ALL.len())) |
| 549 | .child(grid) |
| 550 | .child(big) |
| 551 | .child( |
| 552 | row() |
| 553 | .child(Icon::Eye.stated(IconSize::Toolbar, theme_state(0))) |
| 554 | .child(Icon::Eye.stated(IconSize::Toolbar, theme_state(1))) |
| 555 | .child(Icon::Eye.stated(IconSize::Toolbar, theme_state(2))) |
| 556 | .child(Icon::EyeOff.stated(IconSize::Toolbar, theme_state(3))) |
| 557 | .child(note("rest, hover, on, disabled")), |
| 558 | ) |
| 559 | } |
| 560 | |
| 561 | fn theme_state(i: usize) -> crate::ui::icons::IconState { |
| 562 | use crate::ui::icons::IconState::*; |
| 563 | [Rest, Hover, On, Disabled][i] |
| 564 | } |
| 565 | |
| 566 | /// The gallery as a window-sized overlay, or nothing while it is closed. |
| 567 | /// Mounted last in the stance so it covers everything, menus included. |
| 568 | pub(crate) fn overlay(cx: &mut Context<Player>) -> Option<AnyElement> { |
| 569 | if !is_open() { |
| 570 | return None; |
| 571 | } |
| 572 | let t = tokens(); |
| 573 | let head = div() |
| 574 | .flex_none() |
| 575 | .h(px(r::MENU_BAR_H + 8.)) |
| 576 | .px(px(16.)) |
| 577 | .flex() |
| 578 | .items_center() |
| 579 | .justify_between() |
| 580 | .child( |
| 581 | div() |
| 582 | .type_style(type_scale::title()) |
| 583 | .text_color(c(t.ink1)) |
| 584 | .child(SharedString::from("Component gallery")), |
| 585 | ) |
| 586 | .child( |
| 587 | Button::new("g-close") |
| 588 | .label("Close") |
| 589 | .size(ButtonSize::Default) |
| 590 | .build() |
| 591 | .on_click(cx.listener(|_, _, _, cx| { |
| 592 | set_open(false); |
| 593 | cx.notify(); |
| 594 | })), |
| 595 | ); |
| 596 | let body = div() |
| 597 | .id("gallery-scroll") |
| 598 | .flex_1() |
| 599 | .min_h_0() |
| 600 | .overflow_y_scroll() |
| 601 | .px(px(16.)) |
| 602 | .pb(px(16.)) |
| 603 | .child( |
| 604 | div() |
| 605 | .flex() |
| 606 | .flex_wrap() |
| 607 | .items_start() |
| 608 | .gap(px(12.)) |
| 609 | .child(type_panel()) |
| 610 | .child(surface_panel()) |
| 611 | .child(clip_panel()) |
| 612 | .child(button_panel()) |
| 613 | .child(icon_button_panel(cx)) |
| 614 | .child(segmented_panel(cx)) |
| 615 | .child(field_panel()) |
| 616 | .child(card_panel(cx)) |
| 617 | .child(dialog_panel()) |
| 618 | .child(popup_panel()) |
| 619 | .child(icon_panel()), |
| 620 | ); |
| 621 | Some( |
| 622 | div() |
| 623 | .id("component-gallery") |
| 624 | .occlude() |
| 625 | .absolute() |
| 626 | .top_0() |
| 627 | .left_0() |
| 628 | .size_full() |
| 629 | .flex() |
| 630 | .flex_col() |
| 631 | .bg(c(t.e0)) |
| 632 | .child(head) |
| 633 | .child(body) |
| 634 | .into_any_element(), |
| 635 | ) |
| 636 | } |