app: cherry-pick rune's pause and sound fixes onto the checkout
Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch ported, carrying the four commits of upstream issues 1320 (a pause while a clip is layered holds the layer's picture and time) and 1325 (a video's sound is read ahead of the clock and leads it). Both were written against eb9f1104 and ported across the refactors since. The faults are the first two and the third in docs/rune-upstream.md; the app's workarounds in review.rs stay until the fixes arrive upstream.
This commit is contained in:
1 parent
80fef698ce
commit
5bf262b82b
3795 files changed
+663463
-28
No files matched your search
+17
@@ -0,0 +1,17 @@
|
||||
[package]
|
||||
name = "kit-gallery"
|
||||
version = "0.0.1"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
rune = { workspace = true, default-features = true, features = ["keys-overlay"] }
|
||||
rune-kit = { workspace = true, default-features = true, features = ["markdown", "mermaid"] }
|
||||
rune-theme-opencode = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
wgpu = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,2 @@
|
||||
max_width = 120
|
||||
use_small_heuristics = "Max"
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"t": 0.25, "type": "key", "name": "Up"},
|
||||
{"t": 0.6, "type": "type", "text": "099"},
|
||||
{"t": 1.1, "type": "key", "name": "Enter"},
|
||||
{"t": 1.6, "type": "click", "key": "model-trigger"},
|
||||
{"t": 2.1, "type": "key", "name": "Escape"}
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{"t": 0.25, "type": "key", "name": "Up"},
|
||||
{"t": 0.6, "type": "type", "text": "099", "expect": "instant", "scope": "model-content"},
|
||||
{"t": 1.1, "type": "key", "name": "Enter"},
|
||||
{"t": 1.6, "type": "click", "key": "model-trigger"},
|
||||
{"t": 2.1, "type": "key", "name": "Escape"}
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"t": 0.2, "type": "move", "key": "copy"},
|
||||
{"t": 1.2, "type": "mark", "name": "end"}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{"t":0.1,"type":"key","name":"Tab"},
|
||||
{"t":0.2,"type":"key","name":"Enter"},
|
||||
{"t":0.5,"type":"key","name":"Tab"},
|
||||
{"t":0.6,"type":"key","name":"Tab"},
|
||||
{"t":1.8,"type":"key","name":"Escape"},
|
||||
{"t":2.4,"type":"key","name":"Tab"},
|
||||
{"t":2.5,"type":"type","text":" "},
|
||||
{"t":2.8,"type":"key","name":"Tab"},
|
||||
{"t":2.9,"type":"type","text":" "},
|
||||
{"t":3.2,"type":"key","name":"Tab"},
|
||||
{"t":3.3,"type":"key","name":"Right"},
|
||||
{"t":3.8,"type":"tap","key":"opener"},
|
||||
{"t":4.8,"type":"tap","x":10,"y":10}
|
||||
]
|
||||
@@ -0,0 +1,6 @@
|
||||
[
|
||||
{"t":0.2,"type":"tap","key":"opener"},
|
||||
{"t":1.4,"type":"tap","key":"opener"},
|
||||
{"t":2.0,"type":"tap","key":"opener"},
|
||||
{"t":2.08,"type":"tap","key":"opener"}
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"t": 0.2, "type": "drag", "x": 99, "y": 74, "dx": 126, "dy": 0, "dur": 0.4},
|
||||
{"t": 1.0, "type": "mark", "name": "end"}
|
||||
]
|
||||
@@ -0,0 +1,149 @@
|
||||
//! Manual, headless disabled-control timing and legacy per-instance pixel comparison.
|
||||
use super::*;
|
||||
use rune::render::{Gpu, Instance, Renderer, Offscreen, OFFSCREEN_FORMAT, KIND_LAYER, KIND_LAYER_END, KIND_GRADIENT};
|
||||
|
||||
fn disabled_controls(_: &G, _: &mut Cx<G>) -> El {
|
||||
let mut s = init();
|
||||
let k = kit(&s, true);
|
||||
let mut overlays = Vec::new();
|
||||
let mut columns = rune::row().gap(24.0);
|
||||
for story in ["ui-radio--states", "ui-text-input--states", "ui-select--disabled"] {
|
||||
s.story = story;
|
||||
columns = columns.child(col().w(300.0).child(stories::render(&s, k, &mut overlays)));
|
||||
}
|
||||
let segmented = rune_kit::SegmentedControl::new(&["List", "Grid", "Board"], Some(0))
|
||||
.segment_state(0, rune_kit::State::Disabled)
|
||||
.segment_state(1, rune_kit::State::Disabled)
|
||||
.segment_state(2, rune_kit::State::Disabled).build(k);
|
||||
rune_kit::root(col().fill(k.c.page).padding(24.0).gap(24.0).child(columns).child(segmented), overlays)
|
||||
}
|
||||
|
||||
fn legacy(instances: &[Instance]) -> Vec<Instance> {
|
||||
let mut alpha = 1.0;
|
||||
let mut stack = Vec::new();
|
||||
let mut out = Vec::new();
|
||||
for i in instances {
|
||||
if i.params[1] == KIND_LAYER { stack.push(alpha); alpha *= i.fill[3]; }
|
||||
else if i.params[1] == KIND_LAYER_END { alpha = stack.pop().unwrap(); }
|
||||
else {
|
||||
let mut i = *i;
|
||||
i.fill = i.fill.map(|v| v * alpha);
|
||||
i.border = i.border.map(|v| v * alpha);
|
||||
if i.params[1] == KIND_GRADIENT { i.uv = i.uv.map(|v| v * alpha); }
|
||||
out.push(i);
|
||||
}
|
||||
}
|
||||
assert!(stack.is_empty());
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "manual byte-for-byte disabled styling check; provide RUNE_KIT_PIXEL_BASELINE"]
|
||||
fn disabled_controls_match_legacy_pixels() {
|
||||
// Record against the pre-dimming kit source (reconstructing dev's per-instance opacity),
|
||||
// then run without RECORD on the new source. Keep the directory outside the build checkout.
|
||||
let directory = std::path::PathBuf::from(std::env::var_os("RUNE_KIT_PIXEL_BASELINE").unwrap());
|
||||
let record = std::env::var_os("RUNE_KIT_RECORD_BASELINE").is_some();
|
||||
std::fs::create_dir_all(&directory).unwrap();
|
||||
let gpu = Gpu::headless();
|
||||
let mut renderer = Renderer::new(&gpu.device, OFFSCREEN_FORMAT);
|
||||
for dark in [false, true] {
|
||||
for scale in [1.0, 2.0] {
|
||||
let target = Offscreen::new(&gpu.device, (1024.0 * scale) as u32, (800.0 * scale) as u32);
|
||||
for story in ["ui-button--all-states", "ui-icon-button--all-states", "ui-radio--states",
|
||||
"ui-text-input--states", "ui-textarea--states", "ui-select--disabled",
|
||||
"ui-switch--states", "ui-menu--basic", "ui-segmented-control--basic"] {
|
||||
let Some((_, setup)) = stories::SCENES.iter().find(|(id, _)| *id == story) else { panic!("missing {story}") };
|
||||
let mut s = init(); setup(&mut s);
|
||||
let text = rune::text::TextSystem::new(rune_theme_opencode::FONTS, rune_theme_opencode::FAMILIES);
|
||||
let mut rt = rune::Runtime::with_text(s, view, (1024.0, 800.0), rune::Env { scale, system_dark: dark }, text);
|
||||
rt.frame(0.0); rt.settle_all(); rt.frame(0.0);
|
||||
if record && story == "ui-button--all-states" {
|
||||
assert!(rt.instances.iter().any(|i| i.params[1] == KIND_LAYER),
|
||||
"record the legacy baseline with the pre-dimming kit source");
|
||||
}
|
||||
let instances = if record { legacy(&rt.instances) } else { rt.instances.clone() };
|
||||
renderer.prepare(&gpu.device, &gpu.queue, &mut rt.text.atlas, &instances, ((1024.0 * scale) as u32, (800.0 * scale) as u32));
|
||||
let mut encoder = gpu.device.create_command_encoder(&Default::default());
|
||||
renderer.draw(&mut encoder, &target.view, [0.0; 4]); target.copy(&mut encoder);
|
||||
gpu.queue.submit([encoder.finish()]);
|
||||
let pixels = target.read(&gpu.device);
|
||||
let path = directory.join(format!("{story}-{dark}-{scale}.rgba"));
|
||||
if record { std::fs::write(path, pixels).unwrap(); }
|
||||
else {
|
||||
let before = std::fs::read(path).unwrap();
|
||||
let differences = pixels.iter().zip(&before).filter(|(a, b)| a != b).count();
|
||||
assert_eq!(pixels.len(), before.len());
|
||||
assert_eq!(differences, 0, "{story} dark={dark} scale={scale}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "manual disabled-controls GPU comparison; run on a build worker"]
|
||||
fn disabled_controls_gpu_cost() {
|
||||
let gpu = Gpu::headless();
|
||||
assert!(gpu.device.features().contains(wgpu::Features::TIMESTAMP_QUERY));
|
||||
eprintln!("adapter: {:?}", gpu.adapter.get_info());
|
||||
let text = rune::text::TextSystem::new(rune_theme_opencode::FONTS, rune_theme_opencode::FAMILIES);
|
||||
let mut rt = rune::Runtime::with_text(init(), disabled_controls, (1024.0, 640.0),
|
||||
rune::Env { scale: 2.0, system_dark: true }, text);
|
||||
rt.frame(0.0); rt.settle_all(); rt.frame(0.0);
|
||||
assert!(rt.instances.iter().all(|i| i.params[1] != KIND_LAYER && i.params[1] != KIND_LAYER_END));
|
||||
let old = legacy(&rt.instances);
|
||||
let mut renderers = [Renderer::new(&gpu.device, OFFSCREEN_FORMAT), Renderer::new(&gpu.device, OFFSCREEN_FORMAT)];
|
||||
for (renderer, instances) in renderers.iter_mut().zip([&old, &rt.instances]) {
|
||||
rt.text.atlas.dirty = Some((0, rune::text::ATLAS_SIZE));
|
||||
renderer.prepare(&gpu.device, &gpu.queue, &mut rt.text.atlas, instances, (2048, 1280));
|
||||
}
|
||||
assert_eq!(renderers[1].layer_stats().targets, 0, "disabled styling must stay on the direct path");
|
||||
let target = Offscreen::new(&gpu.device, 2048, 1280);
|
||||
for _ in 0..8 {
|
||||
for renderer in &renderers {
|
||||
let mut enc = gpu.device.create_command_encoder(&Default::default());
|
||||
renderer.draw(&mut enc, &target.view, [0.0; 4]);
|
||||
gpu.queue.submit([enc.finish()]);
|
||||
gpu.device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
|
||||
}
|
||||
}
|
||||
const N: u32 = 60;
|
||||
let queries = gpu.device.create_query_set(&wgpu::QuerySetDescriptor { label: None, ty: wgpu::QueryType::Timestamp, count: N * 4 });
|
||||
let resolve = gpu.device.create_buffer(&wgpu::BufferDescriptor { label: None, size: u64::from(N) * 32,
|
||||
usage: wgpu::BufferUsages::QUERY_RESOLVE | wgpu::BufferUsages::COPY_SRC, mapped_at_creation: false });
|
||||
let read = gpu.device.create_buffer(&wgpu::BufferDescriptor { label: None, size: u64::from(N) * 32,
|
||||
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, mapped_at_creation: false });
|
||||
for sample in 0..N {
|
||||
// Alternate paired order to reduce drift; each sample is one completed frame.
|
||||
for offset in 0..2 {
|
||||
let mode = (sample + offset) % 2;
|
||||
let query = sample * 4 + mode * 2;
|
||||
let mut enc = gpu.device.create_command_encoder(&Default::default());
|
||||
renderers[mode as usize].draw_timed(&mut enc, &target.view, [0.0; 4], Some(wgpu::RenderPassTimestampWrites {
|
||||
query_set: &queries, beginning_of_pass_write_index: Some(query), end_of_pass_write_index: Some(query + 1),
|
||||
}));
|
||||
gpu.queue.submit([enc.finish()]);
|
||||
gpu.device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
|
||||
}
|
||||
}
|
||||
let mut enc = gpu.device.create_command_encoder(&Default::default());
|
||||
enc.resolve_query_set(&queries, 0..N * 4, &resolve, 0);
|
||||
enc.copy_buffer_to_buffer(&resolve, 0, &read, 0, u64::from(N) * 32);
|
||||
gpu.queue.submit([enc.finish()]);
|
||||
read.slice(..).map_async(wgpu::MapMode::Read, |r| r.unwrap());
|
||||
gpu.device.poll(wgpu::PollType::wait_indefinitely()).unwrap();
|
||||
let bytes = read.slice(..).get_mapped_range().unwrap();
|
||||
for (mode, name) in ["flat-reference", "disabled-leaves"].into_iter().enumerate() {
|
||||
let mut ms: Vec<f64> = bytes.chunks_exact(32).map(|b| {
|
||||
let b = &b[mode * 16..mode * 16 + 16];
|
||||
let a = u64::from_le_bytes(b[..8].try_into().unwrap());
|
||||
let z = u64::from_le_bytes(b[8..].try_into().unwrap());
|
||||
assert!(z >= a && z != 0);
|
||||
(z - a) as f64 * f64::from(gpu.queue.get_timestamp_period()) / 1e6
|
||||
}).collect();
|
||||
ms.sort_by(f64::total_cmp);
|
||||
eprintln!("disabled-controls {name}: n={N} median={:.6}ms p95={:.6}ms {:?}",
|
||||
ms[N as usize / 2], ms[N as usize * 95 / 100 - 1], renderers[mode].layer_stats());
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
//! The rune-kit gallery: one scene per `@opencode/ui` Storybook story, in the story's id, so
|
||||
//! `scripts/kit-diff.py` can render both and diff them. `--kit neutral` renders the same
|
||||
//! components on Rune's core neutral theme instead of OpenCode's; `--kit palette` on
|
||||
//! `Kit::from_palette` with a near-black, off-white and red seed (a dark palette with a red accent);
|
||||
//! `--kit palette black` (dark) and `--kit palette warm` (light) use pure-black and
|
||||
//! paper seeds with ink focus rings. `--reduced-motion` renders in the runtime's reduced-motion
|
||||
//! mode.
|
||||
//!
|
||||
//! ```sh
|
||||
//! kit-gallery --list-scenes
|
||||
//! kit-gallery --scene ui-button--variants --snap out.png --theme dark --size 720x300
|
||||
//! ```
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
mod stories;
|
||||
|
||||
#[cfg(test)]
|
||||
mod layer_timing;
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use rune::{AppSpec, Cx, El, TextEdit, col};
|
||||
use rune_kit::Kit;
|
||||
|
||||
pub struct G {
|
||||
pub story: &'static str,
|
||||
/// Toggled things by key (switches, checkboxes, expanded items).
|
||||
pub on: HashSet<String>,
|
||||
/// Picked values by group key (radio groups, selects, segmented controls, tabs).
|
||||
pub pick: HashMap<String, String>,
|
||||
/// The open overlay, by key.
|
||||
pub open: Option<String>,
|
||||
pub edits: [TextEdit; 8],
|
||||
pub combo: rune_kit::ComboboxState,
|
||||
/// The file tree story's files.
|
||||
pub files: rune_kit::TreeModel<rune_kit::FileNode<()>>,
|
||||
pub neutral: bool,
|
||||
pub palette: bool,
|
||||
/// `--reduced-motion`: the runtime's reduced-motion mode.
|
||||
pub reduced: bool,
|
||||
}
|
||||
|
||||
impl G {
|
||||
pub fn is(&self, key: &str) -> bool {
|
||||
self.on.contains(key)
|
||||
}
|
||||
pub fn flip(&mut self, key: &str) {
|
||||
if !self.on.remove(key) {
|
||||
self.on.insert(key.to_owned());
|
||||
}
|
||||
}
|
||||
pub fn picked<'a>(&'a self, group: &str, default: &'a str) -> &'a str {
|
||||
self.pick.get(group).map_or(default, String::as_str)
|
||||
}
|
||||
pub fn toggle_open(&mut self, key: &str) {
|
||||
self.open = if self.open.as_deref() == Some(key) { None } else { Some(key.to_owned()) };
|
||||
}
|
||||
}
|
||||
|
||||
fn init() -> G {
|
||||
G {
|
||||
story: "index",
|
||||
on: HashSet::new(),
|
||||
pick: HashMap::new(),
|
||||
open: None,
|
||||
edits: Default::default(),
|
||||
combo: Default::default(),
|
||||
files: files(),
|
||||
neutral: rune::extra_args().iter().any(|a| a == "neutral"),
|
||||
palette: rune::extra_args().iter().any(|a| a == "palette"),
|
||||
reduced: rune::extra_args().iter().any(|a| a == "--reduced-motion"),
|
||||
}
|
||||
}
|
||||
|
||||
/// The acme-web checkout Desktop's Files panel shows, `src/util` open on `format.ts`.
|
||||
fn files() -> rune_kit::TreeModel<rune_kit::FileNode<()>> {
|
||||
let paths = [".git/HEAD", "src/util/format.ts", "src/money.ts", "src/index.ts", "package.json", "README.md"];
|
||||
let mut m = rune_kit::FileTree::new().compact_folders(false).build(paths.map(|p| (p, ())));
|
||||
m.expand_to("src/util/format.ts");
|
||||
m.select("src/util/format.ts");
|
||||
m
|
||||
}
|
||||
|
||||
pub fn kit(s: &G, dark: bool) -> &'static Kit {
|
||||
if s.palette {
|
||||
static D: std::sync::OnceLock<Kit> = std::sync::OnceLock::new();
|
||||
static L: std::sync::OnceLock<Kit> = std::sync::OnceLock::new();
|
||||
let hex = |c: &str| rune::color::hex(c).unwrap();
|
||||
let seed = |bg: &str, fg: &str, accent: &str| rune_kit::PaletteSeed { bg: hex(bg), fg: hex(fg), accent: hex(accent) };
|
||||
// `--kit palette black|warm`: pure-black and paper seeds with ink focus.
|
||||
let variant = |name: &str| rune::extra_args().iter().any(|a| a == name);
|
||||
let ink = |seed| Kit::from_palette_focus(seed, rune_kit::PaletteFocus::Ink);
|
||||
return if dark {
|
||||
D.get_or_init(|| match variant("black") {
|
||||
true => ink(seed("#000000", "#ffffff", "#ff2a2a")),
|
||||
false => Kit::from_palette(seed("#0a0a0a", "#ededed", "#e5484d")),
|
||||
})
|
||||
} else {
|
||||
L.get_or_init(|| match variant("warm") {
|
||||
true => ink(seed("#e8e4dc", "#000000", "#d81414")),
|
||||
false => Kit::from_palette(seed("#ffffff", "#171717", "#e5484d")),
|
||||
})
|
||||
};
|
||||
}
|
||||
if s.neutral {
|
||||
static D: std::sync::OnceLock<Kit> = std::sync::OnceLock::new();
|
||||
static L: std::sync::OnceLock<Kit> = std::sync::OnceLock::new();
|
||||
return if dark { D.get_or_init(|| Kit::neutral(true)) } else { L.get_or_init(|| Kit::neutral(false)) };
|
||||
}
|
||||
rune_theme_opencode::kit(dark)
|
||||
}
|
||||
|
||||
fn view(s: &G, cx: &mut Cx<G>) -> El {
|
||||
if s.reduced {
|
||||
cx.reduced_motion(true);
|
||||
}
|
||||
let k = kit(s, cx.system_dark());
|
||||
let mut overlays = Vec::new();
|
||||
let body = stories::render(s, k, &mut overlays);
|
||||
// Storybook's decorator: the page colour and 24 px of padding around the story.
|
||||
rune_kit::root(col().key("frame").fill(k.c.page).padding(24.0).child(body), overlays)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
rune::run(AppSpec {
|
||||
scenes: stories::SCENES,
|
||||
fonts: rune_theme_opencode::FONTS,
|
||||
families: rune_theme_opencode::FAMILIES,
|
||||
..AppSpec::new("rune-kit gallery", (720.0, 480.0), init, view)
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Every story builds on both appearances of both themes (no GPU needed).
|
||||
#[test]
|
||||
fn every_story_builds() {
|
||||
for (neutral, palette) in [(false, false), (true, false), (false, true)] {
|
||||
for dark in [false, true] {
|
||||
let mut s = init();
|
||||
s.neutral = neutral;
|
||||
s.palette = palette;
|
||||
for (id, setup) in stories::SCENES {
|
||||
setup(&mut s);
|
||||
let k = kit(&s, dark);
|
||||
let mut layer = Vec::new();
|
||||
let _ = stories::render(&s, k, &mut layer);
|
||||
assert_eq!(s.story, *id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+450
@@ -0,0 +1,450 @@
|
||||
//! The stories, one function per `@opencode/ui` Storybook story id (title + export name).
|
||||
//! Layout wrappers copy each story's own inline styles.
|
||||
|
||||
use rune::{Edge, El, Stagger, TextEdit, TextStyle, Transition, Tx, col, el, row, text};
|
||||
use rune_kit::*;
|
||||
use rune_theme_opencode::icons as ic;
|
||||
|
||||
use crate::G;
|
||||
|
||||
mod combobox;
|
||||
mod controls;
|
||||
mod display;
|
||||
mod icons;
|
||||
mod inputs;
|
||||
mod markdown;
|
||||
mod overlays;
|
||||
|
||||
use controls::{button_all_states, button_icon, button_playground, button_sizes, button_variants, checkbox_basic, checkbox_custom_icon, checkbox_hidden_label, checkbox_states, icon_button_all_states, icon_button_playground, icon_button_sizes, icon_button_variants, radio_basic, radio_controlled, radio_states, switch_appearances, switch_basic, switch_hidden_label, switch_sizes, switch_states, switch_web};
|
||||
use display::{accordion_basic, accordion_multiple, accordion_single, badge_accent, badge_appearances, badge_basic, badge_high_contrast, badge_subtle, card_error, card_info, card_normal, card_success, card_warning, collapsible_basic, collapsible_ghost, keybind_all, keybind_multiple, keybind_playground, keybind_symbols, keybind_variants, list_active_icon, list_basic, list_divider, list_empty, list_grouped, list_no_search, list_with_add, loader_basic, loader_sizes, progress_basic, progress_indeterminate, progress_no_label, rolling_text_basic, scroll_view_thumb, segmented_basic, segmented_controlled, spinner_basic, spinner_sizes};
|
||||
use inputs::{field_direct_child, field_invalid, field_text_input, field_textarea, select_disabled, select_grouped, select_invalid, select_playground, select_states, select_with_field, text_input_appearances, text_input_controlled, text_input_copy, text_input_playground, text_input_states, text_input_with_field, textarea_controlled, textarea_playground, textarea_states, textarea_with_field};
|
||||
use markdown::{
|
||||
markdown_basic, markdown_code, markdown_diagrams, markdown_lenient, markdown_mermaid_charts, markdown_mermaid_data, markdown_mermaid_flows, markdown_mermaid_git, markdown_mermaid_hover, markdown_mermaid_maps, markdown_mermaid_plan, markdown_mermaid_plan_zoomed, markdown_mermaid_shapes, markdown_mermaid_streaming, markdown_mermaid_systems, markdown_stream_tail, markdown_streaming, markdown_table_styles,
|
||||
markdown_walkthrough,
|
||||
};
|
||||
use overlays::{hover_card_basic, menu_appearances, menu_basic, menu_checkbox, menu_radio, menu_rich, menu_submenu, popover_basic, popover_controlled, toast_all, tooltip_keybind, tooltip_path, tooltip_simple, tooltip_title_description};
|
||||
|
||||
type Story = fn(&G, &Kit, &mut Vec<El>) -> El;
|
||||
|
||||
macro_rules! stories {
|
||||
($($id:literal => $f:path,)*) => {
|
||||
pub const STORIES: &[(&str, Story)] = &[$(($id, $f),)*];
|
||||
pub const SCENES: &[(&str, fn(&mut G))] = &[$(($id, |s: &mut G| {
|
||||
s.story = $id;
|
||||
s.combo = ComboboxState::default();
|
||||
if $id.starts_with("rune-combobox--") { let _ = s.combo.step(ComboboxEvent::Toggle { current: None }); }
|
||||
if $id == "rune-popup-list--composer" {
|
||||
s.edits[7] = TextEdit::new("/");
|
||||
s.edits[7].focused = true;
|
||||
}
|
||||
s.open = OPENED.iter().find(|(id, _)| *id == $id).map(|(_, k)| (*k).to_owned());
|
||||
}),)*];
|
||||
};
|
||||
}
|
||||
|
||||
/// Stories whose web version opens an overlay (by default or through the harness's click):
|
||||
/// their scene starts with that overlay open.
|
||||
const OPENED: &[(&str, &str)] = &[
|
||||
("ui-dialog--basic", "dialog"),
|
||||
("rune-dialog--fit", "dialog-fit"),
|
||||
("rune-popup-list--composer", "popup-list"),
|
||||
("ui-menu--basic", "menu"),
|
||||
("ui-menu--rich", "menu"),
|
||||
("ui-menu--with-checkbox", "menu"),
|
||||
("ui-menu--with-radio", "menu"),
|
||||
("ui-menu--with-submenu", "menu"),
|
||||
("ui-menu--appearances", "both"),
|
||||
("ui-select--playground", "select"),
|
||||
("ui-select--grouped", "select"),
|
||||
("rune-select--states", "select"),
|
||||
("components-popover--basic", "popover"),
|
||||
("components-popover--controlled", "popover"),
|
||||
("components-hover-card--basic", "card"),
|
||||
("ui-tooltip--simple", "tip"),
|
||||
("ui-tooltip--with-keybind", "tip"),
|
||||
("ui-tooltip--path", "tip"),
|
||||
("ui-tooltip--title-description", "tip"),
|
||||
("ui-toast--all-examples", "toast"),
|
||||
];
|
||||
|
||||
fn is_open(s: &G, key: &str) -> bool {
|
||||
s.open.as_deref() == Some(key) || s.open.as_deref() == Some("both")
|
||||
}
|
||||
|
||||
fn toggle(key: &'static str) -> impl Fn(&mut G) + Clone {
|
||||
move |s: &mut G| s.toggle_open(key)
|
||||
}
|
||||
|
||||
fn close(s: &mut G) {
|
||||
s.open = None;
|
||||
}
|
||||
|
||||
fn flip(key: &'static str) -> impl Fn(&mut G) {
|
||||
move |s: &mut G| s.flip(key)
|
||||
}
|
||||
|
||||
stories! {
|
||||
"rune-combobox--searchable" => combobox::searchable,
|
||||
"rune-combobox--animated-filter" => combobox::animated_filter,
|
||||
"ui-dialog--basic" => dialog_basic,
|
||||
"motion-focus-modal" => motion_focus_modal,
|
||||
"motion-stagger-list" => motion_stagger_list,
|
||||
"ui-button--playground" => button_playground,
|
||||
"ui-button--variants" => button_variants,
|
||||
"ui-button--sizes" => button_sizes,
|
||||
"ui-button--icon" => button_icon,
|
||||
"ui-button--all-states" => button_all_states,
|
||||
"ui-icon-button--playground" => icon_button_playground,
|
||||
"ui-icon-button--variants" => icon_button_variants,
|
||||
"ui-icon-button--sizes" => icon_button_sizes,
|
||||
"ui-icon-button--all-states" => icon_button_all_states,
|
||||
"ui-switch--basic" => switch_basic,
|
||||
"ui-switch--appearances" => switch_appearances,
|
||||
"ui-switch--states" => switch_states,
|
||||
"ui-switch--hidden-label" => switch_hidden_label,
|
||||
"rune-switch--web" => switch_web,
|
||||
"ui-checkbox--basic" => checkbox_basic,
|
||||
"ui-checkbox--states" => checkbox_states,
|
||||
"ui-checkbox--custom-icon" => checkbox_custom_icon,
|
||||
"ui-checkbox--hidden-label" => checkbox_hidden_label,
|
||||
"ui-radio--basic" => radio_basic,
|
||||
"ui-radio--controlled" => radio_controlled,
|
||||
"ui-radio--states" => radio_states,
|
||||
"ui-text-input--playground" => text_input_playground,
|
||||
"ui-text-input--with-copy-button" => text_input_copy,
|
||||
"ui-text-input--controlled" => text_input_controlled,
|
||||
"ui-text-input--appearances" => text_input_appearances,
|
||||
"ui-text-input--with-field" => text_input_with_field,
|
||||
"ui-text-input--states" => text_input_states,
|
||||
"ui-textarea--playground" => textarea_playground,
|
||||
"ui-textarea--controlled" => textarea_controlled,
|
||||
"ui-textarea--with-field" => textarea_with_field,
|
||||
"ui-textarea--states" => textarea_states,
|
||||
"ui-field--text-input-example" => field_text_input,
|
||||
"ui-field--text-input-direct-child" => field_direct_child,
|
||||
"ui-field--textarea-example" => field_textarea,
|
||||
"ui-field--invalid" => field_invalid,
|
||||
"ui-select--playground" => select_playground,
|
||||
"ui-select--grouped" => select_grouped,
|
||||
"ui-select--invalid" => select_invalid,
|
||||
"ui-select--disabled" => select_disabled,
|
||||
"ui-select--with-field" => select_with_field,
|
||||
"rune-select--states" => select_states,
|
||||
"components-popover--basic" => popover_basic,
|
||||
"components-popover--controlled" => popover_controlled,
|
||||
"ui-menu--basic" => menu_basic,
|
||||
"ui-menu--appearances" => menu_appearances,
|
||||
"ui-menu--rich" => menu_rich,
|
||||
"ui-menu--with-checkbox" => menu_checkbox,
|
||||
"ui-menu--with-radio" => menu_radio,
|
||||
"ui-menu--with-submenu" => menu_submenu,
|
||||
"ui-tooltip--simple" => tooltip_simple,
|
||||
"ui-tooltip--with-keybind" => tooltip_keybind,
|
||||
"ui-tooltip--path" => tooltip_path,
|
||||
"ui-tooltip--title-description" => tooltip_title_description,
|
||||
"components-hover-card--basic" => hover_card_basic,
|
||||
"ui-toast--all-examples" => toast_all,
|
||||
"components-card--normal" => card_normal,
|
||||
"components-card--error" => card_error,
|
||||
"components-card--warning" => card_warning,
|
||||
"components-card--success" => card_success,
|
||||
"components-card--info" => card_info,
|
||||
"components-list--basic" => list_basic,
|
||||
"components-list--grouped" => list_grouped,
|
||||
"components-list--empty" => list_empty,
|
||||
"components-list--with-add" => list_with_add,
|
||||
"components-list--divider" => list_divider,
|
||||
"components-list--active-icon" => list_active_icon,
|
||||
"components-list--no-search" => list_no_search,
|
||||
"ui-accordion--basic" => accordion_basic,
|
||||
"ui-accordion--multiple" => accordion_multiple,
|
||||
"ui-accordion--non-collapsible" => accordion_single,
|
||||
"components-collapsible--basic" => collapsible_basic,
|
||||
"components-collapsible--ghost" => collapsible_ghost,
|
||||
"ui-badge--basic" => badge_basic,
|
||||
"ui-badge--appearances" => badge_appearances,
|
||||
"ui-badge--subtle" => badge_subtle,
|
||||
"ui-badge--high-contrast" => badge_high_contrast,
|
||||
"ui-badge--accent" => badge_accent,
|
||||
"ui-keybind--playground" => keybind_playground,
|
||||
"ui-keybind--variants" => keybind_variants,
|
||||
"ui-keybind--multiple-keys" => keybind_multiple,
|
||||
"ui-keybind--all-examples" => keybind_all,
|
||||
"components-spinner--basic" => spinner_basic,
|
||||
"components-spinner--sizes" => spinner_sizes,
|
||||
"ui-loader--basic" => loader_basic,
|
||||
"ui-loader--sizes" => loader_sizes,
|
||||
"components-progress--basic" => progress_basic,
|
||||
"components-progress--no-label" => progress_no_label,
|
||||
"components-progress--indeterminate" => progress_indeterminate,
|
||||
"ui-segmented-control--basic" => segmented_basic,
|
||||
"ui-segmented-control--controlled" => segmented_controlled,
|
||||
"rune-keybind--symbols" => keybind_symbols,
|
||||
"rune-switch--sizes" => switch_sizes,
|
||||
"rune-scroll-view--thumb" => scroll_view_thumb,
|
||||
"rune-rolling-text--basic" => rolling_text_basic,
|
||||
"rune-markdown--basic" => markdown_basic,
|
||||
"rune-markdown--streaming" => markdown_streaming,
|
||||
"rune-markdown--stream-tail" => markdown_stream_tail,
|
||||
"rune-markdown--walkthrough" => markdown_walkthrough,
|
||||
"rune-markdown--diagrams" => markdown_diagrams,
|
||||
"rune-markdown--lenient" => markdown_lenient,
|
||||
"rune-markdown--mermaid-shapes" => markdown_mermaid_shapes,
|
||||
"rune-markdown--mermaid-charts" => markdown_mermaid_charts,
|
||||
"rune-markdown--mermaid-maps" => markdown_mermaid_maps,
|
||||
"rune-markdown--mermaid-git" => markdown_mermaid_git,
|
||||
"rune-markdown--mermaid-data" => markdown_mermaid_data,
|
||||
"rune-markdown--mermaid-systems" => markdown_mermaid_systems,
|
||||
"rune-markdown--mermaid-flows" => markdown_mermaid_flows,
|
||||
"rune-markdown--mermaid-hover" => markdown_mermaid_hover,
|
||||
"rune-markdown--mermaid-streaming" => markdown_mermaid_streaming,
|
||||
"rune-markdown--mermaid-plan" => markdown_mermaid_plan,
|
||||
"rune-markdown--mermaid-plan-zoomed" => markdown_mermaid_plan_zoomed,
|
||||
"rune-markdown--table-styles" => markdown_table_styles,
|
||||
"rune-markdown--code" => markdown_code,
|
||||
"rune-text--selectable-help" => text_selectable_help,
|
||||
"rune-text--truncate-middle" => text_truncate_middle,
|
||||
"rune-dialog--fit" => dialog_fit,
|
||||
"rune-popup-list--composer" => popup_list_composer,
|
||||
"rune-scroll-bar--basic" => scroll_bar_basic,
|
||||
"rune-scroll-bar--grow" => scroll_bar_grow,
|
||||
"components-file-icon--samples" => icons::file_icon_samples,
|
||||
"components-file-icon--folder" => icons::file_icon_folder,
|
||||
"ui-icon--gallery" => icons::icon_gallery,
|
||||
"rune-icon--catalog" => icons::icon_catalog,
|
||||
"rune-file-icon--catalog" => icons::file_icon_catalog,
|
||||
"rune-tree-icon--catalog" => icons::tree_icon_catalog,
|
||||
"rune-tree--files" => icons::file_tree,
|
||||
}
|
||||
|
||||
fn popup_list_composer(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let entries = [
|
||||
("review", "/review", "Review branch changes", &glyphs::SPARKLE, "⏎", false),
|
||||
("compact", "/compact", "Summarize the conversation", &glyphs::FILE_TEXT, "⌘K", false),
|
||||
("search", "/search", "Search workspace files", k.glyph.search, "⌘P", false),
|
||||
("share", "/share", "Create a read-only link", k.glyph.lock, "", true),
|
||||
];
|
||||
let q = s.edits[7].text.trim_start_matches('/').to_lowercase();
|
||||
let filtered: Vec<_> = entries.into_iter().filter(|(_, label, desc, ..)| {
|
||||
q.is_empty() || label.to_lowercase().contains(&q) || desc.to_lowercase().contains(&q)
|
||||
}).collect();
|
||||
let count = filtered.len();
|
||||
let active = s.pick.get("popup-list").and_then(|v| v.parse::<usize>().ok()).unwrap_or(0).min(count.saturating_sub(1));
|
||||
let items = filtered.into_iter().map(|(id, label, desc, glyph, hint, disabled)| {
|
||||
let mut item = PopupItem::new(id, label)
|
||||
.description(desc)
|
||||
.leading(rune::icon(glyph, 14.0).color(k.c.icon_muted))
|
||||
.disabled(disabled);
|
||||
if !hint.is_empty() {
|
||||
item = item.trailing(text(hint).font(k.ty.small_medium).color(k.c.text_faint));
|
||||
}
|
||||
item
|
||||
});
|
||||
PopupList::new("popup-list", "composer")
|
||||
.open(is_open(s, "popup-list"))
|
||||
.width(320.0)
|
||||
.items(items)
|
||||
.active((count > 0).then_some(active))
|
||||
.on_active(|s: &mut G, i| { s.pick.insert("popup-list".into(), i.to_string()); })
|
||||
.on_choose(|s: &mut G, id, _| {
|
||||
s.edits[7] = TextEdit::new(format!("/{id} "));
|
||||
s.edits[7].focused = true;
|
||||
s.open = None;
|
||||
})
|
||||
.build(k, layer);
|
||||
TextInput::new(&s.edits[7])
|
||||
.width(Some(320.0))
|
||||
.placeholder("Type / for commands or @ to mention…")
|
||||
.animate_edit_layout()
|
||||
.on_edit(|s: &mut G| &mut s.edits[7])
|
||||
.on_change(|s: &mut G, _| { s.open = Some("popup-list".into()); s.pick.insert("popup-list".into(), "0".into()); })
|
||||
.build(k)
|
||||
.key("composer")
|
||||
}
|
||||
|
||||
fn dialog_basic(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
Dialog::new("dialog", "Dialog").description("Description").open(is_open(s, "dialog"))
|
||||
.on_close(close).child(body_text(k, "Dialog body content.")).build(k, layer);
|
||||
Button::new("Open dialog").on_press(toggle("dialog")).build(k).key("opener")
|
||||
}
|
||||
|
||||
fn dialog_fit(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let actions = row().w_full().padding(16.0).gap(8.0).justify_end()
|
||||
.child(Button::new("Cancel").variant(ButtonVariant::Ghost).on_press(close).build(k))
|
||||
.child(Button::new("Delete").on_press(close).build(k));
|
||||
Dialog::new("dialog-fit", "Delete item?").description("This cannot be undone.").width(400.0).fit()
|
||||
.open(is_open(s, "dialog-fit")).on_close(close).child(actions).build(k, layer);
|
||||
Button::new("Open confirmation").on_press(toggle("dialog-fit")).build(k).key("opener")
|
||||
}
|
||||
|
||||
fn motion_focus_modal(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
Dialog::new("dialog", "Loading").open(is_open(s, "dialog")).on_close(close)
|
||||
.child(row().gap(16.0).child(Spinner::new().build(k).key("spinner"))
|
||||
.child(Loader::new().build(k).key("loader")))
|
||||
.child(Button::new("Done").on_press(close).build(k).key("done")).build(k, layer);
|
||||
col().gap(16.0)
|
||||
.child(Button::new("Open dialog").on_press(toggle("dialog")).build(k).key("opener"))
|
||||
.child(Switch::new(s.is("switch")).label("Sync").on_toggle(|s: &mut G| s.flip("switch")).build(k).key("switch"))
|
||||
.child(Checkbox::new(s.is("check")).label("Remember").on_toggle(|s: &mut G| s.flip("check")).build(k).key("check"))
|
||||
.child(SegmentedControl::new(&["First", "Second"], Some(if s.is("second") { 1 } else { 0 }))
|
||||
.on_pick(|s: &mut G, i, _| { if s.is("second") != (i == 1) { s.flip("second"); } }).build(k))
|
||||
}
|
||||
|
||||
/// Five rows that rise and fade in one after another (`El::enter_delay` with a `Stagger`) and
|
||||
/// leave together.
|
||||
fn motion_stagger_list(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
const ROWS: [&str; 5] = ["Inbox", "Drafts", "Sent", "Archive", "Trash"];
|
||||
let stagger = Stagger::new(0.05);
|
||||
let rows = ROWS.iter().enumerate().filter(|_| s.is("rows")).map(|(i, label)| {
|
||||
row().key(*label).w(240.0).h(36.0).px(12.0).center_y().fill(k.c.surface_base).radius(k.radius.md)
|
||||
.child(text(*label).font(k.ty.ui).color(k.c.text_base))
|
||||
.transition(Transition::offset(0.0, 12.0).combined(Transition::opacity()))
|
||||
.enter_delay(stagger.delay(i, ROWS.len()))
|
||||
});
|
||||
col().gap(8.0)
|
||||
.child(Button::new("Show rows").on_press(|s: &mut G| s.flip("rows")).build(k).key("opener"))
|
||||
.child(col().key("rows").gap(4.0).children(rows))
|
||||
}
|
||||
|
||||
pub fn render(s: &G, k: &Kit, overlays: &mut Vec<El>) -> El {
|
||||
match STORIES.iter().find(|(id, _)| *id == s.story) {
|
||||
Some((_, f)) => f(s, k, overlays),
|
||||
None => index(s, k, overlays),
|
||||
}
|
||||
}
|
||||
|
||||
/// Every story stacked, for browsing in a window.
|
||||
fn index(s: &G, k: &Kit, overlays: &mut Vec<El>) -> El {
|
||||
let mut c = col().key("index").gap(24.0);
|
||||
for (id, f) in STORIES {
|
||||
c = c.child(col().key(*id).gap(8.0).child(caption(k, id)).child(f(s, k, overlays)));
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
/// The stories' `font-size: 12px; color: var(--text-weak)` labels (line height inherited).
|
||||
fn caption(k: &Kit, label: &str) -> El {
|
||||
text(label).font(TextStyle::new(12.0, 440.0).lh(24.0)).color(k.c.text_weak)
|
||||
}
|
||||
|
||||
/// `display: flex; gap; align-items: center; flex-wrap: wrap`.
|
||||
fn flex(gap: f32) -> El {
|
||||
row().gap(gap).center_y().flex_wrap()
|
||||
}
|
||||
|
||||
/// CSS `text-transform: capitalize`: the first letter of every word (hyphens split words).
|
||||
fn title_case(s: &str) -> String {
|
||||
let mut out = String::new();
|
||||
let mut start = true;
|
||||
for ch in s.chars() {
|
||||
if start {
|
||||
out.extend(ch.to_uppercase())
|
||||
} else {
|
||||
out.push(ch)
|
||||
}
|
||||
start = !ch.is_alphanumeric();
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The stories' own `toTitleCase`: only the first letter.
|
||||
fn cap_first(s: &str) -> String {
|
||||
let mut c = s.chars();
|
||||
c.next().map(|f| f.to_uppercase().collect::<String>() + c.as_str()).unwrap_or_default()
|
||||
}
|
||||
|
||||
const STATES: [(&str, State); 5] = [
|
||||
("default", State::Rest),
|
||||
("hover", State::Hover),
|
||||
("pressed", State::Pressed),
|
||||
("focus", State::Focus),
|
||||
("disabled", State::Disabled),
|
||||
];
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Selectable text and help
|
||||
|
||||
const SERVE: &str = "opencode serve --port 4096 --hostname 0.0.0.0";
|
||||
|
||||
/// A settings row: a command people can select and copy, highlighted as the kit's fields
|
||||
/// highlight a selection, and an icon-only copy button that explains itself on hover.
|
||||
fn text_selectable_help(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let c = &k.c;
|
||||
col().w(480.0).gap(8.0)
|
||||
.child(caption(k, "Run the server from a terminal"))
|
||||
.child(
|
||||
row().key("command-row").h(36.0).pl(12.0).pr(4.0).gap(8.0).center_y()
|
||||
.fill(c.surface_base).radius(k.radius.md).border(1.0, c.border_weak)
|
||||
.child(text(SERVE).key("command").font(k.ty.mono).color(c.text_base).grow(1.0).shrink()
|
||||
.selectable(true).selection_color(k.selection()))
|
||||
.child(IconButton::new(&ic::COPY).variant(IconButtonVariant::Ghost).control_size(ControlSize::Small)
|
||||
.label("Copy command").on_press_tx(|_: &mut G, tx: &mut Tx| tx.copy(SERVE)).build(k)
|
||||
.key("copy").help("Copy command")),
|
||||
)
|
||||
.child(row().w(280.0).child(TextInput::new(&s.edits[7]).placeholder("Selected like a field")
|
||||
.on_edit(|s: &mut G| &mut s.edits[7]).build(k).key("field")))
|
||||
}
|
||||
|
||||
const LONG_PATH: &str = "~/Projects/rune/crates/rune-kit/src/components/settings/appearance_panel.rs";
|
||||
|
||||
/// A path keeps its folder and file name as its box narrows, beside the end and head cuts, each
|
||||
/// with a `Type::caption` line under it.
|
||||
fn text_truncate_middle(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let c = &k.c;
|
||||
let path = |w: f32, cut: fn(El) -> El, how: &str| col().w(w)
|
||||
.child(cut(text(LONG_PATH).font(k.ty.ui).color(c.text_base)).selectable(true).selection_color(k.selection()))
|
||||
.child(text(format!("{how}, {w} pt")).font(k.ty.caption()).color(c.text_weak));
|
||||
col().gap(12.0)
|
||||
.child(path(360.0, El::truncate_middle, "Middle"))
|
||||
.child(path(240.0, El::truncate_middle, "Middle"))
|
||||
.child(path(160.0, El::truncate_middle, "Middle"))
|
||||
.child(path(240.0, El::truncate, "End"))
|
||||
.child(path(240.0, El::truncate_head, "Head"))
|
||||
}
|
||||
|
||||
fn scroll_bar_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
scroll_feed(k, 24, None)
|
||||
}
|
||||
|
||||
/// A feed whose button lengthens or shortens what follows its rows, so its thumb glides to each
|
||||
/// new length.
|
||||
fn scroll_bar_grow(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col().gap(8.0)
|
||||
.child(Button::new("Change rows").on_press(flip("more")).build(k).key("more"))
|
||||
.child(scroll_feed(k, 12, Some(if s.is("more") { 600.0 } else { 0.0 })))
|
||||
}
|
||||
|
||||
fn scroll_feed(k: &Kit, rows: usize, tail: Option<f32>) -> El {
|
||||
col()
|
||||
.key("panel")
|
||||
.w(360.0)
|
||||
.h(260.0)
|
||||
.radius(k.radius.md)
|
||||
.fill(k.c.layer_01)
|
||||
.border(1.0, k.c.border_weak)
|
||||
.clip_soft(k.radius.md)
|
||||
.child(
|
||||
col()
|
||||
.key("feed")
|
||||
.w_full()
|
||||
.grow(1.0)
|
||||
.min_h(0.0)
|
||||
.padding(8.0)
|
||||
.gap(4.0)
|
||||
.scroll(rune::ScrollSpec { stick_bottom: false })
|
||||
.children((0..rows).map(|i| {
|
||||
row()
|
||||
.key(format!("item-{i}"))
|
||||
.w_full()
|
||||
.h(32.0)
|
||||
.px(10.0)
|
||||
.center_y()
|
||||
.justify_between()
|
||||
.radius(k.radius.sm)
|
||||
.child(text(format!("Build step {:02}", i + 1)).font(k.ty.ui_compact).color(k.c.text_base))
|
||||
.child(text(format!("{} ms", 12 + i * 7)).font(k.ty.small).color(k.c.text_muted))
|
||||
}))
|
||||
.children(tail.map(|h| el().key("tail").w_full().h(h)))
|
||||
.scroll_bar(k),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//! Rune's own combobox scenes; there is no Storybook story to match.
|
||||
|
||||
use rune::El;
|
||||
use rune_kit::{Combobox, ComboboxOption, Kit};
|
||||
|
||||
use crate::G;
|
||||
|
||||
pub(super) fn searchable(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
models(s, false).build(k, layer)
|
||||
}
|
||||
|
||||
/// The same list, crossfading each keystroke's rows and springing the popover's height.
|
||||
pub(super) fn animated_filter(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
models(s, true).build(k, layer)
|
||||
}
|
||||
|
||||
fn models(s: &G, animate: bool) -> Combobox<G> {
|
||||
let options: Vec<_> = (0..200).map(|i| ComboboxOption::new(format!("model-{i}"), format!("Model {i:03}"))).collect();
|
||||
Combobox::new("model", &s.combo, &options, |s: &mut G| &mut s.combo)
|
||||
.label("Model").placeholder("Choose model").current(s.pick.get("model").map(String::as_str))
|
||||
.animate_filtering(animate)
|
||||
.on_choose(|s, id, _| { s.pick.insert("model".into(), id.into()); })
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
//! Button, IconButton, Switch, Checkbox and Radio.
|
||||
|
||||
use super::*;
|
||||
|
||||
// Button
|
||||
|
||||
pub(super) fn button_playground(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Button::new("Button").build(k))
|
||||
}
|
||||
|
||||
pub(super) fn button_variants(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
use ButtonVariant::*;
|
||||
flex(12.0)
|
||||
.child(Button::new("Neutral").variant(Neutral).build(k))
|
||||
.child(Button::new("Danger").variant(Danger).build(k))
|
||||
.child(Button::new("Warning").variant(Warning).build(k))
|
||||
.child(Button::new("Contrast").variant(Contrast).build(k))
|
||||
.child(Button::new("Submit").variant(Submit).build(k))
|
||||
.child(Button::new("Ghost").variant(Ghost).build(k))
|
||||
.child(Button::new("Ghost muted").variant(GhostMuted).icon(&ic::EDIT).build(k))
|
||||
.child(Button::new("Ghost faint").variant(GhostFaint).icon(&ic::EDIT).build(k))
|
||||
.child(Button::new("Loading").variant(Loading).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn button_sizes(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
flex(12.0)
|
||||
.child(Button::new("Mini").control_size(ControlSize::Mini).build(k))
|
||||
.child(Button::new("Small").control_size(ControlSize::Small).build(k))
|
||||
.child(Button::new("Regular").build(k))
|
||||
.child(Button::new("Large").control_size(ControlSize::Large).build(k))
|
||||
.child(Button::new("Extra large").control_size(ControlSize::ExtraLarge).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn button_icon(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
flex(12.0)
|
||||
.child(Button::new("Regular").icon(&ic::PLUS).build(k))
|
||||
.child(Button::new("Large").variant(ButtonVariant::Contrast).control_size(ControlSize::Large).icon(&ic::PLUS).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn button_all_states(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
use ButtonVariant::*;
|
||||
let variants = [
|
||||
("neutral", Neutral),
|
||||
("danger", Danger),
|
||||
("warning", Warning),
|
||||
("contrast", Contrast),
|
||||
("submit", Submit),
|
||||
("ghost", Ghost),
|
||||
("ghost-muted", GhostMuted),
|
||||
("ghost-faint", GhostFaint),
|
||||
("loading", Loading),
|
||||
];
|
||||
let mut c = col().gap(12.0);
|
||||
for (name, v) in variants {
|
||||
let mut r = row().gap(8.0).flex_wrap();
|
||||
for (state, st) in STATES {
|
||||
r = r.child(Button::new(cap_first(state)).variant(v).state(st).build(k).key(format!("{name}-{state}")));
|
||||
}
|
||||
c = c.child(col().gap(8.0).child(caption(k, &title_case(name))).child(r));
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
// IconButton
|
||||
|
||||
pub(super) fn icon_button_playground(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(IconButton::new(&ic::PLUS).label("Add").build(k))
|
||||
}
|
||||
|
||||
pub(super) fn icon_button_variants(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
use IconButtonVariant::*;
|
||||
flex(12.0)
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").variant(Neutral).build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").variant(Contrast).build(k))
|
||||
.child(IconButton::new(&ic::ARROW_UP).label("Send").variant(Submit).build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").variant(Ghost).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn icon_button_sizes(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
flex(12.0)
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").control_size(ControlSize::Mini).build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").control_size(ControlSize::Small).build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").control_size(ControlSize::Large).build(k))
|
||||
.child(IconButton::new(&ic::PLUS).label("Add").control_size(ControlSize::ExtraLarge).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn icon_button_all_states(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
use IconButtonVariant::*;
|
||||
let variants = [("neutral", Neutral), ("contrast", Contrast), ("submit", Submit), ("ghost", Ghost)];
|
||||
let mut c = col().gap(12.0);
|
||||
for (name, v) in variants {
|
||||
let mut r = row().gap(8.0).flex_wrap();
|
||||
for (state, st) in STATES {
|
||||
r = r.child(IconButton::new(&ic::PLUS).label("Add").variant(v).state(st).build(k).key(format!("{name}-{state}")));
|
||||
}
|
||||
c = c.child(col().gap(8.0).child(caption(k, &title_case(name))).child(r));
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
// Switch
|
||||
|
||||
/// `defaultChecked` items read as on until toggled.
|
||||
fn on_by_default(s: &G, key: &str) -> bool {
|
||||
!s.is(key)
|
||||
}
|
||||
|
||||
pub(super) fn switch_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Switch::new(on_by_default(s, "sw")).label("Enable notifications").on_toggle(flip("sw")).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn switch_appearances(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col()
|
||||
.gap(12.0)
|
||||
.child(Switch::new(on_by_default(s, "std")).label("Standard").standard().on_toggle(flip("std")).build(k))
|
||||
.child(Switch::new(on_by_default(s, "cmp")).label("Compact").on_toggle(flip("cmp")).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn switch_states(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col()
|
||||
.gap(12.0)
|
||||
.child(Switch::new(on_by_default(s, "a")).label("Enabled").on_toggle(flip("a")).build(k))
|
||||
.child(Switch::new(s.is("b")).label("Disabled").on_toggle(flip("b")).build(k))
|
||||
.child(Switch::new(false).label("Disabled switch").disabled(true).build(k))
|
||||
}
|
||||
|
||||
/// Every control size off, on, hovered and pressed.
|
||||
pub(super) fn switch_sizes(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let sizes = [("Mini", ControlSize::Mini), ("Small", ControlSize::Small), ("Regular", ControlSize::Regular),
|
||||
("Large", ControlSize::Large), ("Extra large", ControlSize::ExtraLarge)];
|
||||
col().gap(12.0).children(sizes.into_iter().map(|(name, size)| {
|
||||
let key = format!("size-{name}");
|
||||
let sw = |on: bool, st: State| Switch::new(on).control_size(size).state(st).build(k);
|
||||
row().gap(12.0).center_y()
|
||||
.child(caption(k, name).w(80.0))
|
||||
.child(Switch::new(s.is(&key)).control_size(size).label(name).hide_label().on_toggle(move |s: &mut G| s.flip(&key)).build(k))
|
||||
.child(sw(true, State::Rest))
|
||||
.child(sw(false, State::Hover))
|
||||
.child(sw(true, State::Pressed))
|
||||
}))
|
||||
}
|
||||
|
||||
/// The compact switch as the web draws it (`Switch::web`): off and on, at rest, hovered,
|
||||
/// keyboard-focused and disabled.
|
||||
pub(super) fn switch_web(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let states = [("Rest", State::Rest), ("Hover", State::Hover), ("Focus", State::Focus), ("Disabled", State::Disabled)];
|
||||
col().gap(12.0)
|
||||
.child(row().gap(12.0).center_y().child(caption(k, "Live").w(80.0))
|
||||
.child(Switch::new(s.is("web")).web().label("Web").hide_label().on_toggle(flip("web")).build(k)))
|
||||
.children(states.into_iter().map(|(name, st)| {
|
||||
row().gap(16.0).center_y()
|
||||
.child(caption(k, name).w(80.0))
|
||||
.child(Switch::new(false).web().state(st).build(k))
|
||||
.child(Switch::new(true).web().state(st).build(k))
|
||||
}))
|
||||
}
|
||||
|
||||
pub(super) fn switch_hidden_label(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Switch::new(on_by_default(s, "sw")).label("Hidden label").hide_label().on_toggle(flip("sw")).build(k))
|
||||
}
|
||||
|
||||
// Checkbox
|
||||
|
||||
pub(super) fn checkbox_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Checkbox::new(on_by_default(s, "cb")).label("Checkbox").on_toggle(flip("cb")).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn checkbox_states(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col()
|
||||
.gap(12.0)
|
||||
.child(Checkbox::new(on_by_default(s, "a")).label("Checked").on_toggle(flip("a")).build(k))
|
||||
.child(Checkbox::new(s.is("b")).label("Unchecked").on_toggle(flip("b")).build(k))
|
||||
.child(Checkbox::new(false).label("Disabled").disabled(true).build(k))
|
||||
.child(
|
||||
Checkbox::new(s.is("d")).label("With description").description("Helper text").on_toggle(flip("d")).build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn checkbox_custom_icon(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(
|
||||
Checkbox::new(on_by_default(s, "cb")).label("Custom icon").icon(&ic::CHECK).on_toggle(flip("cb")).build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn checkbox_hidden_label(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Checkbox::new(s.is("cb")).label("Hidden label").hide_label().on_toggle(flip("cb")).build(k))
|
||||
}
|
||||
|
||||
// Radio
|
||||
|
||||
fn radio_group(
|
||||
s: &G,
|
||||
group: &'static str,
|
||||
default: &str,
|
||||
label: &str,
|
||||
items: &[(&'static str, &str, Option<&str>)],
|
||||
) -> RadioGroup {
|
||||
let current = s.picked(group, default).to_owned();
|
||||
let mut g = RadioGroup::new().label(label);
|
||||
for (value, l, d) in items {
|
||||
let v = *value;
|
||||
let mut item = RadioItem::new(*l, current == v).on_select(move |s: &mut G| {
|
||||
s.pick.insert(group.to_owned(), v.to_owned());
|
||||
});
|
||||
if let Some(d) = d {
|
||||
item = item.description(*d);
|
||||
}
|
||||
g = g.item(item);
|
||||
}
|
||||
g
|
||||
}
|
||||
|
||||
pub(super) fn radio_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
radio_group(
|
||||
s,
|
||||
"freq",
|
||||
"daily",
|
||||
"Notification frequency",
|
||||
&[
|
||||
("daily", "Daily", Some("Once per day at 9am.")),
|
||||
("weekly", "Weekly", Some("Every Monday morning.")),
|
||||
("never", "Never", Some("No notifications.")),
|
||||
],
|
||||
)
|
||||
.build(k)
|
||||
}
|
||||
|
||||
pub(super) fn radio_controlled(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let v = s.picked("ctl", "daily").to_owned();
|
||||
col()
|
||||
.gap(12.0)
|
||||
.child(
|
||||
radio_group(
|
||||
s,
|
||||
"ctl",
|
||||
"daily",
|
||||
"Controlled",
|
||||
&[("daily", "Daily", None), ("weekly", "Weekly", None), ("never", "Never", None)],
|
||||
)
|
||||
.build(k),
|
||||
)
|
||||
.child(text(format!("Value: {v}")).font(TextStyle::new(12.0, 440.0).lh(24.0)).color(k.c.text_faint))
|
||||
}
|
||||
|
||||
pub(super) fn radio_states(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let disabled_item = RadioGroup::new()
|
||||
.label("Disabled item")
|
||||
.item(RadioItem::new("Enabled", s.picked("di", "a") == "a").on_select(|s: &mut G| {
|
||||
s.pick.insert("di".into(), "a".into());
|
||||
}))
|
||||
.item(RadioItem::new("Disabled", false).disabled(true));
|
||||
col()
|
||||
.gap(20.0)
|
||||
.child(
|
||||
radio_group(
|
||||
s,
|
||||
"def",
|
||||
"a",
|
||||
"Default",
|
||||
&[("a", "Option A", None), ("b", "Option B", Some("Has a description."))],
|
||||
)
|
||||
.build(k),
|
||||
)
|
||||
.child(
|
||||
RadioGroup::new()
|
||||
.label("Disabled group")
|
||||
.disabled(true)
|
||||
.item(RadioItem::new("Option A", true))
|
||||
.item(RadioItem::new("Option B", false))
|
||||
.build(k),
|
||||
)
|
||||
.child(disabled_item.build(k))
|
||||
.child(
|
||||
radio_group(s, "inv", "a", "Invalid", &[("a", "Option A", None), ("b", "Option B", None)])
|
||||
.description("Pick one option.")
|
||||
.invalid(true)
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
//! Card, List, Accordion, Collapsible, Badge, Keybind, Spinner, Loader, Progress and SegmentedControl.
|
||||
|
||||
use super::*;
|
||||
|
||||
// Card, List, Accordion, Collapsible
|
||||
|
||||
fn card(k: &Kit, accent: Option<rune::Color>, icon: Option<&'static rune::Icon>) -> El {
|
||||
let mut c = Card::new()
|
||||
.title("Card title", icon)
|
||||
.description("Small supporting text.")
|
||||
.action(Button::new("Action").build(k));
|
||||
if let Some(a) = accent {
|
||||
c = c.accent(a);
|
||||
}
|
||||
c.build(k)
|
||||
}
|
||||
|
||||
pub(super) fn card_normal(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
card(k, None, None)
|
||||
}
|
||||
pub(super) fn card_error(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
card(k, Some(k.c.danger.icon), Some(&ic::CIRCLE_BAN_SIGN_BOLD))
|
||||
}
|
||||
pub(super) fn card_warning(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
card(k, Some(k.c.warning.icon), Some(&ic::WARNING_BOLD))
|
||||
}
|
||||
pub(super) fn card_success(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
card(k, Some(k.c.success.icon), Some(&ic::CIRCLE_CHECK_BOLD))
|
||||
}
|
||||
pub(super) fn card_info(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
card(k, Some(k.c.info.icon), Some(&ic::HELP_BOLD))
|
||||
}
|
||||
|
||||
fn list(s: &G, items: &[&str], search: bool) -> List {
|
||||
let mut l = List::new();
|
||||
if search {
|
||||
l = l.search(&s.edits[3], "").on_search_edit(|s: &mut G| &mut s.edits[3]);
|
||||
}
|
||||
for i in items {
|
||||
l = l.item(ListItem::new(*i));
|
||||
}
|
||||
l
|
||||
}
|
||||
|
||||
pub(super) fn list_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &["One", "Two", "Three", "Four"], true).build(k)
|
||||
}
|
||||
pub(super) fn list_grouped(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
List::new()
|
||||
.search(&s.edits[3], "")
|
||||
.item(ListItem::new("Alpha").group("Group A"))
|
||||
.item(ListItem::new("Bravo").group("Group A"))
|
||||
.item(ListItem::new("Delta").group("Group B"))
|
||||
.build(k)
|
||||
}
|
||||
pub(super) fn list_empty(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &[], true).build(k)
|
||||
}
|
||||
pub(super) fn list_with_add(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &["One", "Two"], true)
|
||||
.add_row(
|
||||
row()
|
||||
.px(8.0)
|
||||
.py(6.0)
|
||||
.child(text("Add item").font(TextStyle::new(14.0, 500.0).lh(21.0)).color(k.c.text_strong)),
|
||||
)
|
||||
.build(k)
|
||||
}
|
||||
pub(super) fn list_divider(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &["One", "Two", "Three"], false).divider().build(k)
|
||||
}
|
||||
pub(super) fn list_active_icon(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &["Alpha", "Beta", "Gamma"], false).active_icon(&ic::CHEVRON_RIGHT).build(k)
|
||||
}
|
||||
pub(super) fn list_no_search(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
list(s, &["One", "Two", "Three"], false).build(k)
|
||||
}
|
||||
|
||||
fn accordion_content(k: &Kit, s: &str, padded: bool) -> El {
|
||||
let t = text(s).font(TextStyle::new(13.0, 440.0).lh(24.0));
|
||||
if padded { row().py(8.0).child(t.color(k.c.text_weak)) } else { row().child(t.color(k.c.std_text)) }
|
||||
}
|
||||
|
||||
/// The web story's `value="first"` arrives as a control arg and renders closed; so does this.
|
||||
pub(super) fn accordion_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let open = s.picked("acc", "").to_owned();
|
||||
let pick = |v: &'static str| {
|
||||
move |s: &mut G| {
|
||||
let cur = s.picked("acc", "").to_owned();
|
||||
s.pick.insert("acc".into(), if cur == v { String::new() } else { v.into() });
|
||||
}
|
||||
};
|
||||
col().w(420.0).gap(8.0).child(
|
||||
Accordion::new()
|
||||
.item(
|
||||
AccordionItem::new("First")
|
||||
.expanded(open == "first")
|
||||
.child(accordion_content(k, "Accordion content.", true))
|
||||
.on_toggle(pick("first")),
|
||||
)
|
||||
.item(
|
||||
AccordionItem::new("Second")
|
||||
.expanded(open == "second")
|
||||
.child(accordion_content(k, "More content.", true))
|
||||
.on_toggle(pick("second")),
|
||||
)
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn accordion_multiple(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Accordion::new()
|
||||
.item(
|
||||
AccordionItem::new("First")
|
||||
.expanded(!s.is("a1"))
|
||||
.child(accordion_content(k, "Accordion content.", false))
|
||||
.on_toggle(flip("a1")),
|
||||
)
|
||||
.item(
|
||||
AccordionItem::new("Second")
|
||||
.expanded(!s.is("a2"))
|
||||
.child(accordion_content(k, "More content.", false))
|
||||
.on_toggle(flip("a2")),
|
||||
)
|
||||
.build(k)
|
||||
}
|
||||
|
||||
/// The web story passes `value="first"` without `multiple` or `collapsible` and renders closed.
|
||||
pub(super) fn accordion_single(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Accordion::new()
|
||||
.item(AccordionItem::new("First").expanded(false).child(accordion_content(k, "Accordion content.", false)))
|
||||
.build(k)
|
||||
}
|
||||
|
||||
pub(super) fn collapsible_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Collapsible::new("Details", !s.is("c"))
|
||||
.child(
|
||||
row().pt(8.0).child(
|
||||
text("Optional details sit here.").font(TextStyle::new(13.0, 440.0).lh(24.0)).color(k.c.text_weak),
|
||||
),
|
||||
)
|
||||
.on_toggle(flip("c"))
|
||||
.build(k)
|
||||
}
|
||||
|
||||
pub(super) fn collapsible_ghost(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Collapsible::new("Ghost trigger", s.is("c"))
|
||||
.ghost()
|
||||
.child(
|
||||
row().pt(8.0).child(text("Ghost content.").font(TextStyle::new(13.0, 440.0).lh(24.0)).color(k.c.text_weak)),
|
||||
)
|
||||
.on_toggle(flip("c"))
|
||||
.build(k)
|
||||
}
|
||||
|
||||
// Badge, Keybind, Spinner, Loader, Progress, SegmentedControl
|
||||
|
||||
pub(super) fn badge_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Badge::new("Label").build(k))
|
||||
}
|
||||
pub(super) fn badge_appearances(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().gap(8.0).center_y().child(Badge::new("Standard").standard().build(k)).child(Badge::new("Compact").build(k))
|
||||
}
|
||||
pub(super) fn badge_subtle(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row()
|
||||
.gap(8.0)
|
||||
.center_y()
|
||||
.child(Badge::new("1").variant(BadgeVariant::Subtle).build(k))
|
||||
.child(Badge::new("12").variant(BadgeVariant::Subtle).build(k))
|
||||
}
|
||||
pub(super) fn badge_high_contrast(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().gap(8.0).center_y().child(Badge::new("Label").build(k)).child(Badge::new("Label").high_contrast().build(k))
|
||||
}
|
||||
pub(super) fn badge_accent(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Badge::new("New").variant(BadgeVariant::Accent).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn keybind_playground(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Keybind::new(&["⌘"]).build(k))
|
||||
}
|
||||
pub(super) fn keybind_variants(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row()
|
||||
.gap(24.0)
|
||||
.center_y()
|
||||
.child(Keybind::new(&["⌘"]).build(k))
|
||||
.child(Keybind::new(&["⌘"]).variant(KeybindVariant::Ghost).build(k))
|
||||
}
|
||||
pub(super) fn keybind_multiple(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row()
|
||||
.gap(24.0)
|
||||
.center_y()
|
||||
.child(Keybind::new(&["⌘", "K"]).build(k))
|
||||
.child(Keybind::new(&["⌘", "K"]).variant(KeybindVariant::Ghost).build(k))
|
||||
.child(Keybind::new(&["Ctrl", "B"]).build(k))
|
||||
.child(Keybind::new(&["Ctrl", "B"]).variant(KeybindVariant::Ghost).build(k))
|
||||
}
|
||||
pub(super) fn keybind_all(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let line = |name: &str, v: KeybindVariant| {
|
||||
row()
|
||||
.gap(24.0)
|
||||
.center_y()
|
||||
.child(
|
||||
text(name)
|
||||
.w(50.0)
|
||||
.font(TextStyle::new(11.0, 440.0).lh(24.0))
|
||||
.color(rune::theme::hex("#808080").unwrap_or_default()),
|
||||
)
|
||||
.child(Keybind::new(&["⌘"]).variant(v).build(k))
|
||||
.child(Keybind::new(&["⌘", "K"]).variant(v).build(k))
|
||||
.child(Keybind::new(&["⌘", "⇧", "P"]).variant(v).build(k))
|
||||
.child(Keybind::new(&["Ctrl", "Shift", "B"]).variant(v).build(k))
|
||||
};
|
||||
col().gap(16.0).child(line("Neutral", KeybindVariant::Neutral)).child(line("Ghost", KeybindVariant::Ghost))
|
||||
}
|
||||
|
||||
/// Keyboard symbols next to capitals, in both families at 13 and 15 pt, then keycaps.
|
||||
pub(super) fn keybind_symbols(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
const SAMPLE: &str = "⌘K ⇧P ⏎ ⌫ ⎋ ⌥⌃ ←↑ HP";
|
||||
let mut c = col().gap(10.0);
|
||||
for mono in [false, true] {
|
||||
for size in [13.0, 15.0] {
|
||||
let font = TextStyle::new(size, 500.0).lh(size * 1.5);
|
||||
let font = if mono { font.mono() } else { font };
|
||||
let label = format!("{} {size}", if mono { "Plex Mono" } else { "Inter" });
|
||||
c = c.child(
|
||||
row()
|
||||
.gap(16.0)
|
||||
.center_y()
|
||||
.child(text(label).w(96.0).font(TextStyle::new(11.0, 440.0).lh(16.0)).color(k.c.text_faint))
|
||||
.child(text(SAMPLE).font(font).color(k.c.text_base)),
|
||||
);
|
||||
}
|
||||
let mut kk = k.clone();
|
||||
if mono {
|
||||
kk.ty.small_medium = kk.ty.small_medium.mono();
|
||||
}
|
||||
let mut caps = row().gap(12.0).center_y().child(
|
||||
text(if mono { "Plex Mono caps" } else { "Inter caps" })
|
||||
.w(96.0)
|
||||
.font(TextStyle::new(11.0, 440.0).lh(16.0))
|
||||
.color(k.c.text_faint),
|
||||
);
|
||||
let sets: [&[&str]; 6] = [&["⌘", "⇧", "P"], &["⇧", "⏎"], &["⌫"], &["⎋"], &["⌥", "⌃", "K"], &["←", "↑"]];
|
||||
for keys in sets {
|
||||
caps = caps.child(Keybind::new(keys).build(&kk));
|
||||
}
|
||||
c = c.child(caps);
|
||||
}
|
||||
c
|
||||
}
|
||||
|
||||
pub(super) fn spinner_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Spinner::new().build(k))
|
||||
}
|
||||
pub(super) fn spinner_sizes(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row()
|
||||
.gap(16.0)
|
||||
.center_y()
|
||||
.child(Spinner::new().size(12.0).build(k))
|
||||
.child(Spinner::new().size(20.0).build(k))
|
||||
.child(Spinner::new().size(28.0).build(k))
|
||||
}
|
||||
pub(super) fn loader_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(Loader::new().build(k))
|
||||
}
|
||||
pub(super) fn loader_sizes(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row()
|
||||
.gap(16.0)
|
||||
.center_y()
|
||||
.child(Loader::new().size(12.0).build(k))
|
||||
.child(Loader::new().build(k))
|
||||
.child(Loader::new().size(24.0).build(k))
|
||||
}
|
||||
pub(super) fn progress_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Progress::new(Some(0.6)).label("Progress").show_value().build(k)
|
||||
}
|
||||
pub(super) fn progress_no_label(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Progress::new(Some(0.3)).build(k)
|
||||
}
|
||||
pub(super) fn progress_indeterminate(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
Progress::new(None).label("Loading").build(k)
|
||||
}
|
||||
|
||||
pub(super) fn segmented_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let sel = s.picked("seg", "0").parse().unwrap_or(0);
|
||||
row().child(
|
||||
SegmentedControl::new(&["Label", "Label", "Label", "Label"], Some(sel))
|
||||
.on_pick(|s: &mut G, i: usize, _: &mut Tx| {
|
||||
s.pick.insert("seg".into(), i.to_string());
|
||||
})
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
pub(super) fn segmented_controlled(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let sel: usize = s.picked("seg", "1").parse().unwrap_or(1);
|
||||
col()
|
||||
.gap(12.0)
|
||||
.items_start()
|
||||
.child(
|
||||
SegmentedControl::new(&["List", "Grid", "Board"], Some(sel))
|
||||
.label("View")
|
||||
.on_pick(|s: &mut G, i: usize, _: &mut Tx| {
|
||||
s.pick.insert("seg".into(), i.to_string());
|
||||
})
|
||||
.build(k),
|
||||
)
|
||||
.child(
|
||||
text(format!("Value: {}", ["a", "b", "c"][sel.min(2)]))
|
||||
.font(TextStyle::new(12.0, 440.0).lh(24.0))
|
||||
.color(rune::theme::hex("#808080").unwrap_or_default()),
|
||||
)
|
||||
}
|
||||
|
||||
/// A copy label and countdown, sans and mono. Each press of "Roll" advances one step:
|
||||
/// "Copy password" → "Copied, clears in 0:30" → "… 0:29", and the countdown "0:30" → "0:29" → ….
|
||||
pub(super) fn rolling_text_basic(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let step: u32 = s.picked("roll", "0").parse().unwrap_or(0);
|
||||
let label = if step == 0 { "Copy password".to_owned() } else { format!("Copied, clears in 0:{:02}", 31 - step.min(31)) };
|
||||
let count = format!("0:{:02}", 30 - step.min(30));
|
||||
let big = TextStyle::new(28.0, 600.0);
|
||||
let line = |name: &str, e: El| row().gap(12.0).center_y().child(text(name).font(k.ty.small).color(k.c.text_faint).w(56.0)).child(e);
|
||||
col()
|
||||
.gap(14.0)
|
||||
.child(
|
||||
row()
|
||||
.gap(8.0)
|
||||
.child(
|
||||
Button::new("Roll")
|
||||
.on_press(|s: &mut G| {
|
||||
let n: u32 = s.picked("roll", "0").parse().unwrap_or(0);
|
||||
s.pick.insert("roll".into(), (n + 1).to_string());
|
||||
})
|
||||
.build(k)
|
||||
.key("roll"),
|
||||
)
|
||||
.child(Button::new(label.clone()).rolling("roll-button").build(k).key("rolling-button"))
|
||||
.child(Button::new("Cancel").build(k).key("cancel")),
|
||||
)
|
||||
.child(line("Sans", RollingText::new("roll-sans", label.clone()).font(k.ty.body).build(k)))
|
||||
.child(line("Mono", RollingText::new("roll-mono", label.clone()).font(k.ty.mono).build(k)))
|
||||
.child(line("Centred", row().w(260.0).center().child(RollingText::new("roll-centre", label).font(k.ty.body).build(k))))
|
||||
.child(line("Count", RollingText::new("count-sans", count.clone()).font(big).from(Edge::Top).build(k)))
|
||||
.child(line("", RollingText::new("count-mono", count).font(big.mono()).from(Edge::Top).build(k)))
|
||||
}
|
||||
|
||||
/// `ScrollBarStyle::scroll_view`: the `@opencode/ui` ScrollView thumb, hidden at rest and shown while
|
||||
/// the pointer is over the list or it scrolls.
|
||||
pub(super) fn scroll_view_thumb(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let rows = (1..=24).map(|i| row().key(format!("row{i}")).h(28.0).px(12.0).center_y()
|
||||
.child(text(format!("Row {i}")).font(k.ty.ui_compact).color(k.c.text_base)));
|
||||
col().key("list").w(240.0).h(180.0).radius(k.radius.md).fill(k.c.bg_base).border(1.0, k.c.border_weak)
|
||||
.scroll(rune::ScrollSpec { stick_bottom: false })
|
||||
.child(col().children(rows))
|
||||
.scroll_bar_styled(ScrollBarStyle::scroll_view(k))
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
//! FileIcon and Icon, as `file-icon.stories.tsx` and `icon.stories.tsx` lay them out, and Rune's own
|
||||
//! catalogs of every OpenCode icon, file-type badge and file tree icon, and its file tree.
|
||||
|
||||
use rune::icon;
|
||||
use rune_theme_opencode::{file_icons, tree_icons};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// `display: grid; grid-template-columns: repeat(auto-fill, minmax(min, 1fr)); gap` at the
|
||||
/// story's 672-point width.
|
||||
fn grid(min: f32, gap: f32, cells: Vec<El>) -> El {
|
||||
let columns = ((672.0 + gap) / (min + gap)).floor().max(1.0) as usize;
|
||||
let width = (672.0 - gap * (columns - 1) as f32) / columns as f32;
|
||||
let mut rows = col().gap(gap);
|
||||
let mut cells = cells.into_iter().peekable();
|
||||
while cells.peek().is_some() {
|
||||
rows = rows.child(row().gap(gap).children(cells.by_ref().take(columns).map(|c| c.w(width))));
|
||||
}
|
||||
rows
|
||||
}
|
||||
|
||||
/// The stories' `font-size: 12px; color: var(--text-weak)` names.
|
||||
fn name(k: &Kit, label: &str) -> El {
|
||||
text(label).font(TextStyle::new(12.0, 440.0).lh(18.0)).color(k.c.text_weak).truncate()
|
||||
}
|
||||
|
||||
pub(super) fn file_icon_samples(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let items = [
|
||||
("README.md", false),
|
||||
("package.json", false),
|
||||
("tsconfig.json", false),
|
||||
("index.ts", false),
|
||||
("styles.css", false),
|
||||
("logo.svg", false),
|
||||
("photo.png", false),
|
||||
("Dockerfile", false),
|
||||
(".env", false),
|
||||
("src", true),
|
||||
("public", true),
|
||||
];
|
||||
let cells = items
|
||||
.iter()
|
||||
.map(|&(path, dir)| {
|
||||
let glyph = if dir { file_icons::folder(path, false) } else { file_icons::file(path) };
|
||||
row().gap(8.0).center_y().child(icon(glyph, 16.0).color(k.c.text_base)).child(name(k, path))
|
||||
})
|
||||
.collect();
|
||||
grid(120.0, 12.0, cells)
|
||||
}
|
||||
|
||||
pub(super) fn file_icon_folder(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(icon(file_icons::folder("src", true), 16.0).color(k.c.text_base))
|
||||
}
|
||||
|
||||
pub(super) fn icon_gallery(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let names = [
|
||||
"archive", "arrow-left", "arrow-right", "arrow-up-right", "branch", "check", "chevron-down", "close", "code-slash", "edit",
|
||||
"folder", "graduation-cap", "help", "magnifying-glass", "menu", "monitor", "outline-arrow-to-corner-top-right",
|
||||
"outline-copy", "outline-dots", "outline-eye", "outline-eye-slash", "outline-hexagonal-warning", "plus", "review",
|
||||
"settings-gear", "trash", "workspace",
|
||||
];
|
||||
// A name the catalog lacks draws `plus`, as `Icon` does.
|
||||
let find = |n: &str| ic::ALL.iter().copied().find(|i| i.name == n).unwrap_or(&ic::PLUS);
|
||||
let cells = names
|
||||
.iter()
|
||||
.map(|n| {
|
||||
col().gap(6.0).items_center().child(icon(find(n), 16.0).color(k.c.icon_base)).child(
|
||||
text(*n).font(TextStyle::new(10.0, 440.0).lh(15.0)).color(k.c.text_weak).truncate(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
grid((672.0 - 48.0) / 5.0, 12.0, cells)
|
||||
}
|
||||
|
||||
/// Every icon in OpenCode's catalog, by name.
|
||||
pub(super) fn icon_catalog(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let cells = ic::ALL
|
||||
.iter()
|
||||
.map(|i| row().gap(8.0).center_y().child(icon(i, 16.0).color(k.c.icon_base)).child(name(k, i.name)))
|
||||
.collect();
|
||||
grid(128.0, 8.0, cells)
|
||||
}
|
||||
|
||||
/// Every FileIcon badge and folder icon.
|
||||
pub(super) fn file_icon_catalog(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let cells = file_icons::all().iter().map(|i| row().gap(8.0).center_y().child(icon(i, 16.0).color(k.c.text_base)).child(name(k, i.name))).collect();
|
||||
grid(128.0, 8.0, cells)
|
||||
}
|
||||
|
||||
/// Every file tree icon, at rest in `icon-muted` and in its type's colour as a selected row draws it.
|
||||
pub(super) fn tree_icon_catalog(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let muted = rune_theme_opencode::theme(k.dark).color("v2-icon-icon-muted");
|
||||
let cells = tree_icons::all()
|
||||
.map(|t| {
|
||||
row()
|
||||
.gap(6.0)
|
||||
.center_y()
|
||||
.child(icon(t.icon(), 16.0).color(muted))
|
||||
.child(icon(t.icon(), 16.0).color(t.color(k.dark)))
|
||||
.child(name(k, t.token()))
|
||||
})
|
||||
.collect();
|
||||
grid(128.0, 8.0, cells)
|
||||
}
|
||||
|
||||
/// Desktop's file tree: folders show only a chevron, files their type's icon, coloured on the
|
||||
/// selected row.
|
||||
pub(super) fn file_tree(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let dark = k.dark;
|
||||
let tree = Tree::new(|s: &G| &s.files, |s: &mut G| &mut s.files, FileNode::label)
|
||||
.row(move |n, r| tree_icons::item(&n.name, &n.path, n.dir, r.selected, dark))
|
||||
.style(tree_icons::style(k))
|
||||
.name("Files")
|
||||
.build(s, k)
|
||||
.h(8.0 * 28.0 + 8.0);
|
||||
// The tree's scroller: 4 points above the rows and 8 either side (`TREE_UNSAFE_CSS`).
|
||||
col().w(240.0).fill(k.c.bg_base).pt(4.0).px(8.0).child(tree)
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
//! TextInput, Textarea, Field and Select.
|
||||
|
||||
use super::*;
|
||||
|
||||
// TextInput, Textarea, Field
|
||||
//
|
||||
// Solid passes `defaultValue` to these inputs as an attribute the DOM ignores, so the web
|
||||
// stories show their placeholders; the gallery does the same.
|
||||
|
||||
fn edit(v: &str) -> TextEdit {
|
||||
TextEdit::new(v)
|
||||
}
|
||||
|
||||
fn grid(gap: f32, width: f32) -> El {
|
||||
col().gap(gap).w(width).items_stretch()
|
||||
}
|
||||
|
||||
pub(super) fn text_input_playground(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(TextInput::new(&s.edits[0]).placeholder("Placeholder").on_edit(|s: &mut G| &mut s.edits[0]).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn text_input_copy(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(TextInput::new(&edit("")).placeholder("api.example.com/v1").copy_button().build(k))
|
||||
}
|
||||
|
||||
pub(super) fn text_input_controlled(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let value = if s.edits[1].text.is_empty() && !s.is("typed") {
|
||||
"Controlled value".to_owned()
|
||||
} else {
|
||||
s.edits[1].text.clone()
|
||||
};
|
||||
col()
|
||||
.gap(12.0)
|
||||
.child(TextInput::new(&edit(&value)).placeholder("Type here…").build(k))
|
||||
.child(text(format!("Value: {value}")).font(TextStyle::new(12.0, 440.0).lh(24.0)).color(k.c.std_text))
|
||||
}
|
||||
|
||||
pub(super) fn text_input_appearances(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(20.0, 280.0)
|
||||
.child(TextInput::new(&edit("")).placeholder("Base (28px)").build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("Large (32px)").large().build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("Large with copy").large().copy_button().build(k))
|
||||
}
|
||||
|
||||
pub(super) fn text_input_with_field(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(24.0, 280.0)
|
||||
.child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.info()
|
||||
.prefix("Prefix")
|
||||
.control(TextInput::new(&edit("")).placeholder("Text").copy_button().build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
.child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.prefix("Prefix")
|
||||
.control(TextInput::new(&edit("")).placeholder("Text").copy_button().invalid(true).build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn text_input_states(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(20.0, 280.0)
|
||||
.child(TextInput::new(&edit("")).placeholder("Default").build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("With value").build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("With copy").copy_button().build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("Invalid").invalid(true).copy_button().build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("Disabled").disabled(true).build(k))
|
||||
.child(TextInput::new(&edit("")).placeholder("Disabled with value").disabled(true).copy_button().build(k))
|
||||
}
|
||||
|
||||
pub(super) fn textarea_playground(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
row().child(TextArea::new(&s.edits[2]).placeholder("Placeholder").on_edit(|s: &mut G| &mut s.edits[2]).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn textarea_controlled(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(12.0, 280.0)
|
||||
.child(TextArea::new(&edit("")).placeholder("Type here…").build(k))
|
||||
.child(text("Value: Controlled value").font(TextStyle::new(12.0, 440.0).lh(24.0)).color(k.c.std_text))
|
||||
}
|
||||
|
||||
pub(super) fn textarea_with_field(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(24.0, 280.0)
|
||||
.child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.info()
|
||||
.prefix("Prefix")
|
||||
.control(TextArea::new(&edit("")).placeholder("Text").build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
.child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.prefix("Prefix")
|
||||
.control(TextArea::new(&edit("")).placeholder("Text").invalid(true).build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn textarea_states(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(20.0, 280.0)
|
||||
.child(TextArea::new(&edit("")).placeholder("Default").build(k))
|
||||
.child(TextArea::new(&edit("")).placeholder("With value").build(k))
|
||||
.child(TextArea::new(&edit("")).placeholder("Invalid").invalid(true).build(k))
|
||||
.child(TextArea::new(&edit("")).placeholder("Disabled").disabled(true).build(k))
|
||||
.child(TextArea::new(&edit("")).placeholder("Disabled with value").disabled(true).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn field_text_input(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(0.0, 280.0).child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.info()
|
||||
.prefix("Prefix")
|
||||
.control(TextInput::new(&edit("")).placeholder("Text").copy_button().build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn field_direct_child(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(0.0, 280.0).child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.prefix("Prefix")
|
||||
.control(TextInput::new(&edit("")).placeholder("Text").build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn field_textarea(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(0.0, 280.0).child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.prefix("Prefix")
|
||||
.control(TextArea::new(&edit("")).placeholder("Text").build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn field_invalid(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
grid(0.0, 280.0).child(
|
||||
Field::new()
|
||||
.label("Label")
|
||||
.prefix("Prefix")
|
||||
.control(TextInput::new(&edit("")).placeholder("Text").copy_button().invalid(true).build(k))
|
||||
.suffix("Suffix")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
|
||||
// Select
|
||||
|
||||
const FRUITS: [&str; 5] = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];
|
||||
|
||||
fn fruit_select(s: &G, key: &'static str) -> Select {
|
||||
let current = s.pick.get(key).cloned();
|
||||
Select::new(key, &FRUITS)
|
||||
.label("Fruit")
|
||||
.placeholder("Pick a fruit")
|
||||
.current(current.as_deref())
|
||||
.open(is_open(s, key))
|
||||
.on_toggle(toggle(key))
|
||||
.on_close(close)
|
||||
.on_choose(move |s: &mut G, v: &str, _: &mut Tx| {
|
||||
s.pick.insert(key.to_owned(), v.to_owned());
|
||||
s.open = None;
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn select_playground(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(fruit_select(s, "select").build(k, layer))
|
||||
}
|
||||
|
||||
pub(super) fn select_grouped(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let cities =
|
||||
[("North", "Boston"), ("South", "Miami"), ("South", "Atlanta"), ("West", "Seattle"), ("West", "Denver")];
|
||||
let current = s.pick.get("select").cloned();
|
||||
row().child(
|
||||
Select::grouped("select", &cities)
|
||||
.label("City")
|
||||
.placeholder("Pick a fruit")
|
||||
.current(current.as_deref())
|
||||
.open(is_open(s, "select"))
|
||||
.on_toggle(toggle("select"))
|
||||
.on_close(close)
|
||||
.on_choose(|s: &mut G, v: &str, _: &mut Tx| {
|
||||
s.pick.insert("select".into(), v.to_owned());
|
||||
s.open = None;
|
||||
})
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn select_invalid(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(fruit_select(s, "select").invalid(true).build(k, layer))
|
||||
}
|
||||
|
||||
pub(super) fn select_disabled(_: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(Select::new("select", &FRUITS).current(Some("Cherry")).disabled(true).build(k, layer))
|
||||
}
|
||||
|
||||
/// Both triggers in every state, forced, and an open field with its listbox: the inline trigger's
|
||||
/// rest, hover, open and disabled; the 280 x 28 field's rest, hover, keyboard focus, open,
|
||||
/// invalid and disabled.
|
||||
pub(super) fn select_states(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let pick = |key: &'static str, st: State| Select::new(key, &FRUITS).label("Fruit").placeholder("Pick a fruit").current(Some("Banana")).state(st);
|
||||
let line = |name: &str, e: El| row().gap(16.0).center_y().child(text(name.to_owned()).font(k.ty.small).color(k.c.text_faint).w(72.0)).child(e);
|
||||
let field = |key: &'static str, st: State| pick(key, st).appearance(SelectAppearance::Field);
|
||||
col().gap(10.0)
|
||||
.child(line("Inline", pick("i1", State::Rest).trigger(k)))
|
||||
.child(line("Hover", pick("i2", State::Hover).trigger(k)))
|
||||
.child(line("Open", pick("i3", State::Rest).open(true).trigger(k)))
|
||||
.child(line("Disabled", pick("i4", State::Rest).disabled(true).trigger(k)))
|
||||
.child(line("Field", field("f1", State::Rest).trigger(k)))
|
||||
.child(line("Hover", field("f2", State::Hover).trigger(k)))
|
||||
.child(line("Focus", field("f3", State::Focus).trigger(k)))
|
||||
.child(line("Invalid", field("f4", State::Rest).invalid(true).trigger(k)))
|
||||
.child(line("Disabled", field("f5", State::Rest).disabled(true).trigger(k)))
|
||||
.child(line("Open", fruit_select(s, "select").appearance(SelectAppearance::Field).build(k, layer)))
|
||||
}
|
||||
|
||||
pub(super) fn select_with_field(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
grid(0.0, 280.0).child(
|
||||
Field::new()
|
||||
.label("Fruit")
|
||||
.info()
|
||||
.prefix("Optional helper")
|
||||
.control(fruit_select(s, "select").build(k, layer))
|
||||
.suffix("After selection")
|
||||
.build(k),
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
//! Markdown.
|
||||
|
||||
use super::*;
|
||||
|
||||
const MARKDOWN: &str = "# Rune markdown\n\nParagraphs take **strong**, *emphasis*, `inline code` and [links](https://rune.dev). \
|
||||
Links are styled now and become clickable with rich-text spans.\n\n## Lists\n\n- First item\n- Second item with `code`\n\n\
|
||||
1. One\n2. Two\n\n### Quote and rule\n\n> Quoted text sits behind a rule.\n\n---\n\n#### A muted heading\n\n```rust\nfn main() {\n println!(\"hello\");\n}\n```\n";
|
||||
|
||||
pub(super) fn markdown_basic(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col().w(560.0).child(Markdown::new(MARKDOWN).on_link(|_: &mut G, _| {}).build(k))
|
||||
}
|
||||
|
||||
/// Tables, diffs and diagrams: what an agent's answer about a code change looks like.
|
||||
const WALKTHROUGH: &str = r#"## Retry with backoff
|
||||
|
||||
The client now retries failed requests with **exponential backoff**, capped at `max_delay`.
|
||||
|
||||
| Attempt | Delay | Jitter | Notes |
|
||||
|:--------|------:|:------:|-------|
|
||||
| 1 | 0 ms | none | first try |
|
||||
| 2 | 200 ms | ±20% | after a `503` |
|
||||
| 3 | 400 ms | ±20% | |
|
||||
| 4 | 800 ms | ±20% | gives up after this one and reports the **last** error |
|
||||
|
||||
```diff
|
||||
@@ -12,7 +12,9 @@ impl Client {
|
||||
pub async fn send(&self, req: Request) -> Result<Response> {
|
||||
- self.inner.send(req).await
|
||||
+ retry(self.policy, || self.inner.send(req.clone()))
|
||||
+ .await
|
||||
+ .map_err(Error::from)
|
||||
}
|
||||
```
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[Request] --> B{Status?}
|
||||
B -->|2xx| C([Done])
|
||||
B -->|503| D[Wait backoff]
|
||||
D --> E[(Retry budget)]
|
||||
E -.->|left| A
|
||||
E -->|spent| F[Report error]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
autonumber
|
||||
actor U as User
|
||||
participant C as Client
|
||||
participant S as Server
|
||||
U->>+C: send(req)
|
||||
loop until success or budget spent
|
||||
C->>S: POST /items
|
||||
S--xC: 503 Unavailable
|
||||
Note right of S: overloaded
|
||||
end
|
||||
C-->>-U: Err(last error)
|
||||
```
|
||||
"#;
|
||||
|
||||
/// Subgraphs, every node shape, a left-to-right chart that fits, a pie chart, and an unsupported
|
||||
/// diagram.
|
||||
const DIAGRAMS: &str = r#"```mermaid
|
||||
graph TD
|
||||
subgraph client [Client]
|
||||
UI[Web app] --> Cache[(Local cache)]
|
||||
end
|
||||
subgraph edge [Edge]
|
||||
LB{{Load balancer}} --> W1[Worker 1] & W2[Worker 2]
|
||||
end
|
||||
UI ==> LB
|
||||
W1 --> DB[(Postgres)]
|
||||
W2 --> DB
|
||||
W2 -.-> Q>Queue]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
a([Stadium]) --> b[[Subroutine]] --> c((Circle)) --o d{Diamond}
|
||||
d --x e[/Lean/] <--> f[/Trapezoid\]
|
||||
```
|
||||
|
||||
| Narrow | Table |
|
||||
|---|---|
|
||||
| wraps | when its column runs out of room, like this long cell does |
|
||||
|
||||
```mermaid
|
||||
pie title Pets
|
||||
"Dogs" : 386
|
||||
"Cats" : 85
|
||||
```
|
||||
|
||||
```mermaid
|
||||
kanban
|
||||
Todo
|
||||
Write docs
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_diagrams(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col().w(520.0).child(Markdown::new(DIAGRAMS).build(k))
|
||||
}
|
||||
|
||||
/// What the lenient parser reads: an unclosed `[/…` label is a plain rectangle, a line that doesn't
|
||||
/// read is skipped; plus a class diagram and sequence `box` groups with a `rect` band.
|
||||
const LENIENT: &str = r#"```mermaid
|
||||
flowchart LR
|
||||
A[List + count] --> B[/items split view]
|
||||
B --> C[Details]
|
||||
C --> D[Pause / Resume / Delete]
|
||||
C -- --> D
|
||||
```
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
a[setting.some_name] --> b[run_* + /go]
|
||||
c[(store -> row)] --> d[Item.Worker]
|
||||
d --> e[/api/v2/item]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
direction LR
|
||||
class Shape {
|
||||
<<trait>>
|
||||
+area() f32
|
||||
}
|
||||
class Circle {
|
||||
+radius f32
|
||||
}
|
||||
class Canvas {
|
||||
+shapes Vec~Shape~
|
||||
+draw()
|
||||
}
|
||||
Shape <|.. Circle
|
||||
Canvas o-- "many" Shape : holds
|
||||
```
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
box Front
|
||||
actor U as User
|
||||
participant A as App
|
||||
end
|
||||
box Back
|
||||
participant S as Server
|
||||
end
|
||||
U->>A: open list
|
||||
rect rgb(80, 140, 220)
|
||||
A->>+S: fetch items
|
||||
S-->>-A: 20 items
|
||||
end
|
||||
A-->>U: show list
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_lenient(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(LENIENT).style(style).build(k))
|
||||
}
|
||||
|
||||
/// Every Mermaid v11 flowchart shape, four to a row.
|
||||
const SHAPES: &str = r#"```mermaid
|
||||
flowchart LR
|
||||
a1[rect] ~~~ a2(rounded) ~~~ a3([stadium]) ~~~ a4[[subproc]]
|
||||
b1[(cyl)] ~~~ b2((circle)) ~~~ b3(((dbl-circ))) ~~~ b4>odd]
|
||||
c1{diam} ~~~ c2{{hex}} ~~~ c3[/lean-r/] ~~~ c4[\lean-l\]
|
||||
d1[/trap-b\] ~~~ d2[\trap-t/] ~~~ d3@{ shape: bang, label: "bang" } ~~~ d4@{ shape: cloud, label: "cloud" }
|
||||
e1@{ shape: notch-rect, label: "card" } ~~~ e2@{ shape: hourglass, label: "collate" } ~~~ e3@{ shape: bolt, label: "com-link" } ~~~ e4@{ shape: delay, label: "delay" }
|
||||
f1@{ shape: brace, label: "comment" } ~~~ f2@{ shape: brace-r, label: "brace-r" } ~~~ f3@{ shape: braces, label: "braces" } ~~~ f4@{ shape: text, label: "text" }
|
||||
g1@{ shape: h-cyl, label: "h-cyl" } ~~~ g2@{ shape: lin-cyl, label: "lin-cyl" } ~~~ g3@{ shape: curv-trap, label: "display" } ~~~ g4@{ shape: div-rect, label: "div-rect" }
|
||||
h1@{ shape: doc, label: "doc" } ~~~ h2@{ shape: lin-doc, label: "lin-doc" } ~~~ h3@{ shape: docs, label: "docs" } ~~~ h4@{ shape: tag-doc, label: "tag-doc" }
|
||||
i1@{ shape: tri, label: "extract" } ~~~ i2@{ shape: flip-tri, label: "manual file" } ~~~ i3@{ shape: win-pane, label: "win-pane" } ~~~ i4@{ shape: lin-rect, label: "lin-rect" }
|
||||
j1@{ shape: notch-pent, label: "loop limit" } ~~~ j2@{ shape: sl-rect, label: "manual input" } ~~~ j3@{ shape: st-rect, label: "processes" } ~~~ j4@{ shape: flag, label: "paper tape" }
|
||||
k1@{ shape: bow-rect, label: "stored data" } ~~~ k2@{ shape: tag-rect, label: "tag-rect" } ~~~ k3@{ shape: sm-circ } ~~~ k4@{ shape: f-circ }
|
||||
l1@{ shape: fr-circ } ~~~ l2@{ shape: cross-circ } ~~~ l3@{ shape: fork } ~~~ l4@{ shape: icon, form: circle, label: "icon" }
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_shapes(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(SHAPES).style(style).build(k))
|
||||
}
|
||||
|
||||
/// Sequence participant types, `create` and `destroy`, numbering from 10; and a state diagram with
|
||||
/// notes, concurrent regions, a fork and join and a choice.
|
||||
const FLOWS: &str = r#"```mermaid
|
||||
sequenceDiagram
|
||||
autonumber 10
|
||||
participant UI@{ "type": "boundary" }
|
||||
participant Ctl@{ "type": "control" }
|
||||
participant Db@{ "type": "database" }
|
||||
participant Q@{ "type": "queue" }
|
||||
UI->>Ctl: submit
|
||||
Ctl->>Db: save
|
||||
create participant Job
|
||||
Ctl->>Job: start
|
||||
Job->>Q: enqueue
|
||||
destroy Job
|
||||
Job-->>Ctl: done
|
||||
Note over UI,Ctl: saved
|
||||
```
|
||||
|
||||
```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Ready
|
||||
state Ready {
|
||||
[*] --> Idle
|
||||
Idle --> Typing : key
|
||||
--
|
||||
[*] --> Offline
|
||||
Offline --> Online : connect
|
||||
}
|
||||
Ready --> split
|
||||
state split <<fork>>
|
||||
split --> Save
|
||||
split --> Sync
|
||||
state merge <<join>>
|
||||
Save --> merge
|
||||
Sync --> merge
|
||||
merge --> ok
|
||||
state ok <<choice>>
|
||||
ok --> [*] : fine
|
||||
ok --> Ready : retry
|
||||
note right of Save : writes to disk
|
||||
```
|
||||
"#;
|
||||
|
||||
/// An entity-relationship diagram, a gantt chart and a pie chart.
|
||||
const CHARTS: &str = r#"```mermaid
|
||||
erDiagram
|
||||
CUSTOMER ||--o{ ORDER : places
|
||||
ORDER ||--|{ LINE-ITEM : contains
|
||||
PRODUCT |o..o{ LINE-ITEM : "listed in"
|
||||
CUSTOMER {
|
||||
string id PK
|
||||
string name
|
||||
string email UK "login"
|
||||
}
|
||||
ORDER {
|
||||
int id PK
|
||||
string customer FK
|
||||
date placed
|
||||
}
|
||||
LINE-ITEM {
|
||||
int qty
|
||||
decimal price
|
||||
}
|
||||
```
|
||||
|
||||
```mermaid
|
||||
gantt
|
||||
title Release 2.0
|
||||
dateFormat YYYY-MM-DD
|
||||
axisFormat %b %d
|
||||
excludes weekends
|
||||
section Build
|
||||
Design :done, des, 2024-03-04, 4d
|
||||
Core engine :active, core, after des, 8d
|
||||
Plugins :plug, after des, 6d
|
||||
section Ship
|
||||
Beta :crit, beta, after core plug, 4d
|
||||
Docs :docs, after plug, 5d
|
||||
Release :milestone, after beta docs, 0d
|
||||
Code freeze :vert, 2024-03-18, 0d
|
||||
```
|
||||
|
||||
```mermaid
|
||||
pie showData title Where the time went
|
||||
"Building" : 42
|
||||
"Reviewing" : 23
|
||||
"Waiting on CI" : 18
|
||||
"Meetings" : 9
|
||||
"Other" : 4
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_charts(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(CHARTS).style(style).build(k))
|
||||
}
|
||||
|
||||
/// A mindmap, a timeline and a user journey.
|
||||
const MAPS: &str = r#"```mermaid
|
||||
mindmap
|
||||
root((Rune))
|
||||
Layout
|
||||
Flex rows
|
||||
Virtual lists
|
||||
Text measure
|
||||
Motion
|
||||
Springs
|
||||
Transitions
|
||||
Platforms
|
||||
Mac
|
||||
iOS
|
||||
Web
|
||||
Diagrams
|
||||
Flowcharts
|
||||
Charts))new((
|
||||
```
|
||||
|
||||
```mermaid
|
||||
timeline
|
||||
title Shipping a release
|
||||
section Plan
|
||||
Week 1 : Scope : Design review
|
||||
Week 2 : Prototype
|
||||
section Build
|
||||
Week 3 : Core engine : Tests
|
||||
Week 4 : Plugins
|
||||
section Ship
|
||||
Week 5 : Beta : Docs
|
||||
Week 6 : Launch
|
||||
```
|
||||
|
||||
```mermaid
|
||||
journey
|
||||
title A first-time user
|
||||
section Discover
|
||||
Find the site: 4: User
|
||||
Read the docs: 3: User
|
||||
section Try
|
||||
Install: 2: User, CLI
|
||||
First build: 5: User, CLI
|
||||
section Share
|
||||
Tell a friend: 5: User
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_maps(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(MAPS).style(style).build(k))
|
||||
}
|
||||
|
||||
/// A git graph, a short timeline and a quadrant chart.
|
||||
const GIT: &str = r#"```mermaid
|
||||
timeline
|
||||
title Rune
|
||||
2024 : First window
|
||||
2025 : Kit components : Motion
|
||||
2026 : Mermaid diagrams
|
||||
```
|
||||
|
||||
```mermaid
|
||||
gitGraph
|
||||
commit id: "init"
|
||||
commit id: "layout" tag: "v0.1"
|
||||
branch feature
|
||||
checkout feature
|
||||
commit id: "springs"
|
||||
commit id: "fix" type: REVERSE
|
||||
checkout main
|
||||
commit id: "docs" type: HIGHLIGHT
|
||||
merge feature id: "merge" tag: "v0.2"
|
||||
branch hotfix
|
||||
commit id: "patch"
|
||||
checkout main
|
||||
cherry-pick id: "patch"
|
||||
```
|
||||
|
||||
```mermaid
|
||||
quadrantChart
|
||||
title Reach and engagement
|
||||
x-axis Low Reach --> High Reach
|
||||
y-axis Low Engagement --> High Engagement
|
||||
quadrant-1 Expand
|
||||
quadrant-2 Promote
|
||||
quadrant-3 Re-evaluate
|
||||
quadrant-4 Improve
|
||||
Campaign A: [0.3, 0.6]
|
||||
Campaign B: [0.45, 0.23]
|
||||
Campaign C: [0.57, 0.69]
|
||||
Campaign D: [0.78, 0.34]
|
||||
Campaign E: [0.40, 0.34]
|
||||
Campaign F: [0.35, 0.78] radius: 8, color: #e8590c
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_git(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(GIT).style(style).build(k))
|
||||
}
|
||||
|
||||
/// An XY chart, a sankey diagram and a block diagram.
|
||||
const DATA: &str = r#"```mermaid
|
||||
xychart-beta
|
||||
title "Frame time by build"
|
||||
x-axis [debug, release, perf, wasm]
|
||||
y-axis "Milliseconds" 0 --> 20
|
||||
bar "p50" [16.2, 6.1, 5.8, 9.4]
|
||||
line "p99" [19.1, 8.3, 7.9, 13.2]
|
||||
```
|
||||
|
||||
```mermaid
|
||||
sankey-beta
|
||||
Input,Layout,40
|
||||
Input,Text,25
|
||||
Layout,Paint,32
|
||||
Layout,Idle,8
|
||||
Text,Paint,25
|
||||
Paint,GPU,50
|
||||
Paint,Cache,7
|
||||
```
|
||||
|
||||
```mermaid
|
||||
block-beta
|
||||
columns 3
|
||||
app["App"]:3
|
||||
view["Views"] state[("State")] motion(["Motion"])
|
||||
block:core:2
|
||||
columns 2
|
||||
layout["Layout"] text["Text"]
|
||||
end
|
||||
gpu{{"wgpu"}}
|
||||
arrow<["frames"]>(down):3
|
||||
screen["Screen"]:3
|
||||
view --> layout
|
||||
state -- "reads" --> text
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_data(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(DATA).style(style).build(k))
|
||||
}
|
||||
|
||||
/// A requirement diagram and a C4 container diagram.
|
||||
const SYSTEMS: &str = r#"```mermaid
|
||||
requirementDiagram
|
||||
requirement fast_start {
|
||||
id: 1
|
||||
text: First frame in 100 ms.
|
||||
risk: high
|
||||
verifymethod: test
|
||||
}
|
||||
performanceRequirement idle {
|
||||
id: 1.1
|
||||
text: An idle window draws nothing.
|
||||
risk: medium
|
||||
verifymethod: analysis
|
||||
}
|
||||
element runtime {
|
||||
type: crate
|
||||
docref: crates/rune
|
||||
}
|
||||
fast_start - contains -> idle
|
||||
runtime - satisfies -> fast_start
|
||||
runtime - verifies -> idle
|
||||
```
|
||||
|
||||
```mermaid
|
||||
C4Container
|
||||
title Notes app
|
||||
Person(user, "Writer", "Takes notes on a laptop")
|
||||
System_Boundary(app, "Notes") {
|
||||
Container(ui, "Window", "Rust, Rune", "Draws the editor")
|
||||
Container(sync, "Sync", "Rust", "Merges edits")
|
||||
ContainerDb(db, "Store", "SQLite", "Notes and history")
|
||||
}
|
||||
System_Ext(cloud, "Cloud backup", "Keeps a copy")
|
||||
Rel(user, ui, "Types in")
|
||||
Rel(ui, sync, "Sends edits")
|
||||
Rel(sync, db, "Reads and writes", "SQL")
|
||||
Rel(sync, cloud, "Uploads", "HTTPS")
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_systems(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(SYSTEMS).style(style).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn markdown_mermaid_flows(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(FLOWS).style(style).build(k))
|
||||
}
|
||||
|
||||
/// A state diagram for hover: pointing at an edge or its label lights both.
|
||||
const HOVER: &str = r#"```mermaid
|
||||
stateDiagram-v2
|
||||
[*] --> Idle
|
||||
Idle --> Loading : fetch
|
||||
Loading --> Ready : 200 OK
|
||||
Loading --> Failed : error
|
||||
Failed --> Loading : retry
|
||||
Ready --> [*]
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_hover(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).child(Markdown::new(HOVER).style(style).build(k))
|
||||
}
|
||||
|
||||
/// A wide build plan: four subgraphs whose ranks interleave, fourteen classDef-tinted nodes, and
|
||||
/// edges that fan out of one node into another subgraph.
|
||||
fn plan_markdown() -> String {
|
||||
format!("```mermaid\n{}```\n", include_str!("../../../../crates/rune-mermaid/fixtures/plan.mmd"))
|
||||
}
|
||||
|
||||
/// The plan in a reply-wide column that fits any diagram whole, as a chat app shows it.
|
||||
pub(super) fn markdown_mermaid_plan(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(680.0).diagram_min_scale(0.0);
|
||||
col().w(680.0).child(Markdown::new(plan_markdown()).style(style).build(k))
|
||||
}
|
||||
|
||||
/// [`markdown_mermaid_plan`] magnified 3×, as a lightbox shows it to read.
|
||||
pub(super) fn markdown_mermaid_plan_zoomed(g: &G, k: &Kit, o: &mut Vec<El>) -> El {
|
||||
col().w(680.0).origin(0.0, 0.0).scale(3.0).child(markdown_mermaid_plan(g, k, o))
|
||||
}
|
||||
|
||||
/// A table without an outline, with a dimmed header and figures that line up, and a diff whose
|
||||
/// line text is tinted too.
|
||||
const TABLE_STYLES: &str = "| Field | Compared |\n|---|---|\n| title | yes |\n| updatedAt | yes |\n| draft cursor | no |\n\n| Build | Files | Time | Size |\n|:--|--:|--:|--:|\n| debug | 1,204 | 41.8 s | 118.4 MB |\n| release | 1,204 | 71.0 s | 31.1 MB |\n| perf | 1,211 | 69.6 s | 33.7 MB |\n\n```diff\n@@ -3,3 +3,3 @@ fields:\n title: compared\n- draft: compared\n+ draft: ignored\n```\n";
|
||||
|
||||
pub(super) fn markdown_table_styles(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let style = MarkdownStyle::from_kit(k)
|
||||
.table(k.c.border_muted, rune::Color::TRANSPARENT)
|
||||
.table_outline(None)
|
||||
.table_header_text(k.c.text_muted)
|
||||
.diff_text_tint(0.5);
|
||||
col().w(560.0).child(Markdown::new(TABLE_STYLES).style(style).build(k))
|
||||
}
|
||||
|
||||
/// Fenced code in each language family the highlighter knows.
|
||||
const CODE: &str = r#"```tsx
|
||||
// Loads a user, then renders their card.
|
||||
export async function load(id: string): Promise<User | null> {
|
||||
const res = await fetch(`/api/users/${id}`, { method: "GET" });
|
||||
return res.ok ? res.json() : null;
|
||||
}
|
||||
const Card = ({ user }: Props) => <div className="card">{user.name}</div>;
|
||||
```
|
||||
|
||||
```rust
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Retry<'a> { name: &'a str, attempts: u32 }
|
||||
|
||||
fn backoff(n: u32) -> Duration {
|
||||
Duration::from_millis(200 * 2u64.pow(n)) // capped by the caller
|
||||
}
|
||||
```
|
||||
|
||||
```python
|
||||
@dataclass
|
||||
class Job:
|
||||
name: str
|
||||
tries: int = 3 # per run
|
||||
|
||||
def label(self) -> str:
|
||||
return f"{self.name} ×{self.tries}" if self.tries > 1 else self.name
|
||||
```
|
||||
|
||||
```go
|
||||
func (s *Server) Serve(ctx context.Context) error {
|
||||
for job := range s.queue {
|
||||
if err := job.Run(ctx); err != nil {
|
||||
return fmt.Errorf("job %q: %w", job.Name, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
```sh
|
||||
# Build, then ship the release.
|
||||
FEATURES=markdown cargo build --release && echo "done in $SECONDS s"
|
||||
if [ -n "$TAG" ]; then gh release create "$TAG" ./target/*.tar.gz; fi
|
||||
```
|
||||
|
||||
```sql
|
||||
SELECT u.id, count(*) AS posts
|
||||
FROM users u JOIN posts p ON p.user_id = u.id
|
||||
WHERE u.created_at > '2026-01-01' AND p.draft = false
|
||||
GROUP BY u.id ORDER BY posts DESC LIMIT 10;
|
||||
```
|
||||
|
||||
```yaml
|
||||
name: ci
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
test:
|
||||
runs-on: macos-15 # Apple silicon
|
||||
timeout-minutes: 30
|
||||
steps:
|
||||
- run: cargo test --workspace
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_code(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col().w(620.0).child(Markdown::new(CODE).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn markdown_walkthrough(_: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
col().w(680.0).child(Markdown::new(WALKTHROUGH).on_link(|_: &mut G, _| {}).build(k))
|
||||
}
|
||||
|
||||
pub(super) fn markdown_streaming(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let n: usize = s.picked("md-stream", "60").parse().unwrap_or(60);
|
||||
let end = MARKDOWN.char_indices().map(|(i, _)| i).nth(n).unwrap_or(MARKDOWN.len());
|
||||
col().w(560.0).gap(12.0)
|
||||
.child(
|
||||
Button::new("Stream more")
|
||||
.on_press(move |s: &mut G| {
|
||||
s.pick.insert("md-stream".into(), (n + 40).to_string());
|
||||
})
|
||||
.build(k)
|
||||
.key("stream-more"),
|
||||
)
|
||||
.child(Markdown::new(&MARKDOWN[..end]).reveal(0.18).streaming(end < MARKDOWN.len()).build(k))
|
||||
}
|
||||
|
||||
/// A reply streaming in a chunk a press, each ending inside markup: an open emphasis, code or
|
||||
/// strike span draws styled, never its markers, and the table's header line waits to be a table
|
||||
/// rather than laying out as a paragraph first. Each press also starts a block, so it draws.
|
||||
const TAIL_STREAM: [&str; 5] = [
|
||||
"Open **Settings ›",
|
||||
" Appearance** and pick *Dark*.\n\n- run `theme",
|
||||
" dark`\n- then ~~restart",
|
||||
"~~ nothing\n\nChanged:\n\n| File",
|
||||
" | Change |\n|---|---|\n| theme.rs | dark |\n",
|
||||
];
|
||||
|
||||
pub(super) fn markdown_stream_tail(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let n: usize = s.picked("md-tail-stream", "0").parse().unwrap_or(0);
|
||||
let src = TAIL_STREAM[..n.min(TAIL_STREAM.len())].concat();
|
||||
col().w(560.0).gap(12.0)
|
||||
.child(
|
||||
Button::new("Stream more")
|
||||
.on_press(move |s: &mut G| {
|
||||
s.pick.insert("md-tail-stream".into(), (n + 1).to_string());
|
||||
})
|
||||
.build(k)
|
||||
.key("stream-more"),
|
||||
)
|
||||
.child(Markdown::new(src).streaming(n < TAIL_STREAM.len()).build(k))
|
||||
}
|
||||
|
||||
/// A reply streaming in with a flowchart and a sequence diagram: each "Stream more" adds lines up
|
||||
/// to the next one that draws something (a fence, its header or a blank line draws nothing).
|
||||
const DIAGRAM_STREAM: &str = r#"Here's the flow:
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
A[Request] --> B{Cached?}
|
||||
B -->|yes| C[Serve]
|
||||
B -->|no| D[Fetch]
|
||||
D --> E[(Store)]
|
||||
E --> C
|
||||
```
|
||||
|
||||
And who talks to whom:
|
||||
|
||||
```mermaid
|
||||
sequenceDiagram
|
||||
participant U as User
|
||||
participant A as App
|
||||
participant S as Server
|
||||
U->>A: Open
|
||||
A->>S: GET /items
|
||||
S-->>A: 200 OK
|
||||
A-->>U: Show list
|
||||
```
|
||||
"#;
|
||||
|
||||
pub(super) fn markdown_mermaid_streaming(s: &G, k: &Kit, _: &mut Vec<El>) -> El {
|
||||
let end: usize = s.picked("md-diagram-stream", "0").parse().unwrap_or(0).min(DIAGRAM_STREAM.len());
|
||||
let style = MarkdownStyle::from_kit(k).diagram_max_width(560.0);
|
||||
col().w(560.0).gap(12.0)
|
||||
.child(
|
||||
Button::new("Stream more")
|
||||
.on_press(move |s: &mut G| {
|
||||
s.pick.insert("md-diagram-stream".into(), next_drawn_line(DIAGRAM_STREAM, end).to_string());
|
||||
})
|
||||
.build(k)
|
||||
.key("stream-more"),
|
||||
)
|
||||
.child(Markdown::new(&DIAGRAM_STREAM[..end]).style(style).streaming(end < DIAGRAM_STREAM.len()).build(k))
|
||||
}
|
||||
|
||||
/// The end of the first line after `from` that draws something, taking any quiet lines before it
|
||||
/// (and the quiet lines that end the reply, so the last press also closes its fence).
|
||||
fn next_drawn_line(src: &str, from: usize) -> usize {
|
||||
let quiet = |line: &str| {
|
||||
let t = line.trim();
|
||||
t.is_empty() || t.starts_with("```") || t == "flowchart LR" || t == "sequenceDiagram"
|
||||
};
|
||||
let mut at = from;
|
||||
for line in src[from..].split_inclusive('\n') {
|
||||
at += line.len();
|
||||
if !quiet(line) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if src[at..].split_inclusive('\n').all(quiet) { src.len() } else { at }
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
//! Popover, Menu, Tooltip, HoverCard and Toast.
|
||||
|
||||
use super::*;
|
||||
|
||||
fn trigger_text(k: &Kit, s: &str) -> El {
|
||||
body_text(k, s)
|
||||
}
|
||||
|
||||
pub(super) fn popover_basic(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(
|
||||
Popover::new("popover")
|
||||
.trigger(trigger_text(k, "Open popover"))
|
||||
.title("Popover")
|
||||
.description("Optional description")
|
||||
.child(overlay_text(k, "Popover content"))
|
||||
.open(is_open(s, "popover"))
|
||||
.on_close(close)
|
||||
.build(k, layer)
|
||||
.on_press(toggle("popover")),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn popover_controlled(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(
|
||||
Popover::new("popover")
|
||||
.trigger(trigger_text(k, "Toggle popover"))
|
||||
.title("Controlled")
|
||||
.description("Open state is controlled")
|
||||
.child(overlay_text(k, "Controlled content"))
|
||||
.open(is_open(s, "popover"))
|
||||
.on_close(close)
|
||||
.build(k, layer)
|
||||
.on_press(toggle("popover")),
|
||||
)
|
||||
}
|
||||
|
||||
fn menu_button(k: &Kit, label: &str, key: &'static str, open: bool) -> El {
|
||||
Button::new(label).expanded(open).on_press(toggle(key)).build(k)
|
||||
}
|
||||
|
||||
pub(super) fn menu_basic(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "menu");
|
||||
row().child(
|
||||
Menu::new("menu")
|
||||
.trigger(menu_button(k, "Open menu", "menu", open))
|
||||
.item(MenuItem::new("New file").on_select(close))
|
||||
.item(MenuItem::new("Open file").on_select(close))
|
||||
.item(MenuItem::new("Save").on_select(close))
|
||||
.separator()
|
||||
.item(MenuItem::new("Print").disabled(true))
|
||||
.open(open)
|
||||
.on_close(close)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn menu_appearances(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "both");
|
||||
row()
|
||||
.gap(16.0)
|
||||
.child(
|
||||
Menu::new("standard")
|
||||
.standard()
|
||||
.trigger(menu_button(k, "Standard", "both", open))
|
||||
.item(MenuItem::new("New file"))
|
||||
.item(MenuItem::new("Open file"))
|
||||
.open(open)
|
||||
.build(k, layer),
|
||||
)
|
||||
.child(
|
||||
Menu::new("compact")
|
||||
.trigger(menu_button(k, "Compact", "both", open))
|
||||
.item(MenuItem::new("New file"))
|
||||
.item(MenuItem::new("Open file"))
|
||||
.open(open)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn menu_rich(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "menu");
|
||||
let avatar = row()
|
||||
.size(16.0, 16.0)
|
||||
.center()
|
||||
.radius(4.0)
|
||||
.fill(k.c.layer_03)
|
||||
.child(text("A").font(k.ty.small_medium).color(k.c.text_base));
|
||||
row().child(
|
||||
Menu::new("menu")
|
||||
.trigger(menu_button(k, "Open rich menu", "menu", open))
|
||||
.min_width(240.0)
|
||||
.item(MenuItem::new("Text").lead(avatar).icon(&ic::PLUS).shortcut("⇧ D").badge("Label"))
|
||||
.item(MenuItem::new("New window").icon(&ic::PLUS).shortcut("⌘ N"))
|
||||
.item(MenuItem::new("Save as…").icon(&ic::PLUS).shortcut("⌘ S").badge("Beta"))
|
||||
.separator()
|
||||
.item(MenuItem::new("Print").icon(&ic::PLUS).shortcut("⌘ P").disabled(true))
|
||||
.open(open)
|
||||
.on_close(close)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn menu_checkbox(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "menu");
|
||||
row().child(
|
||||
Menu::new("menu")
|
||||
.trigger(menu_button(k, "View", "menu", open))
|
||||
.min_width(200.0)
|
||||
.item(MenuItem::new("Word wrap").shortcut("⌥ Z").checked(!s.is("wrap")).on_select(flip("wrap")))
|
||||
.item(MenuItem::new("Minimap").checked(s.is("minimap")).on_select(flip("minimap")))
|
||||
.item(MenuItem::new("Ruler").checked(false).disabled(true))
|
||||
.open(open)
|
||||
.on_close(close)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn menu_radio(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "menu");
|
||||
let theme = s.picked("theme", "system").to_owned();
|
||||
let pick = |v: &'static str| {
|
||||
move |s: &mut G| {
|
||||
s.pick.insert("theme".into(), v.into());
|
||||
}
|
||||
};
|
||||
row().child(
|
||||
Menu::new("menu")
|
||||
.trigger(menu_button(k, "Theme", "menu", open))
|
||||
.min_width(200.0)
|
||||
.group_label("Appearance")
|
||||
.item(MenuItem::new("Light").checked(theme == "light").on_select(pick("light")))
|
||||
.item(MenuItem::new("Dark").checked(theme == "dark").on_select(pick("dark")))
|
||||
.item(MenuItem::new("System").badge("Auto").checked(theme == "system").on_select(pick("system")))
|
||||
.open(open)
|
||||
.on_close(close)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn menu_submenu(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let open = is_open(s, "menu");
|
||||
let recent = vec![
|
||||
MenuEntry::item(MenuItem::new("project-alpha.tsx")),
|
||||
MenuEntry::item(MenuItem::new("project-beta.tsx")),
|
||||
MenuEntry::item(MenuItem::new("project-gamma.tsx")),
|
||||
MenuEntry::Separator,
|
||||
MenuEntry::item(MenuItem::new("Clear recent")),
|
||||
];
|
||||
row().child(
|
||||
Menu::new("menu")
|
||||
.trigger(menu_button(k, "File", "menu", open))
|
||||
.min_width(200.0)
|
||||
.item(MenuItem::new("New file").shortcut("⌘ N"))
|
||||
.item(MenuItem::new("Open file").shortcut("⌘ O"))
|
||||
.item(MenuItem::new("Open recent").submenu(recent, s.is("recent")).on_select(flip("recent")))
|
||||
.separator()
|
||||
.item(MenuItem::new("Save").shortcut("⌘ S"))
|
||||
.item(MenuItem::new("Save as…").shortcut("⇧⌘ S"))
|
||||
.open(open)
|
||||
.on_close(close)
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
/// The tooltip stories' frame: 80 points of padding, centred.
|
||||
fn tip_frame(e: El) -> El {
|
||||
row().w_full().padding(80.0).center().child(e)
|
||||
}
|
||||
|
||||
pub(super) fn tooltip_simple(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let t = Tooltip::new("tip").trigger(body_text(k, "Hover me")).open(is_open(s, "tip"));
|
||||
tip_frame(t.text(k, "Tooltip Text").build(k, layer))
|
||||
}
|
||||
|
||||
pub(super) fn tooltip_keybind(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let t = Tooltip::new("tip").trigger(body_text(k, "Hover me")).open(is_open(s, "tip"));
|
||||
tip_frame(t.text(k, "Tooltip Text").child(Keybind::new(&["⌘", "⌘"]).build(k)).build(k, layer))
|
||||
}
|
||||
|
||||
pub(super) fn tooltip_path(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let t = Tooltip::new("tip").trigger(body_text(k, "Hover me")).open(is_open(s, "tip"));
|
||||
let font = t.font(k);
|
||||
let parts = row()
|
||||
.gap(3.0)
|
||||
.child(text("Components").font(font).color(k.c.text_base))
|
||||
.child(text("/").font(font).color(k.c.text_faint))
|
||||
.child(text("Tooltip").font(font).color(k.c.text_base));
|
||||
tip_frame(t.child(parts).build(k, layer))
|
||||
}
|
||||
|
||||
pub(super) fn tooltip_title_description(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let t = Tooltip::new("tip").trigger(body_text(k, "Hover me")).open(is_open(s, "tip"));
|
||||
let font = t.font(k);
|
||||
tip_frame(
|
||||
t.child(text("Title").font(font).color(k.c.text_base))
|
||||
.child(text("·").font(font).color(k.c.text_faint))
|
||||
.child(text("Description").font(font).color(k.c.text_faint))
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
pub(super) fn hover_card_basic(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
row().child(
|
||||
HoverCard::new("card")
|
||||
.trigger(body_text(k, "Hover me"))
|
||||
.child(
|
||||
col()
|
||||
.gap(6.0)
|
||||
.child(text("Preview").font(TextStyle::new(13.0, 600.0).lh(24.0)).color(k.c.std_text))
|
||||
.child(
|
||||
text("Short supporting text.").font(TextStyle::new(12.0, 440.0).lh(24.0)).color(k.c.text_weak),
|
||||
),
|
||||
)
|
||||
.open(is_open(s, "card"))
|
||||
.build(k, layer),
|
||||
)
|
||||
}
|
||||
|
||||
static DOWNLOAD: rune::Icon = rune::Icon {
|
||||
name: "story-download",
|
||||
view: 16.0,
|
||||
body: r#"<path d="M13.5554 10.4453V13.5564H11.7777H4.22211C3.23989 13.5564 2.44434 13.5564 2.44434 13.5564V10.4453" stroke="currentColor"/><path d="M4.88867 6L7.99978 9.11111L11.1109 6" stroke="currentColor"/><path d="M8 9.11198V2.44531" stroke="currentColor"/>"#,
|
||||
};
|
||||
|
||||
pub(super) fn toast_all(s: &G, k: &Kit, layer: &mut Vec<El>) -> El {
|
||||
let buttons = col()
|
||||
.gap(12.0)
|
||||
.items_start()
|
||||
.child(Button::new("Show download toast").on_press(|s: &mut G| s.open = Some("toast".into())).build(k))
|
||||
.child(Button::new("Show saved toast").build(k))
|
||||
.child(Button::new("Show saving toast").build(k))
|
||||
.child(Button::new("Show unsaved changes toast").build(k));
|
||||
if is_open(s, "toast") {
|
||||
let t = Toast::new("download", "Download started...")
|
||||
.description("23% · 2 min left")
|
||||
.icon(k, &DOWNLOAD)
|
||||
.closable()
|
||||
.action(k, "Run in background", true, |s: &mut G, _: &mut Tx| s.open = None)
|
||||
.action(k, "Cancel", false, |s: &mut G, _: &mut Tx| s.open = None)
|
||||
.build(k);
|
||||
layer.push(ToastRegion::new().toast(t).build(k));
|
||||
}
|
||||
buttons
|
||||
}
|
||||
Reference in new issue
Block a user