1#![windows_subsystem = "windows"]
5use taut::{
6 Align, Animation, AppFonts, Cap, CellEditor, CellValue, Chart, ChartView, CodeEditor, Color, Column, ContrastColors, Date, Dock, Drawing, Field, FileDialog, Flow, FontFile, Icon, Inspector, Join,
7 Key, Length, Markdown, Mods, Paint, Panel, Path, Pen, Picture, Point, Role, SecondWindow, Selection, Series, Severity, Span, Syntax, Table, Theme, Time, Transform, TreeItem, TreeView, Ui, Window,
8};
9
10const PAGES: [&str; 9] = ["List", "Table", "Parts", "Drawing", "More", "Dock", "Familiar", "Charts", "Writing"];
11const SPACINGS: [&str; 3] = ["Dense", "Usual", "Roomy"];
13const COMMANDS: [&str; 11] = [
15 "Go to the list",
16 "Go to the table",
17 "Go to the parts",
18 "Go to the drawing",
19 "Go to more parts",
20 "Go to the dock",
21 "Go to the familiar parts",
22 "Go to the charts",
23 "Go to the writing",
24 "Light colours, or dark",
25 "Rename this window\u{2026}\tF2",
26];
27const KINDS: [&str; 4] = ["text", "picture", "sound", "folder"];
29const COLUMNS: [Column; 4] = [
30 Column::new("Name").px(240.0).editable(CellEditor::Text),
31 Column::new("Size").px(90.0).align(Align::End).editable(CellEditor::Number),
32 Column::new("Kind").px(110.0).editable(CellEditor::Choice(&KINDS)),
33 Column::new("Note").px(560.0).unsorted(),
34];
35const DAYS: [&str; 7] = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
36
37const PLUS: Icon = Icon::line("M8 3.5v9M3.5 8h9");
38const MORE: Icon = Icon::solid("M3.5 6.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4zM8 6.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4zM12.5 6.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4z");
39const STAR: Icon = Icon::line("M8 2.2 9.8 5.9 13.8 6.4 10.9 9.2 11.6 13.2 8 11.3 4.4 13.2 5.1 9.2 2.2 6.4 6.2 5.9z");
40const GRID: Icon = Icon::line("M3 3h4v4H3zM9 3h4v4H9zM3 9h4v4H3zM9 9h4v4H9z");
41const PAGE: Icon = Icon::line("M4.5 2.5h4.5l2.5 2.5v8.5h-7zM9 2.5V5h2.5M6 8h4M6 10.5h4");
42const BELL: Icon = Icon::line("M8 2.5a3.5 3.5 0 0 1 3.5 3.5v2.5l1.2 2H3.3l1.2-2V6A3.5 3.5 0 0 1 8 2.5zM6.6 12.5a1.5 1.5 0 0 0 2.8 0");
43const SYNC: Icon = Icon::line("M2.8 7.2A5.3 5.3 0 0 1 12 4.6l1.2 1.2M13.2 8.8A5.3 5.3 0 0 1 4 11.4l-1.2-1.2M13.4 2.9v3h-3M2.6 13.1v-3h3");
44const DROP: Icon = Icon::line("M8 2.2c2.6 3 4.2 5.3 4.2 7.3a4.2 4.2 0 0 1-8.4 0c0-2 1.6-4.3 4.2-7.3z");
45const COPY: Icon = Icon::line("M5.5 5.5h7v7h-7zM10.5 5.5v-2h-7v7h2");
46const PANELS: [(&str, bool); 4] = [("Files", false), ("Editor", false), ("Preview", true), ("Log", true)];
48
49const COLOURS: [&str; 40] = [
51 "Amber",
52 "Apricot",
53 "Aquamarine",
54 "Azure",
55 "Beige",
56 "Black",
57 "Blue",
58 "Bronze",
59 "Brown",
60 "Burgundy",
61 "Cerulean",
62 "Charcoal",
63 "Cobalt",
64 "Coral",
65 "Crimson",
66 "Cyan",
67 "Emerald",
68 "Gold",
69 "Green",
70 "Grey",
71 "Indigo",
72 "Ivory",
73 "Jade",
74 "Khaki",
75 "Lavender",
76 "Lilac",
77 "Magenta",
78 "Maroon",
79 "Navy blue",
80 "Ochre",
81 "Olive",
82 "Orange",
83 "Pink",
84 "Purple",
85 "Red",
86 "Scarlet",
87 "Teal",
88 "Turquoise",
89 "Violet",
90 "White",
91];
92
93#[derive(Clone)]
95pub struct Lamp {
96 name: String,
97 power: f32,
98 on: bool,
99 kind: LampKind,
100 tint: Color,
101 rooms: Vec<String>,
102}
103
104#[derive(Clone, Copy, PartialEq)]
106pub enum LampKind {
107 Spot,
108 Flood,
109 Strip,
110}
111taut::inspect!(enum LampKind { Spot: "Spot", Flood: "Flood", Strip: "Strip" });
112taut::inspect!(Lamp { name: "Name", power: Field::new("Power").unit("W").range(0.0, 2000.0), on: "On", kind: "Kind", tint: "Colour", rooms: "Rooms" });
113
114pub struct App {
115 name: String,
116 presses: u32,
117 page: usize,
119 room: usize,
121 filter: String,
122 notes: String,
123 renaming: Option<String>,
125 light: bool,
127 contrast: bool,
130 system: bool,
131 spacing: usize,
132 ticked: bool,
133 on: bool,
134 folded_open: bool,
135 second: bool,
136 level: f32,
137 bold: bool,
138 starred: bool,
139 span: usize,
140 busy: bool,
141 from: f32,
142 to: f32,
143 followed: u32,
144 finding: bool,
146 colour: usize,
147 wanted: String,
148 picture: Option<Picture>,
150 photo: Option<Picture>,
151 drawings: Option<(Drawing, Drawing)>,
152 animation: Option<Animation>,
153 playing: bool,
155 letters: Option<FontFile>,
157 place: String,
158 shape: Option<usize>,
160 selected_row: usize,
162 tree_open: [bool; 2],
163 amount: f32,
164 off: bool,
165 count: i32,
166 day: Date,
167 alarm: Time,
169 meeting: (Date, Time),
170 away: (Date, Date),
171 marked: f32,
173 zoom: f32,
174 tint: Color,
176 drag_lists: [Vec<&'static str>; 2],
178 within: f32,
181 fruit: &'static str,
182 faint: bool,
183 hide: bool,
184 table: Table,
186 selection: Selection,
187 files: Vec<(String, u32, &'static str)>,
188 tools: Panel,
190 code: CodeEditor,
192 lamp: Lamp,
194 inspector: Inspector,
195 beside: SecondWindow,
196 file_dialog: FileDialog,
198 dock: Dock,
200 slices: ChartView,
203 view: ChartView,
204 dots: [Vec<f32>; 4],
205 live: bool,
206 load: Vec<f32>,
207 fed: f64,
208 folders: TreeView,
209 step: usize,
211 results: usize,
212 query: String,
213 topics: Vec<String>,
214 topic: String,
215 stars: f32,
216 face: Option<Picture>,
218 liked: [bool; 2],
219 loading: bool,
220 banner: bool,
221 styles: [bool; 3],
222 section: Option<usize>,
224 writing: Markdown,
226}
227
228pub fn describe(app: &mut App, ui: &mut Ui) {
229 ui.theme = theme(app, ui);
230 if let Some(letters) = app.letters.take() {
231 ui.set_text_system(Box::new(AppFonts::new(letters)));
232 }
233 menu_bar(app, ui);
234 shortcuts(app, ui);
235 top_bar(app, ui);
236 pages(app, ui);
237 tools_panel(app, ui);
238 second_window(app, ui);
239 rename_dialog(app, ui);
240 match ui.command_palette(&mut app.finding, &COMMANDS) {
242 Some(page) if page < PAGES.len() => (app.page, _) = (page, ui.notice(&format!("This is the page \u{201c}{}\u{201d}", PAGES[page]))),
244 Some(9) => app.light = !app.light,
245 Some(_) => app.renaming = Some(app.name.clone()),
246 None => {}
247 }
248 if let Some(file) = ui.file_dialog(&mut app.file_dialog) {
250 app.name = file.file_name().map_or_else(String::new, |name| name.to_string_lossy().into_owned());
251 }
252}
253
254fn menu_bar(app: &mut App, ui: &mut Ui) {
257 ui.menu_bar();
258 if ui.menu_button("&File") {
259 if ui.menu_item("&Rename this window…\tF2").clicked {
260 app.renaming = Some(app.name.clone());
261 }
262 if ui.submenu("&Go to page") {
263 for (number, name) in PAGES.iter().enumerate() {
264 if ui.menu_item(name).clicked {
265 app.page = number;
266 }
267 }
268 ui.close();
269 }
270 if ui.menu_item("&Open a file…").clicked {
271 app.file_dialog.pick(std::env::home_dir().unwrap_or_else(|| ".".into()));
272 }
273 ui.separator();
274 if ui.menu_item("&Close the window").clicked {
275 ui.quit();
276 }
277 ui.close();
278 }
279 if ui.menu_button("&View") {
280 ui.menu_checkbox(&mut app.light, "&Light colours");
281 ui.menu_checkbox(&mut app.tools.open, "The &Tools panel");
282 ui.menu_checkbox(&mut app.beside.open, "A &second window");
283 app.finding |= ui.menu_item("&Find a command\u{2026}\tCtrl+K").clicked;
284 let mut whole = ui.full_screen();
286 if ui.menu_checkbox(&mut whole, "&Over all of the screen\tF11").changed {
287 ui.set_full_screen(whole);
288 }
289 ui.separator();
292 ui.menu_radio(&mut app.room, 0, "Roo&my rows");
293 ui.menu_radio(&mut app.room, 1, "Tig&ht rows");
294 ui.separator();
295 for (name, _) in PANELS.iter().filter(|(_, closes)| *closes) {
296 let mut open = app.dock.is_open(name);
297 if ui.menu_checkbox(&mut open, name).changed {
298 app.dock.set_open(name, open);
299 }
300 }
301 ui.separator();
302 ui.menu_checkbox(&mut app.contrast, "High contrast");
303 ui.menu_checkbox(&mut app.system, "As the system has it");
304 if ui.submenu("Spacing") {
305 for (number, name) in SPACINGS.iter().enumerate() {
306 app.spacing = if ui.menu_checkbox(&mut (app.spacing == number), name).clicked { number } else { app.spacing };
307 }
308 ui.close();
309 }
310 ui.close();
311 }
312 ui.close();
313}
314
315fn shortcuts(app: &mut App, ui: &mut Ui) {
317 if ui.keys("F2") {
318 app.renaming = Some(app.name.clone());
319 }
320 if ui.keys("F11") {
321 let whole = ui.full_screen();
322 ui.set_full_screen(!whole);
323 }
324 app.finding |= ui.keys("Ctrl+K");
325 if ui.keys("Ctrl+N") {
326 ui.notice("An item was added");
327 }
328 app.starred ^= ui.keys("Ctrl+D");
329}
330
331fn top_bar(app: &mut App, ui: &mut Ui) {
334 let t = ui.theme;
335 ui.row().pad((10.0, 8.0)).gap(8.0).fill(t.panel).open();
336 ui.label(&format!("{}: 60 items, {} presses counted", app.name, app.presses));
337 tool_bar(app, ui);
338 ui.el().w(Length::Px(170.0)).open();
339 ui.text_box(&mut app.filter, "Filter items");
340 ui.close();
341 ui.select(&mut app.room, &["Roomy", "Tight"]);
342 if ui.button("Start over").clicked {
343 app.presses = 0;
344 ui.announce("Counting from nothing again");
345 }
346 app.presses += ui.primary_button("Count one").clicked as u32;
347 let more = ui.icon_button(MORE, "More");
348 if more.clicked {
349 ui.open_popup(more.id, more.rect);
350 }
351 if ui.menu(more.id) {
352 if ui.menu_item("Rename this window…").clicked {
353 app.renaming = Some(app.name.clone());
354 }
355 app.light ^= ui.menu_item(if app.light { "Dark colours" } else { "Light colours" }).clicked;
356 ui.separator();
357 if ui.menu_item("Copy the notes").clicked {
358 ui.copy(&app.notes);
359 }
360 if ui.menu_item("Close the window").clicked {
361 ui.quit();
362 }
363 ui.close();
364 }
365 ui.close();
366 ui.separator();
367}
368
369fn pages(app: &mut App, ui: &mut Ui) {
371 ui.row().pad((10.0, 4.0, 10.0, 0.0)).open();
372 ui.tabs(&mut app.page, &PAGES);
373 ui.close();
374 ui.separator();
375 match app.page {
376 0 => list(app, ui),
377 1 => table(app, ui),
378 2 => parts(app, ui),
379 3 => drawing(app, ui),
380 4 => more_parts(app, ui),
381 5 => docks(app, ui),
382 6 => web_widgets(app, ui),
383 7 => charts(app, ui),
384 _ => writing(app, ui),
385 }
386}
387
388fn tool_bar(app: &mut App, ui: &mut Ui) {
391 let bar = ui.tool_bar();
392 if ui.tool(PLUS, "Add an item\tCtrl+N").clicked {
393 ui.notice("An item was added");
394 }
395 let tint = ui.tool(DROP, "The colour that stands out");
396 ui.tool_toggle(&mut app.starred, STAR, "Starred\tCtrl+D");
397 ui.tool_group();
398 if ui.tool(COPY, "Copy the notes").clicked {
399 ui.copy(&app.notes);
400 }
401 if ui.tool(SYNC, "Start over").clicked {
402 app.presses = 0;
403 }
404 ui.tool(GRID, "A tool that does nothing");
405 ui.close();
406 if tint.clicked {
408 ui.open_popup(tint.id, if tint.rect.is_empty() { bar.rect } else { tint.rect });
409 }
410 if ui.popover(tint.id) {
411 ui.label("The colour that stands out");
412 ui.color_picker(&mut app.tint);
413 ui.close();
414 }
415}
416
417fn table(app: &mut App, ui: &mut Ui) {
422 let t = ui.theme;
423 ui.row().pad((14.0, 8.0)).gap(12.0).open();
424 let summary = format!(
426 "{} files, {} picked. Click a heading to sort by it and drag its edge; the arrows, Control and Shift pick rows; F2 or two clicks change a cell; Control+C copies, Control+V pastes from a spreadsheet, Control+Z undoes.",
427 app.files.len(),
428 app.selection.len()
429 );
430 ui.el().w(Length::Grow(1.0)).text(&summary, t.small_font, t.text_dim).wrap().show();
431 let mut freeze_first = app.table.frozen > 0;
432 if ui.checkbox(&mut freeze_first, "Keep the first column in view").changed {
433 app.table.frozen = freeze_first as usize;
434 }
435 ui.close();
436 let table = ui.table(&mut app.table, &COLUMNS);
437 if table.changed {
438 sort(app);
439 }
440 let files = &app.files;
443 let shown = |row: usize, column: usize| [files[row].0.clone(), format!("{} KB", files[row].1), files[row].2.to_string()][column].clone();
444 for change in ui.cell_changes(&table, &COLUMNS, shown) {
445 let file = &mut app.files[change.row];
446 match change.value {
447 CellValue::Text(name) => file.0 = name,
448 CellValue::Number(size) => file.1 = size.clamp(0.0, u32::MAX as f64) as u32,
449 CellValue::Choice(kind) => file.2 = KINDS[kind],
450 }
451 }
452 let (files, selection) = (&app.files, &app.selection);
454 ui.copy_rows(&table, selection.iter().map(|row| [files[row].0.clone(), files[row].1.to_string(), files[row].2.to_string()]));
455 for row in ui.rows(app.files.len(), 24.0) {
456 if ui.selectable_row(row, app.selection.contains(row)).clicked {
457 app.selection.click(row, ui.mods());
458 }
459 let (name, size, kind) = &app.files[row];
460 ui.cell(name);
461 ui.cell(&format!("{size} KB"));
462 ui.cell(kind);
463 ui.note("what does not fit its column is cut off there");
464 ui.close();
465 }
466 ui.close();
467 ui.close();
468}
469
470fn sort(app: &mut App) {
472 let by = app.table.sort.clone();
473 let one = |a: &(String, u32, &str), b: &(String, u32, &str), column: usize| match column {
474 0 => a.0.cmp(&b.0),
475 1 => a.1.cmp(&b.1),
476 _ => a.2.cmp(b.2),
477 };
478 let order = |a: &(String, u32, &str), b: &(String, u32, &str)| by.iter().map(|(column, down)| if *down { one(b, a, *column) } else { one(a, b, *column) }).find(|way| way.is_ne());
479 app.files.sort_by(|a, b| order(a, b).unwrap_or(std::cmp::Ordering::Equal));
480 app.selection.clear();
481}
482
483fn second_window(app: &mut App, ui: &mut Ui) {
486 if !ui.window(&mut app.beside, "taut gallery: a second window") {
487 return;
488 }
489 ui.column().pad(14.0).gap(10.0).open();
490 dim_text(ui, "A second window. What is set here is set in the first one too.");
491 ui.switch(&mut app.light, "Light colours");
492 ui.slider(&mut app.level, 50.0..=100.0);
493 ui.text_box(&mut app.name, "The name of the first window");
494 if ui.button("Close this window").clicked {
495 ui.quit();
496 }
497 ui.close();
498 ui.close();
499}
500
501fn tools_panel(app: &mut App, ui: &mut Ui) {
504 if !ui.panel(&mut app.tools, "Tools") {
505 return;
506 }
507 dim_text(ui, "Moved by its title, stretched by its edges.");
508 ui.switch(&mut app.light, "Light colours");
509 ui.row().gap(10.0).open();
510 ui.label("The colour that stands out");
511 ui.color_picker(&mut app.tint);
512 ui.close();
513 ui.slider(&mut app.level, 50.0..=100.0);
514 ui.close();
515}
516
517fn list(app: &mut App, ui: &mut Ui) {
518 let (t, room) = (ui.theme, if app.room == 0 { 5.0 } else { 1.0 });
519 ui.column().grow().scroll().pad(10.0).gap(6.0).open();
520 ui.checkbox(&mut app.ticked, "A tick box, which the keyboard can reach with Tab and flip with Space");
521 ui.paragraph("A paragraph breaks into as many lines as the width of the window needs. Under it is a box for several lines of text, then a list that scrolls.");
522 ui.check_spelling(None);
524 ui.text_area(&mut app.notes, "Notes", (2, 6));
525 for i in (0..60).filter(|i| format!("item {i}").contains(app.filter.as_str())) {
528 if i % 10 == 0 || !format!("item {}", i - 1).contains(app.filter.as_str()) {
529 ui.row().key(("heading", i / 10)).pad((4.0, 4.0)).fill(t.bg).sticky().open();
530 ui.el().text(&format!("Items {} to {}", i / 10 * 10, i / 10 * 10 + 9), t.small_font, t.text_dim).show();
531 ui.close();
532 }
533 ui.row().key(i).gap(8.0).pad((10.0, room)).fill(t.panel).radius(6.0).open();
534 ui.icon(PAGE);
535 ui.label(&format!("item {i}"));
536 ui.note("a note");
537 ui.spacer();
538 ui.note(&format!("{} KB", 2 + i * 7 % 40));
539 ui.icon_button(MORE, "A button that is only an icon says what it does here");
540 ui.close();
541 }
542 ui.close();
543}
544
545fn parts(app: &mut App, ui: &mut Ui) {
546 let t = ui.theme;
547 ui.column().grow().scroll().pad(14.0).gap(10.0).open();
548 ui.switch(&mut app.light, "Light colours");
549 ui.switch(&mut app.on, "A switch slides over when it is flipped");
550 if ui.fold(&mut app.folded_open, "A heading that folds away what is under it") {
551 ui.radio(&mut app.second, false, "One choice");
552 ui.radio(&mut app.second, true, "Or the other, never both");
553 ui.row().gap(10.0).open();
554 ui.label("A slider");
555 ui.el().w(Length::Px(220.0)).open();
556 ui.slider(&mut app.level, 50.0..=100.0);
557 ui.close();
558 ui.label(&format!("at {:.0}", app.level));
559 ui.close();
560 ui.progress((app.level - 50.0) / 50.0);
561 }
562 ui.separator();
563 ui.row().gap(10.0).open();
565 ui.toggle(&mut app.bold, "Bold");
566 ui.icon_toggle(&mut app.starred, STAR, "A button that stays down while it is on");
567 ui.segmented(&mut app.span, &["Day", "Week", "Month"]);
568 ui.switch(&mut app.busy, "Busy");
569 if app.busy {
570 ui.spinner();
571 }
572 ui.close();
573 ui.row().gap(10.0).open();
574 ui.label("A span");
575 ui.el().w(Length::Px(220.0)).open();
576 ui.range(&mut app.from, &mut app.to, 0.0..=100.0);
577 ui.close();
578 ui.label(&format!("from {:.0} to {:.0}", app.from, app.to));
579 ui.close();
580 ui.wrapping_row().w(Length::Px(420.0)).open();
582 ui.words("Words of ", t.font, t.text);
583 ui.words("several kinds ", if app.bold { t.font.bold() } else { t.font }, t.accent);
584 ui.words("break into lines together, and a ", t.font, t.text);
585 app.followed += ui.link("link").clicked as u32;
586 ui.words(&format!(" among them is pressed: {} times so far.", app.followed), t.font, t.text_dim);
587 ui.close();
588 ui.wrapping_row().w(Length::Px(420.0)).gap(6.0).line_gap(10.0).open();
591 for tag in ["layout", "drawing", "text", "tables", "menus", "docks", "scenes", "screen readers", "fonts", "pictures"] {
592 ui.el().text(tag, t.small_font, t.text_dim).pad((8.0, 3.0)).fill(t.raised).border(t.line, 1.0).radius(10.0).show();
593 }
594 ui.close();
595 ui.label("Emoji in colour, in any text: \u{1F642} \u{1F44D}\u{1F3FD} \u{1F469}\u{200D}\u{1F680} \u{2764}\u{FE0F} 2\u{FE0F}\u{20E3}");
597 ui.row().gap(10.0).open();
599 ui.el().w(Length::Px(200.0)).open();
600 ui.combo(&mut app.colour, &COLOURS);
601 ui.close();
602 ui.el().w(Length::Px(200.0)).open();
603 ui.autocomplete(&mut app.wanted, "Any colour, by name", &COLOURS);
604 ui.close();
605 ui.close();
606 ui.switch(&mut app.contrast, "High contrast");
609 ui.switch(&mut app.system, "As the system has it");
610 dim_text(ui, &system_preferences(ui));
611 ui.segmented(&mut app.spacing, &SPACINGS);
612 ui.close();
613}
614
615fn drawing(app: &mut App, ui: &mut Ui) {
617 let t = ui.theme;
618 ui.column().grow().scroll().pad(14.0).gap(12.0).open();
619 ui.note("A chart drawn by the app: a filled shape with a line over it. The slider on the Parts page changes it.");
620 wave_chart(app, ui);
621 shapes(app, ui);
622
623 ui.note("Fills that go from one colour into others: across, down, along any line, outwards. And text too long for its box.");
624 ui.row().gap(12.0).open();
625 ui.el().size(120.0, 28.0).radius(6.0).gradient_across(t.accent, t.green).show();
626 ui.el().size(120.0, 28.0).radius(6.0).gradient(t.raised, t.accent.with_alpha(0.6)).show();
627 ui.el().size(120.0, 28.0).radius(6.0).gradient_along(60.0, &[(0.0, t.red), (0.5, t.amber), (1.0, t.green)]).show();
628 ui.el().size(28.0, 28.0).radius(14.0).gradient_around(&[(0.0, t.text), (0.6, t.accent), (1.0, t.accent.with_alpha(0.0))]).show();
629 ui.el().w(Length::Px(180.0)).clip().text("Text that is too long for its box ends in dots", t.font, t.text).show();
630 ui.close();
631 ui.note("Drawings read from SVG files, sharp at any size: one in its own colours, and an icon of lines in the colour it is given. And a moving picture, read from a GIF file, which plays while it is asked to.");
632 if app.drawings.is_none() {
633 app.drawings = ui.add_drawing(include_str!("../tests/pictures/logo.svg")).zip(ui.add_drawing(include_str!("../tests/pictures/lines.svg")));
634 app.animation = ui.add_animation(include_bytes!("../tests/pictures/moving.gif"));
635 }
636 ui.row().gap(16.0).open();
637 if let Some((logo, lines)) = app.drawings {
638 ui.el().drawing(logo, t.text).size(135.0, 90.0).show();
639 ui.el().drawing(lines, t.text).size(16.0, 16.0).show();
640 ui.el().drawing(lines, t.accent).size(32.0, 32.0).show();
641 ui.el().drawing(lines, t.text).size(64.0, 64.0).show();
642 }
643 ui.toggle(&mut app.playing, "Play");
645 if let Some(animation) = app.animation.filter(|_| app.playing) {
646 ui.el().animation(animation).size(96.0, 64.0).show();
647 }
648 ui.close();
649 ui.note("A picture made of pixels, shown larger than it is; and a grid, whose columns line up.");
650 let picture = *app.picture.get_or_insert_with(|| ui.add_picture(16, (0..256u32).map(|i| 0xff00_0080 | (i % 16 * 17) << 16 | (i / 16 * 17) << 8).collect()));
652 let photo = app.photo.or_else(|| ui.add_picture_file(include_bytes!("../tests/pictures/plain.jpg")));
654 app.photo = photo;
655 ui.row().gap(16.0).align(Align::Start, Align::Start).open();
656 ui.el().picture(picture).size(96.0, 96.0).show();
657 if let Some(photo) = photo {
658 ui.el().picture(photo).size(134.0, 90.0).show();
659 }
660 ui.grid(2).w(Length::Px(340.0)).gap(8.0).align(Align::Start, Align::Center).open();
661 ui.label("Name");
662 ui.text_box(&mut app.name, "Name");
663 ui.label("Where it is kept");
664 ui.text_box(&mut app.place, "A folder");
665 ui.label("Rows");
666 ui.select(&mut app.room, &["Roomy", "Tight"]);
667 ui.close();
668 ui.close();
669 ui.close();
670}
671
672fn wave_chart(app: &App, ui: &mut Ui) {
675 let t = ui.theme;
676 let (wide, high, waves) = (600.0, 150.0, (app.level - 40.0) / 10.0);
677 let points: Vec<(f32, f32)> = (0..=120)
678 .map(|step| {
679 let x = step as f32 * wide / 120.0;
680 (x, high / 2.0 - (x / wide * waves * std::f32::consts::TAU).sin() * (high / 2.0 - 12.0) * (1.0 - x / wide * 0.6))
681 })
682 .collect();
683 let (mut line, mut area) = (Path::new(), Path::new());
685 line.smooth_through(&points);
686 area.move_to(0.0, high).smooth_through(&points).line_to(wide, high).close();
687 ui.el().flow(Flow::Stack).size(wide, high).fill(t.panel).radius(6.0).clip().open();
688 ui.el().size(wide, high).shape(&area, t.accent.with_alpha(0.2)).show();
689 ui.el().size(wide, high).outline(&line, 2.0, t.accent).show();
690 ui.el().size(10.0, 10.0).radius(5.0).fill(t.amber).offset(wide - 30.0, 14.0).show();
691 ui.close();
692}
693
694fn shapes(app: &mut App, ui: &mut Ui) {
697 let t = ui.theme;
698 ui.note("Lines under pens of every kind: ends cut off, square or round, corners to a point, cut across or round, dashes and dots. Below, shapes of the app's own: a pie, a star the slider on the Parts page turns, a ring, a box with corners of their own, and a line between them with an arrow at its end. A click picks the shape it falls on.");
699 let pens = [
700 Pen::new(5.0).cap(Cap::Flat).join(Join::Mitre(4.0)),
701 Pen::new(5.0).cap(Cap::Square).join(Join::Bevel),
702 Pen::new(5.0),
703 Pen::new(3.0).cap(Cap::Flat).join(Join::Mitre(4.0)).dashes(&[8.0, 4.0], 0.0),
704 Pen::new(4.0).dashes(&[0.0, 9.0], 0.0),
705 ];
706 let zigzag = Path::new().move_to(6.0, 34.0).line_to(26.0, 8.0).line_to(46.0, 34.0).line_to(66.0, 8.0).clone();
707 ui.row().gap(12.0).open();
708 for (nth, pen) in pens.into_iter().enumerate() {
709 ui.el().size(72.0, 42.0).outline(&zigzag, pen, Color::series(nth, t.bg)).show();
710 }
711 ui.close();
712 let mut drawn: Vec<(Path, Paint)> = Vec::new();
714 let slices = [0.4, 0.25, 0.2, 0.15];
715 let mut from = -90.0;
716 for share in slices {
717 drawn.push((Path::new().move_to(80.0, 80.0).arc(80.0, 80.0, 60.0, from, share * 360.0).close().clone(), Paint::Color(Color::series(drawn.len(), t.panel))));
718 from += share * 360.0;
719 }
720 let turn = Transform::new().rotate(app.level * 3.6).translate(240.0, 80.0);
721 let star = Path::new().star(0.0, 0.0, 55.0, 22.0, 5).transform(turn).clone();
722 let (along, around) = ([(0.0, t.accent), (1.0, t.green)], [(0.0, t.amber), (1.0, t.red)]);
723 drawn.push((star, Paint::Linear(90.0, &along)));
724 drawn.push((Path::new().circle(390.0, 80.0, 50.0).add(Path::new().circle(390.0, 80.0, 24.0).reverse()).clone(), Paint::Radial(&around)));
725 drawn.push((Path::new().rounded_rect(470.0, 30.0, 110.0, 100.0, (28.0, 4.0, 28.0, 4.0)).clone(), Paint::Color(t.raised)));
726 let wire = Path::new().move_to(140.0, 145.0).cubic_to(260.0, 175.0, 420.0, 120.0, 520.0, 140.0).clone();
727 let (end, way) = wire.point_at(wire.length()).unwrap_or((Point::default(), 0.0));
728 let arrow = Path::svg("M0 0-12-6-12 6Z").transform(Transform::new().rotate(way).translate(end.x, end.y)).clone();
729 let (wide, high) = (600.0, 170.0);
731 let area = ui.el().flow(Flow::Stack).size(wide, high).fill(t.panel).radius(6.0).clip().sense().open();
732 if let Some(at) = ui.pointer().filter(|_| area.clicked) {
733 let at = Point { x: at.x - area.rect.x, y: at.y - area.rect.y };
734 let on_wire = wire.distance(at) <= 6.0;
735 app.shape = if on_wire { Some(drawn.len()) } else { drawn.iter().rposition(|(shape, _)| shape.contains(at)) };
736 }
737 for (shape, ink) in &drawn {
738 ui.el().size(wide, high).shape(shape, *ink).show();
739 }
740 let selected = app.shape == Some(drawn.len());
741 ui.el().size(wide, high).outline(&wire, if selected { 4.0 } else { 2.0 }, t.text_dim).show();
742 ui.el().size(wide, high).shape(&arrow, t.text_dim).show();
743 if let Some((shape, _)) = app.shape.and_then(|nth| drawn.get(nth)) {
745 ui.el().size(wide, high).outline(shape, Pen::new(2.0).cap(Cap::Flat).dashes(&[6.0, 4.0], 0.0), t.text).show();
746 }
747 ui.close();
748}
749
750fn docks(app: &mut App, ui: &mut Ui) {
754 ui.dock(&mut app.dock);
755 for (name, closes) in PANELS {
756 let shows = if closes { ui.docked_closable(&mut app.dock, name) } else { ui.docked(&mut app.dock, name) };
757 if !shows {
758 continue;
759 }
760 if name == "Files" {
761 folders(app, ui);
762 } else {
763 ui.label(name);
764 dim_text(
765 ui,
766 "Carry a tab along its strip to put it elsewhere among the tabs, or away to another place, and let it go on a mark. Let go anywhere else, the panel floats; a double press on a tab does that too, and one on the title of a panel that floats puts it back.",
767 );
768 dim_text(ui, "The button at the end of the tabs has the panel fill the dock. Control+Tab goes to the next tab, Control+F6 to the next place.");
769 ui.button("Something to press");
770 }
771 ui.close();
772 }
773 ui.close();
774}
775
776fn folders(app: &mut App, ui: &mut Ui) {
779 for row in ui.tree_view(&mut app.folders, 22.0, folders_under) {
780 ui.tree_row(&mut app.folders, row);
781 ui.close();
782 }
783 ui.close();
784}
785
786fn charts(app: &mut App, ui: &mut Ui) {
790 let kinds = KINDS.map(|kind| app.files.iter().filter(|file| file.2 == kind).count() as f32);
791 ui.column().grow().scroll().pad(14.0).gap(14.0).open();
792 ui.row().gap(16.0).align(Align::Start, Align::Start).open();
793 ui.chart_view(&mut app.slices, &Chart::of(&[Series::pie("Files", &kinds)]).categories(&KINDS), 300.0, 160.0);
794 ui.chart(&Chart::of(&[Series::ring("Files", &kinds)]).categories(&KINDS), 230.0, 160.0);
795 ui.close();
796 ui.row().gap(16.0).align(Align::Start, Align::Start).open();
797 let (read, written) = ([3.0, 5.0, 2.0, 6.0, 4.0, 1.0, 2.0], [1.0, 2.0, 4.0, 1.0, 3.0, 2.0, 0.5]);
798 ui.chart(&Chart::of(&[Series::bars("Read", &read), Series::bars("Written", &written)]).categories(&DAYS).stacked(), 300.0, 190.0);
799 dim_text(ui, "The wheel zooms the scatter, dragging moves it, two clicks show all of it again; its names switch its rows off and on.");
800 ui.close();
801 let [small_at, small, large_at, large] = &app.dots;
802 let small: Vec<f32> = small_at.iter().zip(small).map(|(at, chance)| at * 0.5 + chance / 5.0).collect();
804 let large: Vec<f32> = large_at.iter().zip(large).map(|(at, chance)| 30.0 + at * 0.6 + chance / 4.0).collect();
805 let dots = [Series::points("Small", &small).at(small_at), Series::points("Large", &large).at(large_at)];
806 ui.chart_view(&mut app.view, &Chart::of(&dots), 560.0, 220.0);
807 ui.toggle(&mut app.live, "Live");
809 let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0.0, |since| since.as_secs_f64());
810 if app.live && now - app.fed >= 0.1 {
811 let next = app.load.last().copied().unwrap_or(0.5) + ((now * 7.3).sin() * 0.08) as f32;
812 app.load.remove(0);
813 app.load.push(next.clamp(0.0, 1.0));
814 app.fed = now;
815 }
816 if app.live {
817 ui.wake_after(std::time::Duration::from_millis(100));
818 }
819 ui.chart(&Chart::of(&[Series::area("Load", &app.load)]).x_range(-59.9, 0.0).y_range(0.0, 1.0).time(app.fed), 560.0, 160.0);
820 ui.close();
821}
822
823fn folders_under(under: Option<usize>) -> Vec<TreeItem> {
827 match under {
828 None => (0..1000).map(|n| TreeItem::with_children(n, format!("Folder {n:03}"))).collect(),
829 Some(top) if top < 1000 => {
830 let inner = (0..2).map(|n| TreeItem::with_children(1000 + top * 2 + n, format!("Inner {n}")));
831 inner.chain((0..98).map(|n| TreeItem::new(10_000 + top * 100 + n, format!("file {n:02}.txt")))).collect()
832 }
833 Some(inner) if inner < 10_000 => (0..5).map(|n| TreeItem::new(1_000_000 + inner * 5 + n, format!("deep {n}.txt"))).collect(),
834 Some(_) => Vec::new(),
835 }
836}
837
838fn web_widgets(app: &mut App, ui: &mut Ui) {
840 ui.column().grow().pad(14.0).scroll().open();
841 ui.column().max(640.0, f32::INFINITY).gap(14.0).open();
842 navigation(app, ui);
843 tags_and_people(app, ui);
844 cards_and_groups(app, ui);
845 ui.close();
846 ui.close();
847}
848
849fn navigation(app: &mut App, ui: &mut Ui) {
852 if app.banner {
853 app.banner = !ui.banner(Severity::Info, "The parts every web page and phone app has. This strip goes with its cross.").clicked;
854 ui.close();
855 }
856 if let Some(place) = ui.breadcrumbs(&["Home", "Pictures", "Holidays", "2026", "Mountains"]) {
857 ui.notice(&format!("Gone back to place {}", place + 1));
858 }
859 ui.steps(&mut app.step, &["Account", "Address", "Payment", "Done"]);
860 ui.row().gap(8.0).open();
862 ui.set_enabled(app.step > 0);
863 app.step -= ui.button("Back").clicked as usize;
864 ui.set_enabled(app.step < 3);
865 app.step += ui.primary_button("Next").clicked as usize;
866 ui.set_enabled(true);
867 ui.close();
868 ui.pagination(&mut app.results, 24);
869 ui.row().gap(8.0).open();
870 ui.search(&mut app.query, "Search the pictures");
871 let save = ui.split_button("Save");
872 if save.clicked {
873 ui.notice("Saved");
874 }
875 if ui.menu(save.id) {
876 if ui.menu_item("Save as\u{2026}").clicked {
877 ui.notice("Saved under another name");
878 }
879 if ui.menu_item("Save a copy").clicked {
880 ui.notice("A copy was saved");
881 }
882 ui.close();
883 }
884 ui.close();
885}
886
887fn tags_and_people(app: &mut App, ui: &mut Ui) {
889 let t = ui.theme;
890 ui.tag_input(&mut app.topics, &mut app.topic, "Topics: Enter or a comma after each");
891 if app.topics.is_empty() {
893 ui.column().pad(16.0).gap(8.0).align(Align::Start, Align::Center).open();
894 ui.el().icon(STAR, 32.0, t.text_faint).show();
895 ui.label("No topics yet");
896 if ui.button("Add a few").clicked {
897 app.topics = vec!["mountains".into(), "lakes".into()];
898 }
899 ui.close();
900 }
901 ui.row().gap(10.0).open();
902 ui.rating(&mut app.stars, 5, 0.5);
903 ui.note(&format!("{} of 5", app.stars));
904 ui.close();
905 let face = face(app, ui);
907 ui.row().gap(8.0).open();
908 ui.avatar("Ada Lovelace", Some(face), 36.0);
909 for name in ["Grace Hopper", "Alan Turing", "Katherine Johnson"] {
910 ui.avatar(name, None, 36.0);
911 }
912 ui.el().w(Length::Px(8.0)).show();
913 ui.el().flow(Flow::Stack).open();
914 ui.icon_button(BELL, "Notices, 3 new");
915 let badge = ui.el().place((Align::End, Align::Start)).offset(6.0, -6.0).min(16.0, 16.0).pad((4.0, 0.0)).radius(8.0).fill(t.red);
916 badge.text("3", t.small_font, t.on_accent).text_align(Align::Center).show();
917 ui.close();
918 ui.close();
919}
920
921fn cards_and_groups(app: &mut App, ui: &mut Ui) {
924 let t = ui.theme;
925 ui.row().gap(10.0).align(Align::Start, Align::Start).open();
927 for (number, (name, words)) in [("Mountains", "A walk of four hours, with a lake at the top."), ("The sea", "Two days along the coast, from bay to bay.")].into_iter().enumerate() {
928 let card = ui.card();
929 ui.text(name, t.font.bold(), t.text);
930 dim_text(ui, words);
931 ui.toggle(&mut app.liked[number], "Liked");
932 ui.close();
933 if card.clicked {
934 ui.notice(&format!("Opened \u{201c}{name}\u{201d}"));
935 }
936 }
937 ui.close();
938 ui.switch(&mut app.loading, "Show what stands in while something loads");
939 if app.loading {
940 ui.row().gap(10.0).open();
941 ui.skeleton().size(40.0, 40.0).radius(20.0).show();
942 ui.column().w(Length::Grow(1.0)).gap(8.0).open();
943 ui.skeleton().show();
944 ui.skeleton().w(Length::Px(160.0)).show();
945 ui.close();
946 ui.close();
947 }
948 let styles = ui.row().place((Align::Start, Align::Center)).pad(2.0).gap(2.0).fill(t.panel).border(t.line, 1.0).radius(t.radius).open();
950 ui.tell(&styles, Role::Group, None, "Text style");
951 for (on, name) in app.styles.iter_mut().zip(["Bold", "Italic", "Underline"]) {
952 ui.toggle(on, name);
953 }
954 ui.close();
955 for (number, (title, words)) in [("What it is", "A page of the parts people know."), ("How it goes", "Each part is one call.")].into_iter().enumerate() {
957 let mut open = app.section == Some(number);
958 if ui.fold(&mut open, title) {
959 dim_text(ui, words);
960 }
961 app.section = if open { Some(number) } else { app.section.filter(|was| *was != number) };
962 }
963 ui.row().gap(8.0).open();
964 ui.label("Find");
965 ui.shortcut("Ctrl+F");
966 ui.el().w(Length::Px(12.0)).show();
967 ui.label("Commands");
968 ui.shortcut("Ctrl+K");
969 ui.close();
970 if !app.banner && ui.link("Show the banner again").clicked {
971 app.banner = true;
972 }
973}
974
975fn dim_text(ui: &mut Ui, text: &str) {
977 let t = ui.theme;
978 ui.el().w(Length::Grow(1.0)).text(text, t.small_font, t.text_dim).wrap().show();
979}
980
981fn more_parts(app: &mut App, ui: &mut Ui) {
983 let wave: Vec<f32> = (0..48).map(|i| (i as f32 * std::f32::consts::PI / 8.0).sin() * app.amount).collect();
986 ui.column().grow().scroll().open();
987 ui.row().pad(14.0).gap(28.0).align(Align::Start, Align::Start).open();
988 rows_tree_and_chart(app, ui, &wave);
989 numbers_and_plots(app, ui, &wave);
990 form_parts(app, ui);
991 ui.close();
992 parts_by_other_names(app, ui);
993 code_and_inspector(app, ui);
994 ui.close();
995}
996
997fn rows_tree_and_chart(app: &mut App, ui: &mut Ui, wave: &[f32]) {
999 ui.column().w(Length::Px(240.0)).gap(2.0).open();
1000 dim_text(ui, "Rows to pick. Right-click one for a menu.");
1001 for (number, name) in ["Inbox", "Drafts", "Sent", "Archive"].iter().enumerate() {
1002 let row = ui.selectable(app.selected_row == number, name);
1003 if row.clicked {
1004 app.selected_row = number;
1005 }
1006 if ui.context_menu(&row) {
1007 if ui.menu_item("Pick this one").clicked {
1008 app.selected_row = number;
1009 }
1010 ui.menu_item("Leave it");
1011 ui.close();
1012 }
1013 }
1014 ui.tree(&mut app.tree_open[0], "A tree");
1015 if app.tree_open[0] {
1016 ui.label("A leaf");
1017 ui.tree(&mut app.tree_open[1], "A branch");
1018 if app.tree_open[1] {
1019 ui.label("A leaf, a step further in");
1020 ui.close();
1021 }
1022 ui.close();
1023 }
1024 let half: Vec<f32> = wave.iter().map(|value| value / 2.0).collect();
1026 ui.el().h(Length::Px(10.0)).show();
1027 ui.chart(&Chart::of(&[Series::area("Wave", wave).smooth(), Series::line("Half", &half).smooth()]), 240.0, 150.0);
1028 ui.close();
1029}
1030
1031fn numbers_and_plots(app: &mut App, ui: &mut Ui, wave: &[f32]) {
1034 ui.column().w(Length::Px(290.0)).gap(10.0).open();
1035 ui.row().gap(10.0).open();
1036 ui.label("A number to drag sideways");
1037 ui.drag_value(&mut app.amount, 0.1);
1038 ui.close();
1039 dim_text(ui, "A wave as tall as that number, as a line and as bars.");
1040 ui.plot_lines(wave, 290.0, 60.0);
1041 ui.plot_bars(&wave[..18], 290.0, 60.0);
1042 ui.checkbox(&mut app.off, "Switch the two parts under this off");
1043 ui.set_enabled(!app.off);
1044 ui.row().gap(12.0).open();
1045 ui.button("A button");
1046 ui.switch(&mut app.on, "A switch");
1047 ui.close();
1048 ui.set_enabled(true);
1049 dim_text(ui, "A slider that stops at steps, and one that goes by a curve: half way is 100%.");
1050 ui.slider_marked(&mut app.marked, 0.0..=10.0, 1.0, "");
1051 ui.slider_curved(&mut app.zoom, 25.0..=400.0, "%");
1052 ui.close();
1053}
1054
1055fn form_parts(app: &mut App, ui: &mut Ui) {
1058 ui.column().w(Length::Px(250.0)).gap(10.0).open();
1059 ui.row().gap(10.0).open();
1060 ui.label("A number to type");
1061 ui.number_in(&mut app.count, 0..=99, 1, "copies");
1062 ui.close();
1063 ui.row().gap(10.0).open();
1064 ui.label("A colour to pick");
1065 ui.color_picker(&mut app.tint);
1066 ui.close();
1067 ui.row().gap(10.0).open();
1068 ui.label("A day to pick");
1069 ui.date(&mut app.day);
1070 ui.close();
1071 dim_text(ui, "Things to carry from one box to the other.");
1072 ui.row().gap(10.0).align(Align::Start, Align::Start).open();
1073 drag_list(app, ui, 0);
1074 drag_list(app, ui, 1);
1075 ui.close();
1076 dim_text(ui, "A time, a day and a time, and a span of days picked in one calendar.");
1077 ui.row().gap(10.0).open();
1078 ui.time(&mut app.alarm, false);
1079 ui.close();
1080 ui.row().gap(10.0).open();
1081 ui.date_time(&mut app.meeting.0, &mut app.meeting.1);
1082 ui.close();
1083 ui.row().gap(10.0).open();
1084 ui.date_range(&mut app.away.0, &mut app.away.1);
1085 ui.close();
1086 let here = format!("{} · {} · {}", ui.format_number(1_234_567.5, 1), ui.format_date(app.day), ui.format_time(app.alarm, false));
1089 dim_text(ui, &here);
1090 let recent = ui.recent_colors().to_string();
1091 if !recent.is_empty() {
1092 dim_text(ui, &format!("Kept: {recent}"));
1093 }
1094 #[cfg(feature = "translations")]
1096 languages(ui);
1097 ui.close();
1098}
1099
1100#[cfg(feature = "translations")]
1102fn languages(ui: &mut Ui) {
1103 ui.wrapping_row().gap(6.0).open();
1104 for (name, code) in [("Deutsch", "de"), ("Español", "es"), ("Français", "fr"), ("日本語", "ja"), ("Português", "pt"), ("中文", "zh")] {
1105 if ui.button(name).clicked {
1106 ui.translate(code);
1107 }
1108 }
1109 ui.close();
1110}
1111
1112fn parts_by_other_names(app: &mut App, ui: &mut Ui) {
1116 ui.row().pad((14.0, 0.0, 14.0, 14.0)).gap(28.0).align(Align::Start, Align::Start).open();
1117 ui.column().w(Length::Px(290.0)).gap(10.0).open();
1118 ui.row().gap(10.0).open();
1119 ui.button_with_icon(SYNC, "Refresh");
1120 let face = face(app, ui);
1121 ui.button_with_picture(face, "Ada");
1122 ui.close();
1123 ui.slider_with_value(&mut app.level, 50.0..=100.0, "%");
1124 ui.progress_with_percent((app.level - 50.0) / 50.0);
1125 ui.grid(2).gap(10.0).align(Align::Start, Align::Center).open();
1126 ui.label("From 0 to 10");
1127 ui.drag_value_in(&mut app.within, 0.0..=10.0, 0.05);
1128 ui.label("A fruit");
1129 ui.select_value(&mut app.fruit, &[("apple", "Apple"), ("pear", "Pear"), ("plum", "Plum")]);
1130 ui.close();
1131 ui.close();
1132 ui.column().w(Length::Px(290.0)).gap(10.0).open();
1133 let t = ui.theme;
1134 ui.grid(2).gap(12.0).line_gap(4.0).pad(4.0).stripes(t.panel).radius(4.0).open();
1135 for (name, size) in [("notes.txt", "2 KB"), ("photo.png", "3.1 MB"), ("song.ogg", "4.6 MB"), ("todo.md", "1 KB")] {
1136 ui.el().w(Length::Grow(1.0)).text(name, t.font, t.text).show();
1137 ui.note(size);
1138 }
1139 ui.close();
1140 ui.checkbox(&mut app.faint, "Draw the row under this faint");
1141 ui.row().gap(10.0).opacity(if app.faint { 0.4 } else { 1.0 }).open();
1142 ui.button("Not yet");
1143 ui.switch(&mut app.on, "Ready");
1144 ui.close();
1145 ui.checkbox(&mut app.hide, "Hide the middle button");
1146 ui.row().gap(10.0).open();
1147 ui.button("Left");
1148 ui.el().hidden(app.hide).open();
1149 ui.button("Middle");
1150 ui.close();
1151 ui.button("Right");
1152 ui.close();
1153 ui.close();
1154 ui.close();
1155}
1156
1157fn code_and_inspector(app: &mut App, ui: &mut Ui) {
1160 ui.row().h(Length::Px(320.0)).pad((14.0, 0.0, 14.0, 14.0)).gap(14.0).open();
1161 ui.column().grow().open();
1162 ui.code_editor(&mut app.code, "The gallery's source");
1163 ui.close();
1164 ui.column().w(Length::Px(300.0)).h(Length::Grow(1.0)).open();
1165 ui.inspect(&mut app.inspector, &mut app.lamp);
1166 ui.close();
1167 ui.close();
1168}
1169
1170fn face(app: &mut App, ui: &mut Ui) -> Picture {
1172 *app.face.get_or_insert_with(|| ui.add_picture(32, (0..32 * 32).map(|at| 0xff00_0000 | (150 + at % 32 * 3) << 16 | (110 + at / 32 * 3) << 8 | 140).collect()))
1173}
1174
1175fn drag_list(app: &mut App, ui: &mut Ui, side: usize) {
1177 let t = ui.theme;
1178 let wanted = ui.drag_payload().is_some_and(|what| what as usize / 100 != side);
1179 let around = ui.column().key(side).w(Length::Px(118.0)).min(0.0, 124.0).pad(4.0).gap(2.0).fill(t.panel).border(if wanted { t.accent } else { t.line }, 1.0).radius(6.0).sense().open();
1180 for (number, &name) in app.drag_lists[side].iter().enumerate() {
1181 let thing = ui.selectable(false, name);
1182 if ui.drag_source(&thing, (side * 100 + number) as u64) {
1183 ui.label(name);
1184 ui.close();
1185 }
1186 }
1187 ui.close();
1188 let Some(what) = ui.dropped(&around).map(|what| what as usize).filter(|what| what / 100 != side) else { return };
1189 let thing = app.drag_lists[what / 100].remove(what % 100);
1190 app.drag_lists[side].push(thing);
1191}
1192
1193fn rename_dialog(app: &mut App, ui: &mut Ui) {
1195 let t = ui.theme;
1196 let Some(name) = &mut app.renaming else { return };
1197 let beside = ui.dialog();
1198 ui.text("Rename this window", t.font.bold(), t.text);
1199 ui.note("The name shows at the start of the bar, and in the window's title.");
1200 let name_box = ui.text_box(name, "Name");
1201 if ui.focus() == 0 {
1202 ui.set_focus(name_box.id); }
1204 ui.row().gap(8.0).align(Align::End, Align::Center).open();
1205 let cancel = ui.button("Cancel").clicked;
1206 let keep = ui.primary_button("Rename").clicked || ui.key(Key::Enter, Mods::NONE);
1207 ui.close();
1208 ui.close();
1209 if keep {
1210 app.name = name.clone();
1211 ui.set_title(&app.name);
1212 }
1213 if keep || cancel || beside.clicked || ui.key(Key::Escape, Mods::NONE) {
1214 app.renaming = None;
1215 ui.rerun();
1216 }
1217}
1218
1219fn chance(n: u32) -> f32 {
1221 let x = n.wrapping_mul(747_796_405).wrapping_add(2_891_336_453);
1222 let x = ((x >> ((x >> 28) + 4)) ^ x).wrapping_mul(277_803_737);
1223 ((x >> 22) ^ x) as f32 / u32::MAX as f32 * 100.0
1224}
1225
1226fn theme(app: &App, ui: &Ui) -> Theme {
1229 let theme = match (app.system, app.contrast, app.light) {
1230 (true, ..) => ui.system_theme(),
1231 (false, true, light) => Theme::high_contrast(if light { ContrastColors::LIGHT } else { ContrastColors::DARK }),
1232 (false, false, true) => Theme::light().accented(app.tint),
1233 (false, false, false) => Theme::dark().accented(app.tint),
1234 };
1235 [theme.dense(), theme, theme.roomy()][app.spacing]
1236}
1237
1238fn system_preferences(ui: &Ui) -> String {
1240 let colour = ui.system_accent().map_or("no colour of its own".into(), |colour| format!("the colour {colour}"));
1241 let (contrast, motion) = (if ui.high_contrast() { "high contrast" } else { "no high contrast" }, if ui.reduced_motion() { "less movement" } else { "movement" });
1242 format!("The system asks for {} windows, {colour}, {contrast}, {motion}, text \u{d7}{}.", if ui.system_dark() { "dark" } else { "light" }, ui.text_scale())
1243}
1244
1245pub fn app() -> App {
1247 App {
1248 name: "Gallery".into(),
1249 presses: 0,
1250 page: 0,
1251 room: 0,
1252 filter: String::new(),
1253 notes: String::new(),
1254 renaming: None,
1255 light: false,
1256 contrast: false,
1257 system: false,
1258 spacing: 1,
1259 ticked: false,
1260 on: true,
1261 folded_open: true,
1262 second: false,
1263 level: 72.0,
1264 bold: false,
1265 starred: true,
1266 span: 1,
1267 busy: false,
1268 from: 20.0,
1269 to: 70.0,
1270 followed: 0,
1271 finding: false,
1272 colour: 6,
1273 wanted: String::new(),
1274 picture: None,
1275 photo: None,
1276 drawings: None,
1277 animation: None,
1278 playing: false,
1279 letters: std::env::var_os("TAUT_FONT").and_then(|file| std::fs::read(file).ok()).and_then(FontFile::read),
1281 place: String::new(),
1282 shape: None,
1283 selected_row: 1,
1284 tree_open: [true, true],
1285 amount: 4.0,
1286 off: true,
1287 count: 12,
1288 day: Date::today(),
1289 alarm: Time::new(7, 30, 0),
1290 meeting: (Date::today(), Time::new(14, 0, 0)),
1291 away: (Date::today(), Date::from_days(Date::today().days() + 6)),
1292 marked: 3.0,
1293 zoom: 100.0,
1294 within: 2.5,
1295 fruit: "pear",
1296 faint: true,
1297 hide: false,
1298 tint: Theme::dark().accent,
1299 drag_lists: [vec!["Apples", "Pears", "Plums"], vec!["Bread"]],
1300 table: Table { frozen: 1, ..Default::default() },
1301 selection: Selection::default(),
1302 files: (0..5000u32).map(|n| (format!("file {n:04}"), n * 7919 % 4096 + 1, ["text", "picture", "sound", "folder"][n as usize * 5 % 4])).collect(),
1303 tools: Panel { open: false, ..Panel::new(520.0, 150.0, 300.0, 220.0) },
1304 code: CodeEditor::new(include_str!("gallery.rs"), &Syntax::RUST),
1305 lamp: Lamp { name: "Desk".into(), power: 40.0, on: true, kind: LampKind::Spot, tint: Color::rgb(0xffcf7a), rooms: vec!["Study".into(), "Hall".into()] },
1306 inspector: Inspector::default(),
1307 beside: SecondWindow { open: false, ..SecondWindow::new(380.0, 240.0) },
1308 file_dialog: FileDialog::default(),
1309 dock: Dock::of(&["Files"]).beside(Dock::of(&["Editor", "Preview"]).above(Dock::of(&["Log"]), 0.7), 0.25),
1310 step: 2,
1311 results: 0,
1312 query: String::new(),
1313 topics: vec!["mountains".into(), "walks".into()],
1314 topic: String::new(),
1315 stars: 3.5,
1316 face: None,
1317 liked: [true, false],
1318 loading: true,
1319 banner: true,
1320 styles: [true, false, false],
1321 section: Some(0),
1322 slices: ChartView::default(),
1323 view: ChartView::default(),
1324 dots: [0, 1, 2, 3].map(|row| (0..80u32).map(|n| chance(n + 80 * row)).collect()),
1325 live: false,
1326 load: (0..600).map(|nth| 0.5 + (nth as f32 / 40.0).sin() * 0.2).collect(),
1327 fed: std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0.0, |since| since.as_secs_f64()),
1328 folders: TreeView::default(),
1329 writing: Markdown::parse(WRITING),
1330 }
1331}
1332
1333const WRITING: &str = "# Writing
1335
1336A document read from Markdown: words in **bold**, in *slant*, in `code`, ~~struck through~~, and [links](https://commonmark.org) among them, broken into rows as wide as the room. Select any of it with the pointer or with Shift and the arrows, and copy it with Control+C. [Lists](#lists) are further down.
1337
1338## Lists
1339
1340- A point
1341- Another, with more under it:
1342 1. first
1343 2. second
1344- [x] a task that is done
1345- [ ] and one that is not
1346
1347> Quoted from elsewhere, in a quieter colour.
1348
1349```rust
1350fn main() {
1351 let words = \"coloured by the language it names\"; // and a comment
1352 println!(\"{words} {}\", 42);
1353}
1354```
1355
1356| Part | What it does | Costs |
1357|:-----|:------------:|------:|
1358| Rows | break words | a letter as a label does |
1359| Code | colours words | the lines in view |
1360
1361---
1362
1363Only what is in view is described: a long document costs what a screenful of it does.
1364";
1365
1366fn writing(app: &mut App, ui: &mut Ui) {
1369 let t = ui.theme;
1370 ui.column().grow().scroll().pad(14.0).open();
1371 ui.column().max(680.0, f32::INFINITY).gap(14.0).open();
1372 let pieces = [
1373 Span::text("A paragraph of rich text: "),
1374 Span::text("bold").bold(),
1375 Span::text(", "),
1376 Span::text("slanted").italic(),
1377 Span::text(", "),
1378 Span::text("larger").size(t.font.size * 1.4),
1379 Span::text(", in "),
1380 Span::text("colour").color(t.green),
1381 Span::text(", "),
1382 Span::text("marked").background(t.amber.with_alpha(0.35)),
1383 Span::text(", "),
1384 Span::text("code").code(),
1385 Span::text(", "),
1386 Span::icon(STAR),
1387 Span::text(" an icon, and "),
1388 Span::text("a link").link(),
1389 Span::text("."),
1390 ];
1391 if ui.rich(&pieces).is_some() {
1392 ui.notice("The link was pressed");
1393 }
1394 ui.separator();
1395 if let Some(link) = ui.markdown(&app.writing) {
1396 ui.notice(&format!("A link to {link}"));
1397 }
1398 if cfg!(feature = "brahmic") {
1400 ui.separator();
1401 SYLLABLES.iter().for_each(|line| _ = ui.label(line));
1402 }
1403 ui.close();
1404 ui.close();
1405}
1406
1407const SYLLABLES: [&str; 15] = [
1410 "हिन्दी: नमस्ते दुनिया, क्षमा और धर्म",
1411 "বাংলা: আমি বাংলায় কথা বলি",
1412 "ਪੰਜਾਬੀ: ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ",
1413 "ગુજરાતી: કેમ છો? શ્રી ગણેશ",
1414 "ଓଡ଼ିଆ: ନମସ୍କାର, ଭୁବନେଶ୍ୱର",
1415 "தமிழ்: வணக்கம், கொண்டு",
1416 "తెలుగు: నమస్కారం, శ్రీ",
1417 "ಕನ್ನಡ: ನಮಸ್ಕಾರ, ಕರ್ನಾಟಕ",
1418 "മലയാളം: നമസ്കാരം, കേരളം",
1419 "සිංහල: ආයුබෝවන්, ශ්රී ලංකා",
1420 "ไทย: สวัสดีครับ น้ำใจ",
1421 "ລາວ: ສະບາຍດີ",
1422 "ខ្មែរ: សួស្ដី ស្ត្រី",
1423 "မြန်မာ: မင်္ဂလာပါ",
1424 "བོད་ཡིག: བཀྲ་ཤིས་བདེ་ལེགས།",
1425];
1426
1427fn main() {
1428 let mut app = app();
1429 taut::run(Window { title: "taut gallery", width: 900.0, height: 600.0, min_width: 280.0, min_height: 220.0, ..Default::default() }, move |ui| describe(&mut app, ui));
1430}