From 776f17eae958861d0c9ef4d769efae052676b057 Mon Sep 17 00:00:00 2001 From: Lawrence Date: Wed, 2 Dec 2026 16:32:25 -0800 Subject: [PATCH] feat: the control window is drawn with Material 3 widgets from the egui-material3 fork, in Strobe's own theme colours and density (D710) Every standard control comes from the owner's freeknet fork of egui-material3, pinned to a commit and allowed as a git source in deny.toml: buttons, icon, tool and transport buttons, segmented buttons, switches, text fields, selects in place of combo boxes, number fields in place of drag values, checkboxes, tabs, menu items and dialogs. The shared helpers (widgets, form) keep their signatures and wrap the library. - ui::m3 maps each M3 colour role from the theme's palette, gives the library Strobe's density (Comfortable -3, Compact -4) and a type scale at Strobe's body size, and names a Material Symbol for every Icon. - Roboto and the outlined Material Symbols replace Segoe UI and the stroked icon set; the old painted widgets are gone. - The value bars, XY pads, meters, scene cards and preview stay Strobe's. - The editor toolbar gives its name and chips the room its actions leave; the sort select fits its longest option; the monitor select says "Not chosen"; destructive confirms are error-coloured. - xtask credits finds licence files two folders down (the fork's fonts) and skips images named "copyright". --- Cargo.lock | 160 +++++++- Cargo.toml | 2 + THIRD_PARTY.md | 6 +- crates/strobe-app/Cargo.toml | 1 + crates/strobe-app/src/desktop.rs | 13 +- crates/strobe-app/src/ui/audio.rs | 43 +- crates/strobe-app/src/ui/browser.rs | 333 ++++++---------- crates/strobe-app/src/ui/command_palette.rs | 11 +- crates/strobe-app/src/ui/controls.rs | 39 +- crates/strobe-app/src/ui/credits.rs | 3 +- crates/strobe-app/src/ui/editor.rs | 83 ++-- crates/strobe-app/src/ui/fonts.rs | 6 + crates/strobe-app/src/ui/form.rs | 76 +--- crates/strobe-app/src/ui/icon.rs | 94 +---- crates/strobe-app/src/ui/inspector.rs | 61 +-- crates/strobe-app/src/ui/m3.rs | 208 ++++++++++ crates/strobe-app/src/ui/macros.rs | 37 +- crates/strobe-app/src/ui/map.rs | 360 ++++++++--------- crates/strobe-app/src/ui/mod.rs | 1 + crates/strobe-app/src/ui/modal.rs | 176 +++------ crates/strobe-app/src/ui/playlist.rs | 32 +- crates/strobe-app/src/ui/presets.rs | 4 +- crates/strobe-app/src/ui/projectors.rs | 8 +- crates/strobe-app/src/ui/settings.rs | 183 ++++----- crates/strobe-app/src/ui/shell_tests.rs | 8 +- crates/strobe-app/src/ui/side.rs | 122 ++---- crates/strobe-app/src/ui/tags.rs | 24 +- crates/strobe-app/src/ui/theme.rs | 3 +- crates/strobe-app/src/ui/widgets.rs | 412 ++++++++------------ crates/xtask/src/credits.rs | 50 ++- deny.toml | 3 + docs/DECISIONS_BY_AREA.md | 3 +- docs/ROADMAP.md | 2 +- docs/UI_DESIGN.md | 2 +- docs/UI_REVIEW.md | 3 +- docs/decisions/D710.md | 74 ++++ 36 files changed, 1372 insertions(+), 1274 deletions(-) create mode 100644 crates/strobe-app/src/ui/m3.rs create mode 100644 docs/decisions/D710.md diff --git a/Cargo.lock b/Cargo.lock index 41760202..237a382e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,7 +128,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -139,7 +139,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -208,6 +208,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64" version = "0.23.1" @@ -745,7 +751,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -796,6 +802,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "document-features" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61" +dependencies = [ + "litrs", +] + [[package]] name = "downcast-rs" version = "1.2.1" @@ -818,6 +833,40 @@ dependencies = [ "emath", ] +[[package]] +name = "eframe" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c5642501a65ca657d05f00c643a5c14ff2346cb3818032bfe23d58e1f8e5f84" +dependencies = [ + "ahash", + "bytemuck", + "document-features", + "egui", + "egui-winit", + "egui_glow", + "glow", + "glutin", + "glutin-winit", + "image", + "js-sys", + "log", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", + "parking_lot", + "percent-encoding", + "profiling", + "raw-window-handle", + "send_wrapper", + "static_assertions", + "wasm-bindgen", + "web-sys", + "web-time", + "windows-sys 0.61.2", + "winit", +] + [[package]] name = "egui" version = "0.37.0" @@ -835,6 +884,24 @@ dependencies = [ "profiling", "smallvec", "unicode-segmentation", + "web-sys", +] + +[[package]] +name = "egui-material3" +version = "0.0.10" +source = "git+https://github.com/freeknet/egui-material3?rev=ce84fab#ce84fabb1d026f26ebc25abb3c89b665f3bace4f" +dependencies = [ + "base64 0.22.1", + "eframe", + "egui", + "hex", + "image", + "lazy_static", + "once_cell", + "serde", + "serde_json", + "ureq 2.12.1", ] [[package]] @@ -950,7 +1017,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -1536,6 +1603,7 @@ checksum = "85ab80394333c02fe689eaf900ab500fbd0c2213da414687ebf995a65d5a6104" dependencies = [ "bytemuck", "byteorder-lite", + "image-webp", "moxcms", "num-traits", "png", @@ -1544,6 +1612,16 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "image-webp" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c8d2831f3eb9706eeac62164959a288f12c047a3c53b353c6c00d5d60eb5c7f" +dependencies = [ + "byteorder-lite", + "quick-error", +] + [[package]] name = "imagesize" version = "0.15.0" @@ -1756,6 +1834,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "lazy_static" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb" + [[package]] name = "libc" version = "0.2.190" @@ -1818,6 +1902,12 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" +[[package]] +name = "litrs" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b614978e47ce529faee66579f2b2fe19c94aa96d910a6a9a8043b2b02d8175" + [[package]] name = "lock_api" version = "0.4.14" @@ -2527,7 +2617,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3116,7 +3206,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -3213,6 +3303,12 @@ version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + [[package]] name = "serde" version = "1.0.229" @@ -3459,6 +3555,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strength_reduce" version = "0.2.4" @@ -3479,9 +3581,10 @@ name = "strobe-app" version = "0.5.1" dependencies = [ "anyhow", - "base64", + "base64 0.23.1", "clap", "egui", + "egui-material3", "egui-winit", "egui_glow", "embed-resource", @@ -3589,7 +3692,7 @@ name = "strobe-forge" version = "0.5.1" dependencies = [ "anyhow", - "base64", + "base64 0.23.1", "clap", "image", "serde", @@ -3598,7 +3701,7 @@ dependencies = [ "strobe-diag", "strobe-gfx", "strobe-scene", - "ureq", + "ureq 3.5.2", ] [[package]] @@ -3729,7 +3832,7 @@ dependencies = [ "strobe-scene", "strobe-ssf-lib", "thiserror 2.0.21", - "ureq", + "ureq 3.5.2", ] [[package]] @@ -4077,20 +4180,38 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" +dependencies = [ + "base64 0.22.1", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "url", + "webpki-roots 0.26.11", +] + [[package]] name = "ureq" version = "3.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ac5cecf619ca81f66a96482db09687c9f7465af65f4300a8c30cca05bd5a59d" dependencies = [ - "base64", + "base64 0.23.1", "log", "percent-encoding", "rustls", "rustls-pki-types", "ureq-proto", "utf8-zero", - "webpki-roots", + "webpki-roots 1.0.10", ] [[package]] @@ -4099,7 +4220,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622dce33c252115466d83f63e9744a18f12b4406aae51a01c15ad8fcf1185eb3" dependencies = [ - "base64", + "base64 0.23.1", "http", "httparse", "log", @@ -4469,6 +4590,15 @@ dependencies = [ "web-sys", ] +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.10", +] + [[package]] name = "webpki-roots" version = "1.0.10" @@ -4506,7 +4636,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] @@ -4857,7 +4987,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d6f32a0ff4a9f6f01231eb2059cc85479330739333e0e58cadf03b6af2cca10" dependencies = [ "cfg-if", - "windows-sys 0.59.0", + "windows-sys 0.61.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6c81cf64..2455d211 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -141,6 +141,8 @@ web-sys = "0.3.106" egui = { version = "0.37", default-features = false, features = ["default_fonts"] } egui_glow = { version = "0.37", features = ["winit"] } egui-winit = { version = "0.37", default-features = false, features = ["links", "clipboard", "wayland", "x11"] } +# Spike: the freeknet Material 3 fork, by path (not for merging; cargo-deny would refuse the git source). +egui-material3 = { git = "https://github.com/freeknet/egui-material3", rev = "ce84fab", default-features = false } [workspace.lints.rust] warnings = "deny" diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md index 2c75aa63..3a7bc80f 100644 --- a/THIRD_PARTY.md +++ b/THIRD_PARTY.md @@ -22,7 +22,7 @@ The release zip carries these next to the program. Their notices are in `LICENSE ## Crates -Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc`), 262 in all, with the licence its authors published it under. The release zip's `THIRD-PARTY-NOTICES.txt` has each one's version and full licence text. +Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc`), 266 in all, with the licence its authors published it under. The release zip's `THIRD-PARTY-NOTICES.txt` has each one's version and full licence text. | Crate | Licence | Source | |---|---|---| @@ -77,6 +77,7 @@ Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc | dpi | Apache-2.0 AND MIT | https://github.com/rust-windowing/winit | | ecolor | MIT OR Apache-2.0 | https://github.com/emilk/egui | | egui | MIT OR Apache-2.0 | https://github.com/emilk/egui | +| egui-material3 | (MIT OR Apache-2.0) AND Apache-2.0 AND OFL-1.1 | https://github.com/nikescar/egui-material3 | | egui-winit | MIT OR Apache-2.0 | https://github.com/emilk/egui/tree/main/crates/egui-winit | | egui_glow | MIT OR Apache-2.0 | https://github.com/emilk/egui/tree/main/crates/egui_glow | | either | MIT OR Apache-2.0 | https://github.com/rayon-rs/either | @@ -112,6 +113,7 @@ Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc | harfrust | MIT | https://github.com/harfbuzz/harfrust | | hashbrown | MIT OR Apache-2.0 | https://github.com/rust-lang/hashbrown | | heck | MIT OR Apache-2.0 | https://github.com/withoutboats/heck | +| hex | MIT OR Apache-2.0 | https://github.com/KokaKiwi/rust-hex | | hmac | MIT OR Apache-2.0 | https://github.com/RustCrypto/MACs | | http | MIT OR Apache-2.0 | https://github.com/hyperium/http | | httparse | MIT OR Apache-2.0 | https://github.com/seanmonstar/httparse | @@ -126,6 +128,7 @@ Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc | idna | MIT OR Apache-2.0 | https://github.com/servo/rust-url | | idna_adapter | Apache-2.0 OR MIT | https://github.com/hsivonen/idna_adapter | | image | MIT OR Apache-2.0 | https://github.com/image-rs/image | +| image-webp | MIT OR Apache-2.0 | https://github.com/image-rs/image-webp | | indexmap | Apache-2.0 OR MIT | https://github.com/indexmap-rs/indexmap | | is_terminal_polyfill | MIT OR Apache-2.0 | https://github.com/polyfill-rs/is_terminal_polyfill | | itertools | MIT OR Apache-2.0 | https://github.com/rust-itertools/itertools | @@ -135,6 +138,7 @@ Every crate compiled into `strobe.exe` (`strobe-app` for `x86_64-pc-windows-msvc | jiff-tzdb | Unlicense OR MIT | https://github.com/BurntSushi/jiff | | jiff-tzdb-platform | Unlicense OR MIT | https://github.com/BurntSushi/jiff | | kurbo | Apache-2.0 OR MIT | https://github.com/linebender/kurbo | +| lazy_static | MIT OR Apache-2.0 | https://github.com/rust-lang-nursery/lazy-static.rs | | libc | MIT OR Apache-2.0 | https://github.com/rust-lang/libc | | libloading | ISC | https://github.com/nagisa/rust_libloading | | linebender_resource_handle | Apache-2.0 OR MIT | https://github.com/linebender/raw_resource_handle | diff --git a/crates/strobe-app/Cargo.toml b/crates/strobe-app/Cargo.toml index ec57d47d..3a99cac9 100644 --- a/crates/strobe-app/Cargo.toml +++ b/crates/strobe-app/Cargo.toml @@ -48,6 +48,7 @@ thiserror.workspace = true egui.workspace = true egui_glow.workspace = true egui-winit.workspace = true +egui-material3.workspace = true jiff.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/strobe-app/src/desktop.rs b/crates/strobe-app/src/desktop.rs index 89aa97a8..03bdf3fa 100644 --- a/crates/strobe-app/src/desktop.rs +++ b/crates/strobe-app/src/desktop.rs @@ -1199,7 +1199,7 @@ impl Controller { Stage::Reconnecting(_) => "Disconnect", Stage::Live | Stage::Ended(_) => "Return to local Strobe", }; - if ui.button(leave).clicked() { + if remote_button(ui, leave).clicked() { actions.push(crate::ui::Action::DisconnectDesktop); } }); @@ -1283,10 +1283,10 @@ impl Controller { }; let mut offer = |ui: &mut egui::Ui| { if reconnect { - if ui.button("Reconnect").clicked() { + if remote_button(ui, "Reconnect").clicked() { actions.push(crate::ui::Action::ConnectDesktop); } - } else if ui.button("Ask again").clicked() { + } else if remote_button(ui, "Ask again").clicked() { actions.push(crate::ui::Action::ConnectDesktop); } }; @@ -1483,6 +1483,13 @@ fn dimmed_image(ui: &mut egui::Ui, texture: egui::TextureId, size: [u32; 2]) { ui.add(egui::Image::new((texture, fit)).tint(egui::Color32::from_gray(70))); } +/// An outlined M3 button for the controlled-desktop view. That view has no +/// palette of its own (the widget ignores it: the palette drives the M3 +/// roles already), so the fallback stands in. +fn remote_button(ui: &mut egui::Ui, label: &str) -> egui::Response { + crate::ui::widgets::button(ui, crate::palette::fallback(), None, label) +} + /// A message card in the middle of the window, over whatever is drawn /// there, with `buttons` under the text. It is local UI: nothing in it is /// sent to the host. diff --git a/crates/strobe-app/src/ui/audio.rs b/crates/strobe-app/src/ui/audio.rs index 10348250..38d1af6d 100644 --- a/crates/strobe-app/src/ui/audio.rs +++ b/crates/strobe-app/src/ui/audio.rs @@ -70,10 +70,16 @@ pub fn show( { actions.push(Action::RefreshAudioDevices); } - egui::ComboBox::from_id_salt("audio-input") - .width(ui.available_width().min(PICKER_WIDTH)) - .selected_text(choice_label(audio.choice, audio.devices)) - .show_ui(ui, |ui| input_choices(ui, audio, actions)); + let choices = input_choices(audio); + let options: Vec<(DeviceChoice, &str)> = choices + .iter() + .map(|(choice, label)| (choice.clone(), label.as_str())) + .collect(); + let mut chosen = audio.choice.clone(); + let width = ui.available_width().min(PICKER_WIDTH); + if widgets::select(ui, "audio-input", &mut chosen, &options, width).changed() { + actions.push(Action::SelectAudioInput(chosen)); + } }); }); }); @@ -117,30 +123,29 @@ pub fn show( } /// The entries of the picker: the defaults, then every device found. -fn input_choices(ui: &mut egui::Ui, audio: &AudioPanel<'_>, actions: &mut Vec) { - let mut entry = |ui: &mut egui::Ui, label: &str, choice: DeviceChoice| { - if ui - .selectable_label(*audio.choice == choice, label) - .clicked() - { - actions.push(Action::SelectAudioInput(choice)); - } - }; - entry(ui, "Default input", DeviceChoice::DefaultInput); +fn input_choices(audio: &AudioPanel<'_>) -> Vec<(DeviceChoice, String)> { + let mut entries = vec![(DeviceChoice::DefaultInput, "Default input".to_string())]; if audio .devices .iter() .any(|device| device.kind == DeviceKind::Loopback) { - entry( - ui, - "Default output (loopback)", + entries.push(( DeviceChoice::DefaultLoopback, - ); + "Default output (loopback)".to_string(), + )); } for device in audio.devices { - entry(ui, &device.name, DeviceChoice::ById(device.id.clone())); + entries.push((DeviceChoice::ById(device.id.clone()), device.name.clone())); + } + // A saved choice whose device is unplugged still shows, by its id. + if !entries.iter().any(|(choice, _)| choice == audio.choice) { + entries.push(( + audio.choice.clone(), + choice_label(audio.choice, audio.devices), + )); } + entries } /// The picker's closed text: what is chosen, by name where known. diff --git a/crates/strobe-app/src/ui/browser.rs b/crates/strobe-app/src/ui/browser.rs index 86401796..9a819edc 100644 --- a/crates/strobe-app/src/ui/browser.rs +++ b/crates/strobe-app/src/ui/browser.rs @@ -89,6 +89,10 @@ use std::borrow::Cow; /// The id of the search field, so a command can focus it. pub const SEARCH_ID: &str = "browser-search"; +/// The corner radius of a scene card and the preview card: M3's medium +/// shape, 12 dp. +const CARD_RADIUS: u8 = 12; + /// How large the grid's cards are (D282). One setting for the grid, saved. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum CardSize { @@ -262,49 +266,22 @@ const HEADER_TWO_ROWS: f32 = 560.0; /// one group in one border, so they read as the grid's filters rather /// than five unrelated controls (UI_REVIEW, Library). fn filter_group(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette) { - /// What the group takes: the two lists, the two square buttons, the - /// divider, the gaps between them, the margin and the border. - const WIDTH: f32 = SORT_WIDTH + 26.0 + 26.0 + 1.0 + SHOW_WIDTH + 2.0 * 4.0 + 6.0; + /// What the group takes: the two lists, the two square buttons and the + /// gaps between them. + const WIDTH: f32 = SORT_WIDTH + 26.0 + 26.0 + SHOW_WIDTH + 2.0 * 4.0 + 6.0; // A fixed allocation, laid out left to right even inside the header's // right-to-left row: a left-to-right child there claims the whole row. ui.allocate_ui_with_layout( Vec2::new(WIDTH, 30.0), Layout::left_to_right(Align::Center), |ui| { - egui::Frame::new() - .fill(theme::rgb(theme.raised)) - .stroke(Stroke::new(1.0, theme::rgb(theme.border))) - .corner_radius(CornerRadius::same(theme::RADIUS)) - .inner_margin(theme::margin(2.0)) - .show(ui, |ui| { - ui.spacing_mut().item_spacing.x = 2.0; - // The two lists sit flat inside the group's border. - let fill = theme::rgb(theme.raised); - let widgets = &mut ui.visuals_mut().widgets; - for state in [&mut widgets.inactive, &mut widgets.noninteractive] { - state.bg_stroke = Stroke::NONE; - state.weak_bg_fill = fill; - } - ui.horizontal(|ui| { - sort_controls(ui, model, theme); - divider(ui, theme); - show_control(ui, model); - }); - }); + ui.spacing_mut().item_spacing.x = 2.0; + sort_controls(ui, model, theme); + show_control(ui, model); }, ); } -/// A thin upright line between the filter group's parts. -fn divider(ui: &mut Ui, theme: &Palette) { - let (rect, _) = ui.allocate_exact_size(Vec2::new(1.0, 18.0), Sense::hover()); - ui.painter().vline( - rect.center().x, - rect.y_range(), - Stroke::new(1.0, theme::rgb(theme.border)), - ); -} - /// The toolbar on a row of its own, for a narrow window: new scene and /// refresh at the left, the thumbnail-size switch at the right, as /// Synesthesia's library has them. @@ -360,36 +337,27 @@ fn thumbnails_button(ui: &mut Ui, model: &Model<'_>, theme: &Palette, actions: & } } -/// The S, M and L card sizes, in a right-to-left layout. +/// The S, M and L card sizes, in a right-to-left layout: an M3 segmented +/// button with text cells (the shared `widgets::segmented` takes icons). fn size_switch(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette) { - // Largest first, so they read S M L left to right. - for size in CardSize::ALL.iter().rev() { - let active = model.ui.browser.cards == *size; - let (rect, response) = ui.allocate_exact_size(Vec2::new(26.0, 26.0), Sense::click()); - let fill = if active { theme.accent } else { theme.raised }; - let fill = widgets::hover_fill( - ui, - response.id, - response.hovered(), - fill, - if active { theme.accent } else { theme.hover }, - ); - ui.painter() - .rect_filled(rect, CornerRadius::same(theme::RADIUS), fill); - ui.painter().text( - rect.center(), - egui::Align2::CENTER_CENTER, - size.letter(), - egui::TextStyle::Small.resolve(ui.style()), - theme::rgb(if active { - theme.text_on_accent - } else { - theme.text - }), - ); - if super::help::hovered(response, size.tooltip()).clicked() { - model.ui.browser.cards = *size; - } + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let mut selected = CardSize::ALL + .iter() + .position(|size| *size == model.ui.browser.cards) + .unwrap_or(0); + let before = selected; + let mut group = egui_material3::SegmentedButton::single(&mut selected) + .id_salt("library-size") + .show_check(false); + for size in CardSize::ALL { + group = + group.segment(egui_material3::Segment::new(size.letter()).hover_text(size.tooltip())); + } + group.show(ui); + if selected != before + && let Some(size) = CardSize::ALL.get(selected) + { + model.ui.browser.cards = *size; } } @@ -450,7 +418,7 @@ fn filter_row(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut /// Whether the search field had focus when the frame began: Esc is its own /// business while it does (clear first, then leave). fn search_prelude(ui: &mut Ui, model: &mut Model<'_>) -> bool { - let id = egui::Id::unique(SEARCH_ID); + let id = search_edit_id(); let had_focus = ui.ctx().memory(|m| m.has_focus(id)); let escape = ui.input(|i| i.key_pressed(Key::Escape)); if had_focus && escape && !model.ui.browser.query.is_empty() { @@ -460,8 +428,14 @@ fn search_prelude(ui: &mut Ui, model: &mut Model<'_>) -> bool { had_focus } +/// The search field's text-edit id: fixed wherever the field sits, so the +/// prelude can ask whether it has focus before the field is drawn. +fn search_edit_id() -> egui::Id { + egui::Id::unique(SEARCH_ID).with("edit") +} + /// The width of the sort dropdown, and of the health dropdown. -const SORT_WIDTH: f32 = 128.0; +const SORT_WIDTH: f32 = 160.0; const SHOW_WIDTH: f32 = 96.0; /// How many scenes, as a sentence (D474): "229 scenes", "12 of 229 scenes" @@ -501,7 +475,8 @@ fn count_label(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, brief: bool) } } -/// The search field, `width` wide. +/// The search field, `width` wide: an M3 outlined field with a search icon +/// and, while there is text, a clear button. fn search_field( ui: &mut Ui, model: &mut Model<'_>, @@ -509,67 +484,22 @@ fn search_field( had_focus: bool, width: f32, ) -> egui::Response { - let id = egui::Id::unique(SEARCH_ID); - let size = Vec2::new(width.max(80.0), 28.0); - let response = ui - .allocate_ui_with_layout(size, Layout::left_to_right(Align::Center), |ui| { - egui::Frame::new() - .fill(theme::rgb(theme.app)) - .stroke(Stroke::new( - 1.0, - theme::rgb(if had_focus { - theme.accent - } else { - theme.border - }), - )) - .corner_radius(CornerRadius::same(theme::RADIUS)) - .inner_margin(theme::margin_xy(SPACE_SM, 3.0)) - .show(ui, |ui| { - ui.set_width(size.x - SPACE_SM * 2.0 - 2.0); - ui.horizontal(|ui| { - icons::show( - ui, - Icon::Search, - icons::INLINE, - theme::rgb(theme.text_muted), - ); - let clear_width = if model.ui.browser.query.is_empty() { - 0.0 - } else { - 22.0 - }; - let edit = ui.add( - egui::TextEdit::singleline(&mut model.ui.browser.query) - .id(id) - .frame(egui::Frame::NONE) - .hint_text("Search names, authors and tags Ctrl+F") - .desired_width(ui.available_width() - clear_width - SPACE_SM), - ); - if !model.ui.browser.query.is_empty() { - let (rect, response) = - ui.allocate_exact_size(Vec2::splat(16.0), Sense::click()); - icons::paint( - ui.painter(), - rect, - Icon::Close, - theme::rgb(if response.hovered() { - theme.text - } else { - theme.text_muted - }), - ); - if response.on_hover_text("Clear the search").clicked() { - model.ui.browser.query.clear(); - } - } - edit - }) - .inner - }) - .inner - }) - .inner; + let _ = (theme, had_focus); // The M3 theme colours it, and the input keeps its own focus (D710). + let has_text = !model.ui.browser.query.is_empty(); + let mut input = egui_material3::MaterialInput::outlined(&mut model.ui.browser.query) + .placeholder("Search names, authors and tags Ctrl+F") + .leading_icon(super::m3::symbol(Icon::Search).0) + .id_salt(SEARCH_ID) + .edit_id(search_edit_id()) + .width(width.max(80.0)); + if has_text { + input = input.trailing_icon_button(super::m3::symbol(Icon::Close).0, "Clear the search"); + } + let shown = input.show(ui); + let response = shown.response; + if shown.trailing_icon_clicked { + model.ui.browser.query.clear(); + } if model.ui.browser.focus_search { model.ui.browser.focus_search = false; response.request_focus(); @@ -640,45 +570,36 @@ fn order_controls(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette) { /// The sort dropdown and its direction, and the favourites-only toggle. fn sort_controls(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette) { - egui::ComboBox::from_id_salt("library-sort") - .selected_text(model.ui.browser.sort.label()) - .width(SORT_WIDTH - 24.0) - .show_ui(ui, |ui| { - for key in SortKey::ALL { - ui.selectable_value(&mut model.ui.browser.sort, key, key.label()); - } - }) - .response - .on_hover_text("What the grid is ordered by"); - let descending = model.ui.browser.descending; - if square_button( + let options = SortKey::ALL.map(|key| (key, key.label())); + widgets::select( ui, - theme, - if descending { - Icon::ArrowDown - } else { - Icon::ArrowUp - }, - false, + "library-sort", + &mut model.ui.browser.sort, + &options, + SORT_WIDTH, ) - .on_hover_text(if descending { + .on_hover_text("What the grid is ordered by"); + let descending = model.ui.browser.descending; + let order_tip = if descending { "Descending. Click for ascending." } else { "Ascending. Click for descending." - }) - .clicked() - { + }; + let direction = if descending { + Icon::ArrowDown + } else { + Icon::ArrowUp + }; + if square_button(ui, theme, direction, false, order_tip).clicked() { model.ui.browser.descending = !descending; } let only_favourites = model.ui.browser.filter == HealthFilter::Favourites; - if square_button(ui, theme, Icon::Star, only_favourites) - .on_hover_text(if only_favourites { - "Showing favourites only. Click to show every scene." - } else { - "Show only the scenes you starred" - }) - .clicked() - { + let star_tip = if only_favourites { + "Showing favourites only. Click to show every scene." + } else { + "Show only the scenes you starred" + }; + if square_button(ui, theme, Icon::Star, only_favourites, star_tip).clicked() { model.ui.browser.filter = if only_favourites { HealthFilter::All } else { @@ -689,47 +610,29 @@ fn sort_controls(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette) { /// The health filter. fn show_control(ui: &mut Ui, model: &mut Model<'_>) { - egui::ComboBox::from_id_salt("library-show") - .selected_text(model.ui.browser.filter.label()) - .width(SHOW_WIDTH - 24.0) - .show_ui(ui, |ui| { - for filter in HealthFilter::ALL { - ui.selectable_value(&mut model.ui.browser.filter, filter, filter.label()); - } - }) - .response - .on_hover_text( - "Show every scene, the ones that loaded this run, the ones that failed (they need \ + let options = HealthFilter::ALL.map(|filter| (filter, filter.label())); + widgets::select( + ui, + "library-show", + &mut model.ui.browser.filter, + &options, + SHOW_WIDTH, + ) + .on_hover_text( + "Show every scene, the ones that loaded this run, the ones that failed (they need \ work), or your favourites", - ); + ); } -/// A 26-point square icon button, filled with the accent while `active`. -fn square_button(ui: &mut Ui, theme: &Palette, icon: Icon, active: bool) -> egui::Response { - let (rect, response) = ui.allocate_exact_size(Vec2::splat(26.0), Sense::click()); - let rest = if active { - theme.accent_soft - } else { - theme.raised - }; - let fill = widgets::hover_fill(ui, response.id, response.hovered(), rest, theme.hover); - ui.painter() - .rect_filled(rect, CornerRadius::same(theme::RADIUS), fill); - if active { - ui.painter().rect_stroke( - rect, - CornerRadius::same(theme::RADIUS), - Stroke::new(1.0, theme::rgb(theme.accent)), - StrokeKind::Inside, - ); - } - icons::paint( - ui.painter(), - Rect::from_center_size(rect.center(), Vec2::splat(icons::INLINE)), - icon, - theme::rgb(if active { theme.accent } else { theme.text }), - ); - response +/// A square icon toggle, tonal while `active`. +fn square_button( + ui: &mut Ui, + theme: &Palette, + icon: Icon, + active: bool, + tooltip: &str, +) -> egui::Response { + widgets::tool_button_fitted(ui, theme, icon, tooltip, active, tooltip, false) } /// The selected scene's tags, and the field that edits them (D264). @@ -930,7 +833,7 @@ fn card( } let painter = ui.painter(); let fill = widgets::selection_fill(ui, theme, id, selected, response.hovered(), theme.raised); - painter.rect_filled(rect, CornerRadius::same(theme::RADIUS), fill); + painter.rect_filled(rect, CornerRadius::same(CARD_RADIUS), fill); // The picture, or generated cover art: the scene's two colours and its // initial (D474). @@ -939,8 +842,8 @@ fn card( Vec2::new(rect.width(), rect.height() - caption_height()), ); let radius = CornerRadius { - nw: theme::RADIUS, - ne: theme::RADIUS, + nw: CARD_RADIUS, + ne: CARD_RADIUS, sw: 0, se: 0, }; @@ -967,7 +870,7 @@ fn card( // A diagonal wash from one colour to the other. Square corners // under the card's rounded ones, inset by the radius at the // top so nothing pokes out. - let wash = picture.with_min_y(picture.top() + f32::from(theme::RADIUS)); + let wash = picture.with_min_y(picture.top() + f32::from(CARD_RADIUS)); let mut mesh = egui::Mesh::default(); let middle = first.lerp(second, 0.5); mesh.colored_vertex(wash.left_top(), theme::translucent(first, 150)); @@ -1090,14 +993,14 @@ fn card( if selected || playing { ui.painter().rect_stroke( rect, - CornerRadius::same(theme::RADIUS), + CornerRadius::same(CARD_RADIUS), Stroke::new(if selected { 2.0 } else { 1.0 }, theme::rgb(theme.accent)), StrokeKind::Inside, ); } else { ui.painter().rect_stroke( rect, - CornerRadius::same(theme::RADIUS), + CornerRadius::same(CARD_RADIUS), Stroke::new( 1.0, theme::rgb(if failed { theme.danger } else { theme.border }), @@ -1141,7 +1044,7 @@ fn card( // the first row). ui.painter().rect_stroke( rect.shrink(3.0), - CornerRadius::same(theme::RADIUS.saturating_sub(2)), + CornerRadius::same(CARD_RADIUS - 3), Stroke::new(1.5, theme::rgb(theme.accent_hover)), StrokeKind::Inside, ); @@ -1174,7 +1077,7 @@ fn card( theme.hover, ); ui.painter() - .rect_filled(dots, CornerRadius::same(theme::RADIUS), fill); + .rect_filled(dots, CornerRadius::same(u8::MAX), fill); } icons::paint( ui.painter(), @@ -1189,30 +1092,28 @@ fn card( let mut menu_choice = None; let mut menu = |ui: &mut Ui| { if playing { - if ui.button("Reload from disk").clicked() { + if widgets::menu_item(ui, None, "Reload from disk", true).clicked() { menu_choice = Some(Menu::Reload); ui.close(); } - } else if ui.button("Preview without loading").clicked() { + } else if widgets::menu_item(ui, None, "Preview without loading", true).clicked() { menu_choice = Some(Menu::Preview); ui.close(); } - if ui - .button(if favourite { - "Remove from favourites" - } else { - "Add to favourites" - }) - .clicked() - { + let star_label = if favourite { + "Remove from favourites" + } else { + "Add to favourites" + }; + if widgets::menu_item(ui, None, star_label, true).clicked() { menu_choice = Some(Menu::Star); ui.close(); } - if ui.button("Open in Editor").clicked() { + if widgets::menu_item(ui, None, "Open in Editor", true).clicked() { menu_choice = Some(Menu::Edit); ui.close(); } - if read_only && ui.button(super::tags::COPY_LABEL).clicked() { + if read_only && widgets::menu_item(ui, None, super::tags::COPY_LABEL, true).clicked() { menu_choice = Some(Menu::Copy); ui.close(); } @@ -1375,7 +1276,7 @@ fn preview_card( egui::Frame::new() .fill(theme::rgb(theme.raised)) .stroke(Stroke::new(1.0, theme::rgb(theme.info))) - .corner_radius(CornerRadius::same(theme::RADIUS)) + .corner_radius(CornerRadius::same(CARD_RADIUS)) .inner_margin(theme::margin(SPACE_SM)) .show(ui, |ui| { ui.set_width(ui.available_width()); diff --git a/crates/strobe-app/src/ui/command_palette.rs b/crates/strobe-app/src/ui/command_palette.rs index 4ea925b5..502e9e6d 100644 --- a/crates/strobe-app/src/ui/command_palette.rs +++ b/crates/strobe-app/src/ui/command_palette.rs @@ -211,10 +211,11 @@ pub fn draw(ctx: &Context, theme: &Palette, model: &mut Model<'_>, actions: &mut // runs off the screen (U-09). ui.set_width(CARD_WIDTH.min(screen.width() - 2.0 * CARD_MARGIN).max(0.0)); let field = ui.add( - egui::TextEdit::singleline(&mut state.query) - .id(egui::Id::unique("palette-query")) - .hint_text("Type a command, pane, scene or preset") - .desired_width(f32::INFINITY), + egui_material3::MaterialInput::outlined(&mut state.query) + .id_salt("palette-query") + .placeholder("Type a command, pane, scene or preset") + .leading_icon("search") + .fill_width(true), ); if just_opened { field.request_focus(); @@ -322,7 +323,7 @@ fn rows( if active || response.hovered() { let fill = if active { theme.selection } else { theme.hover }; ui.painter() - .rect_filled(rect, CornerRadius::same(theme::RADIUS), theme::rgb(fill)); + .rect_filled(rect, CornerRadius::same(theme::RADIUS_LG), theme::rgb(fill)); } let text = if item.unavailable.is_some() { theme.text_faint diff --git a/crates/strobe-app/src/ui/controls.rs b/crates/strobe-app/src/ui/controls.rs index 8486f582..75e16d38 100644 --- a/crates/strobe-app/src/ui/controls.rs +++ b/crates/strobe-app/src/ui/controls.rs @@ -786,7 +786,7 @@ fn pin_menu(response: &Response, def: &ControlDef, pins: &mut Option<&mut Extras } else { ("Pin as a macro", true) }; - if ui.button(label).clicked() { + if widgets::menu_item(ui, None, label, true).clicked() { pins.chosen = Some((def.name.clone(), pin)); ui.close(); } @@ -917,9 +917,13 @@ fn row_menu( ) -> bool { let mut reset = false; response.context_menu(|ui| { - if ui - .add_enabled(modified, egui::Button::new("Reset to the default")) - .clicked() + if widgets::menu_item( + ui, + Some(crate::icon::Icon::Reset), + "Reset to the default", + modified, + ) + .clicked() { reset = true; ui.close(); @@ -931,7 +935,7 @@ fn row_menu( } else { ("Pin as a macro", true) }; - if ui.button(label).clicked() { + if widgets::menu_item(ui, None, label, true).clicked() { pins.chosen = Some((def.name.clone(), pin)); ui.close(); } @@ -1515,25 +1519,22 @@ fn dropdown_row( row } None => { - let current = def.labels.get(selected).cloned().unwrap_or_default(); let width = (ui.available_width() * 0.5).clamp(80.0, 200.0); let row = property_row(ui, theme, &name, scale, width, mark.as_deref()); let slot = right_slot(row.rect, Vec2::new(width, height - 4.0)); + let options: Vec<(usize, &str)> = def + .labels + .iter() + .enumerate() + .map(|(option, label)| (option, label.as_str())) + .collect(); + let mut choice = selected; let picked = ui.put(slot, |ui: &mut Ui| { - // No taller than the row, at the compact density too. - ui.spacing_mut().interact_size.y = slot.height(); - egui::ComboBox::from_id_salt(("dropdown", index)) - .width(width) - .selected_text(current) - .show_ui(ui, |ui| { - for (option, label) in def.labels.iter().enumerate() { - if ui.selectable_label(option == selected, label).clicked() { - bank.set(index, Some(0), &[option as f32]); - } - } - }) - .response + widgets::select(ui, ("dropdown", index), &mut choice, &options, width) }); + if picked.changed() { + bank.set(index, Some(0), &[choice as f32]); + } describe(picked, def); row } diff --git a/crates/strobe-app/src/ui/credits.rs b/crates/strobe-app/src/ui/credits.rs index adb3acbd..4f02a3cf 100644 --- a/crates/strobe-app/src/ui/credits.rs +++ b/crates/strobe-app/src/ui/credits.rs @@ -237,7 +237,8 @@ fn credits() -> &'static Credits { /// A link: a quiet button that opens `url` in the browser. fn link(ui: &mut Ui, theme: &Palette, label: &str, url: &str) { - if widgets::button(ui, theme, None, label) + let _ = theme; // Colours reach the widget through the M3 theme (D710). + if widgets::text_button(ui, None, label) .on_hover_text(url) .clicked() { diff --git a/crates/strobe-app/src/ui/editor.rs b/crates/strobe-app/src/ui/editor.rs index e572a516..90f39818 100644 --- a/crates/strobe-app/src/ui/editor.rs +++ b/crates/strobe-app/src/ui/editor.rs @@ -101,6 +101,8 @@ pub fn show(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut V actions.push(Action::EditorSave); } + /// The chip that says the scene being edited is not the one playing. + const NOT_ON_SCREEN: &str = "Not on screen"; let on_screen = playing_dir.is_some_and(|dir| dir == doc.dir); // The failure, when it is this scene's. let error = failure @@ -136,16 +138,6 @@ pub fn show(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut V ui.horizontal(|ui| { ui.set_min_height(30.0); - ui.label( - egui::RichText::new(&doc.name) - .font(theme::heading_font()) - .color(theme::rgb(theme.text)), - ); - widgets::status_chip(ui, tone.icon(), word, tone.colour(theme)).on_hover_text(tip); - if !on_screen { - widgets::status_chip(ui, Icon::Info, "Not on screen", theme.text_muted) - .on_hover_text("This is not the scene the output is playing"); - } ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { // Right to left: the menu at the edge, then Save, then the // primary action nearest the name's line of sight. @@ -156,16 +148,14 @@ pub fn show(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut V "More: revert unsaved changes, or restore this file's backup", ); egui::Popup::menu(&more).show(|ui| { - if ui - .button("Revert unsaved changes") + if widgets::menu_item(ui, Some(Icon::Reset), "Revert unsaved changes", true) .on_hover_text("Throw away what has not been saved") .clicked() { actions.push(Action::EditorRevert); ui.close(); } - if ui - .button("Restore backup") + if widgets::menu_item(ui, Some(Icon::Refresh), "Restore backup", true) .on_hover_text( "Put this file's text from before this session's first save back in \ the editor (not saved until you save)", @@ -202,6 +192,43 @@ pub fn show(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut V { actions.push(Action::EditorSaveReload); } + // The name and its chips get what the actions leave. A chip + // with no room is left out (the more important status first), + // and the name gives way to the chips it has room for. + ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| { + const NAME_MIN: f32 = 80.0; + let gap = ui.spacing().item_spacing.x; + let room = ui.available_width(); + let status_w = widgets::status_chip_width(ui, word) + gap; + let screen_w = if on_screen { + 0.0 + } else { + widgets::status_chip_width(ui, NOT_ON_SCREEN) + gap + }; + let show_status = room >= NAME_MIN + status_w; + let show_screen = !on_screen && room >= NAME_MIN + status_w + screen_w; + let chips = if show_status { status_w } else { 0.0 } + + if show_screen { screen_w } else { 0.0 }; + let name_w = (room - chips).max(0.0); + ui.allocate_ui(egui::vec2(name_w, ui.available_height()), |ui| { + ui.add( + egui::Label::new( + egui::RichText::new(&doc.name) + .font(theme::heading_font()) + .color(theme::rgb(theme.text)), + ) + .truncate(), + ); + }); + if show_status { + widgets::status_chip(ui, tone.icon(), word, tone.colour(theme)) + .on_hover_text(tip); + } + if show_screen { + widgets::status_chip(ui, Icon::Info, NOT_ON_SCREEN, theme.text_muted) + .on_hover_text("This is not the scene the output is playing"); + } + }); }); }); ui.add_space(SPACE_XS); @@ -222,18 +249,22 @@ pub fn show(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut V } // Tabs. - ui.horizontal_wrapped(|ui| { - for (index, tab) in doc.tabs.iter().enumerate() { - let label = if tab.is_dirty() { - format!("{} \u{2022}", tab.file) - } else { - tab.file.clone() - }; - if ui.selectable_label(index == doc.active, label).clicked() { - doc.active = index; - } - } - }); + let mut selected = doc.active; + let mut tabs = egui_material3::MaterialTabs::secondary(&mut selected) + .id_salt("editor-tabs") + .scrollable(); + for tab in &doc.tabs { + let label = if tab.is_dirty() { + format!("{} \u{2022}", tab.file) + } else { + tab.file.clone() + }; + tabs = tabs.tab(label); + } + ui.add(tabs); + if selected != doc.active && selected < doc.tabs.len() { + doc.active = selected; + } ui.add_space(SPACE_SM); let active = doc.active.min(doc.tabs.len().saturating_sub(1)); diff --git a/crates/strobe-app/src/ui/fonts.rs b/crates/strobe-app/src/ui/fonts.rs index ab223003..2ed10a52 100644 --- a/crates/strobe-app/src/ui/fonts.rs +++ b/crates/strobe-app/src/ui/fonts.rs @@ -84,6 +84,12 @@ pub fn install(ctx: &egui::Context) { .or_default() .insert(0, "consolas".to_owned()); } + // Roboto in front of the proportional faces, Roboto Medium for + // headings, and the Material Symbols. + super::m3::add_fonts(&mut fonts); + if let Some(strong) = fonts.families.get_mut(&FontFamily::Name(STRONG.into())) { + strong.insert(0, "Roboto-Medium".to_owned()); + } ctx.set_fonts(fonts); STRONG_FAMILY.with(|family| family.replace(FontFamily::Name(STRONG.into()))); log::info!("UI fonts: Segoe UI from {}", dir.display()); diff --git a/crates/strobe-app/src/ui/form.rs b/crates/strobe-app/src/ui/form.rs index b397a11e..12b7d5b7 100644 --- a/crates/strobe-app/src/ui/form.rs +++ b/crates/strobe-app/src/ui/form.rs @@ -72,7 +72,7 @@ const WIDE: f32 = 1.45; const WIDE_SHARE: f32 = 0.6; /// A switch's track. -const SWITCH: Vec2 = Vec2::new(36.0, 20.0); +const SWITCH: Vec2 = Vec2::new(52.0, 32.0); /// The width of a row's control column at the density in force. #[must_use] @@ -489,68 +489,20 @@ impl Group<'_> { /// that slides across. Flips `on` when clicked, or on Space or Enter when /// it has the focus. pub fn toggle(ui: &mut Ui, theme: &Palette, on: &mut bool) -> Response { - let (rect, mut response) = ui.allocate_exact_size(SWITCH, Sense::click()); - if response.clicked() { - *on = !*on; - response.mark_changed(); - } - let state = *on; - let enabled = ui.is_enabled(); - response.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, enabled, state, "")); - let t = motion::toggle(ui.ctx(), response.id, state, motion::QUICK); - let painter = ui.painter(); - let radius = egui::CornerRadius::same((SWITCH.y / 2.0) as u8); - let off_track = widgets::hover_fill( - ui, - response.id.with("hover"), - response.hovered(), - theme.control, - theme.control_hover, - ); - let track = if state { - theme::rgb(theme.accent) - } else { - off_track - }; - painter.rect_filled(rect, radius, track); - if !state { - painter.rect_stroke( - rect, - radius, - Stroke::new(1.0, theme::rgb(theme.border_strong)), - egui::StrokeKind::Inside, - ); - } - if response.has_focus() { - painter.rect_stroke( - rect.expand(2.0), - egui::CornerRadius::same((SWITCH.y / 2.0 + 2.0) as u8), - Stroke::new(2.0, theme::rgb(theme.accent_hover)), - egui::StrokeKind::Outside, - ); - } - let knob_radius = SWITCH.y / 2.0 - 3.0; - let left = rect.left() + 3.0 + knob_radius; - let right = rect.right() - 3.0 - knob_radius; - let knob = egui::pos2(left + (right - left) * t, rect.center().y); - let ink = if state { - theme.text_on_accent - } else { - theme.text_muted - }; - painter.circle_filled(knob, knob_radius, theme::rgb(ink)); - response.on_hover_cursor(egui::CursorIcon::PointingHand) + let _ = theme; // Colours reach the widget through the M3 theme (D710). + ui.add(egui_material3::MaterialSwitch::new(on).dense(true)) + .on_hover_cursor(egui::CursorIcon::PointingHand) } /// A single-line text field `width` wide: outlined, with room inside, and /// a placeholder fainter than any value so an empty field never reads as a /// filled one (UI review S3). pub fn field(ui: &mut Ui, theme: &Palette, text: &mut String, hint: &str, width: f32) -> Response { + let _ = theme; // Colours reach the widget through the M3 theme (D710). ui.add( - egui::TextEdit::singleline(text) - .hint_text(egui::RichText::new(hint).color(theme::rgb(theme.text_faint))) - .desired_width(width) - .margin(theme::margin_xy(SPACE_SM, SPACE_XS)), + egui_material3::MaterialInput::outlined(text) + .placeholder(hint) + .width(width), ) } @@ -566,12 +518,16 @@ pub fn slider( /// Room for the value box beside the track. const VALUE: f32 = 64.0; ui.with_layout(Layout::left_to_right(Align::Center), |ui| { - ui.spacing_mut().slider_width = (ui.available_width() - VALUE).max(SPACE_LG * 3.0); - let mut slider = egui::Slider::new(value, range).custom_formatter(|v, _| format(v)); + let width = (ui.available_width() - VALUE).max(SPACE_LG * 3.0); + let mut slider = egui_material3::MaterialSlider::new(value, range) + .width(width) + .show_value(false); if let Some(step) = step { - slider = slider.step_by(step); + slider = slider.step(step as f32); } - ui.add(slider) + let response = ui.add(slider); + ui.label(format(f64::from(*value))); + response }) .inner } diff --git a/crates/strobe-app/src/ui/icon.rs b/crates/strobe-app/src/ui/icon.rs index 47c034e9..a1a3f23e 100644 --- a/crates/strobe-app/src/ui/icon.rs +++ b/crates/strobe-app/src/ui/icon.rs @@ -1,27 +1,20 @@ // ============================================================================ // Module: strobe_app::ui::icon -// Description: Painting crate::icon's geometry with egui, and the sizes the -// app draws an icon at. +// Description: Painting crate::icon's icons as Material Symbols glyphs with +// egui, and the sizes the app draws an icon at. // -// Dependencies: egui (Painter, Shape); crate::icon; super::theme. +// Dependencies: egui (Painter, Shape); crate::icon; super::m3. // Ported from rustaman's `gui::ui::icon` (D5, D130). // ============================================================================ //! The icon set, painted. //! -//! [`crate::icon`] owns the shapes, as static data with tests that run -//! anywhere. This module maps them onto a rect and strokes them. -//! -//! ## Strokes, not fills -//! -//! Every icon is a stroked path with round caps and joins (a handful are -//! solid, like the play triangle). A stroke takes the theme's colour as one -//! argument and scales with the icon, so an icon at 12 px in a list row and -//! the same icon at 20 px in the rail carry the same visual weight; at 16 px -//! a mitre joint on a chevron renders as a spike a pixel long. +//! [`crate::icon`] owns the icon names and their meaning. This module draws +//! each one as a Material Symbols glyph (see `super::m3::symbol`), centred in +//! a rect and optionally rotated, in the theme's colour. -use crate::icon::{GRID, Icon, MAX_ARC_POINTS, Seg, WEIGHT, arc_points}; -use egui::{Color32, Painter, Pos2, Rect, Shape, Stroke, Vec2}; +use crate::icon::Icon; +use egui::{Color32, Painter, Rect, Shape, Vec2}; /// Paints `icon` inside `rect`, in `color`. The icon is centred and drawn on /// the largest square that fits, so a caller may hand over a non-square rect @@ -35,70 +28,23 @@ pub fn paint(painter: &Painter, rect: Rect, icon: Icon, color: Color32) { /// as the same object turning, where two chevrons swapped at the halfway /// point read as one being replaced by another. pub fn paint_rotated(painter: &Painter, rect: Rect, icon: Icon, color: Color32, turns: f32) { + // The symbols' em box is the icon's optical box, so the glyph is set a + // little larger than the icon's nominal square to read at the same weight. + const OPTICAL: f32 = 1.2; let side = rect.width().min(rect.height()); if side <= 0.0 { return; } - let scale = side / GRID; - let origin = rect.center() - Vec2::splat(side / 2.0); - let stroke = Stroke::new((WEIGHT * scale).max(1.0), color); - - // Rotation happens in grid space, about the grid's own centre, so an - // icon that is optically centred stays centred as it turns. + let (_, glyph) = super::m3::symbol(icon); + let font = egui::FontId::new(side * OPTICAL, super::m3::symbol_family()); + let galley = painter.layout_no_wrap(glyph.to_string(), font, color); let turns = if turns.is_finite() { turns } else { 0.0 }; - let (sin, cos) = (turns * std::f32::consts::TAU).sin_cos(); - let half = GRID / 2.0; - let place = |&(x, y): &(f32, f32)| { - let (dx, dy) = (x - half, y - half); - let (rx, ry) = (dx * cos - dy * sin + half, dx * sin + dy * cos + half); - Pos2::new(origin.x + rx * scale, origin.y + ry * scale) - }; - - for seg in icon.segments() { - match *seg { - Seg::Open(points) => { - painter.add(Shape::line(points.iter().map(place).collect(), stroke)); - } - Seg::Closed(points) => { - let mut placed: Vec = points.iter().map(place).collect(); - if let Some(&first) = placed.first() { - placed.push(first); - } - painter.add(Shape::line(placed, stroke)); - } - Seg::Solid(points) => { - // `convex_polygon` is the cheap path, and these shapes are - // convex. It takes its own stroke, which is `NONE`: a filled - // shape that is also outlined is drawn half a stroke larger - // than the grid says. - painter.add(Shape::convex_polygon( - points.iter().map(place).collect(), - color, - Stroke::NONE, - )); - } - Seg::Dot(x, y) => { - painter.circle_filled(place(&(x, y)), stroke.width / 2.0, color); - } - Seg::Circle(cx, cy, radius) => { - let mut buffer = [(0.0, 0.0); MAX_ARC_POINTS]; - let count = arc_points(cx, cy, radius, 0.0, std::f32::consts::TAU, &mut buffer); - let mut placed: Vec = buffer.iter().take(count).map(place).collect(); - if let Some(&first) = placed.first() { - placed.push(first); - } - painter.add(Shape::line(placed, stroke)); - } - Seg::Arc(cx, cy, radius, start, end) => { - let mut buffer = [(0.0, 0.0); MAX_ARC_POINTS]; - let count = arc_points(cx, cy, radius, start, end, &mut buffer); - painter.add(Shape::line( - buffer.iter().take(count).map(place).collect(), - stroke, - )); - } - } - } + let angle = turns * std::f32::consts::TAU; + let rotated = egui::emath::Rot2::from_angle(angle) * (galley.size() / 2.0); + let pos = rect.center() - rotated; + painter.add(Shape::Text( + egui::epaint::TextShape::new(pos, galley, color).with_angle(angle), + )); } /// Allocates a square of `size` in the current layout and paints `icon` into diff --git a/crates/strobe-app/src/ui/inspector.rs b/crates/strobe-app/src/ui/inspector.rs index c7f6f9c8..442f7189 100644 --- a/crates/strobe-app/src/ui/inspector.rs +++ b/crates/strobe-app/src/ui/inspector.rs @@ -59,6 +59,7 @@ //! that flows into the same columns on the page. use super::controls; +use super::form; use super::icon as icons; use super::model::{Action, GeneratePanel, MediaFrom, MediaPanel, Model}; use super::tags; @@ -173,8 +174,7 @@ pub fn show( && let Some(entry) = model.playing.and_then(|i| model.library.entries.get(i)) { let capture = |ui: &mut Ui| { - if ui - .small_button("Use frame as picture") + if widgets::button(ui, theme, None, "Use frame as picture") .on_hover_text( "Save what is on screen now as this scene's picture in the library \ (thumbnail.jpg in its folder)", @@ -396,8 +396,7 @@ fn media_row( .color(theme::rgb(theme.text_faint)), ); } - if ui - .small_button("Choose") + if widgets::button(ui, theme, None, "Choose") .on_hover_text("Show a picture, or a folder of pictures, behind syn_Media") .clicked() { @@ -411,13 +410,15 @@ fn media_row( ); } for (kind, label, hover) in LIVE_BUTTONS { - if ui.small_button(label).on_hover_text(hover).clicked() { + if widgets::button(ui, theme, None, label) + .on_hover_text(hover) + .clicked() + { *live = Some(crate::live::Listing::start(kind)); } } if media.chosen - && ui - .small_button("Scene's own") + && widgets::button(ui, theme, None, "Scene's own") .on_hover_text("Give each scene its own media back") .clicked() { @@ -428,18 +429,20 @@ fn media_row( }; let mut done = false; ui.horizontal(|ui| { - let field = ui.add( - egui::TextEdit::singleline(text) - .hint_text("A picture, or a folder of pictures") - .desired_width((ui.available_width() - 120.0).max(80.0)), + let field = form::field( + ui, + theme, + text, + "A picture, or a folder of pictures", + (ui.available_width() - 120.0).max(80.0), ); let entered = field.lost_focus() && ui.input(|input| input.key_pressed(egui::Key::Enter)); let path = text.trim(); - if (ui.small_button("Use").clicked() || entered) && !path.is_empty() { + if (widgets::button(ui, theme, None, "Use").clicked() || entered) && !path.is_empty() { actions.push(Action::SetMedia(Some(std::path::PathBuf::from(path)))); done = true; } - if ui.small_button("Cancel").clicked() { + if widgets::button(ui, theme, None, "Cancel").clicked() { done = true; } }); @@ -531,8 +534,7 @@ fn live_row( } crate::live::Listed::Found(names) => { for name in names { - if ui - .small_button(name.as_str()) + if widgets::button(ui, theme, None, name.as_str()) .on_hover_text(live_hover(kind)) .clicked() { @@ -547,7 +549,7 @@ fn live_row( ui.label(faint(&format!("Listing failed: {why}"))); } } - if ui.small_button("Cancel").clicked() { + if widgets::button(ui, theme, None, "Cancel").clicked() { done = true; } }); @@ -571,8 +573,7 @@ fn transitions_row(ui: &mut Ui, theme: &Palette, actions: &mut Vec) { .on_hover_text( "The scene's transitions: some numbers jump to another of their values and some colours crossfade when Strobe hears the next track start", ); - if ui - .small_button("New song") + if widgets::button(ui, theme, None, "New song") .on_hover_text( "Change the look now, as a new song would. A playlist cue that waits for a new song ends too.", ) @@ -799,7 +800,7 @@ fn review( // Wrapped: a row is wider than a pane at its narrowest, and an // unwrapped one pushed the dock under the toolbar (U-09). ui.horizontal_wrapped(|ui| { - ui.checkbox(&mut edit.keep, "") + ui.add(egui_material3::MaterialCheckbox::new(&mut edit.keep, "")) .on_hover_text("Keep this control; untick to leave the number as it was"); // The bar in a fixed column, so a long colour range never // runs under it. @@ -810,11 +811,7 @@ fn review( .on_hover_text("How much the picture moves with it, against the strongest"); if edit.keep { // Renamable while kept (D246); checked when applied. - ui.add( - egui::TextEdit::singleline(&mut edit.name) - .font(egui::TextStyle::Monospace) - .desired_width(110.0), - ) + form::field(ui, theme, &mut edit.name, "", 130.0) .on_hover_text(format!( "The control's name in the copy (proposed: {}). Letters, digits and _.", kept.name @@ -926,18 +923,22 @@ fn range_fields(ui: &mut Ui, kept: &Kept, edit: &mut Review) { let span = (edit.max - edit.min).abs().max(0.01); let speed = span / 200.0; ui.add( - egui::DragValue::new(&mut edit.min) - .speed(speed) + egui_material3::MaterialNumberField::outlined(&mut edit.min) + .id_salt("range_min") + .step(f64::from(speed)) .range(f32::MIN..=default) - .max_decimals(3), + .decimals(3) + .width(84.0), ) .on_hover_text("The lowest the control goes"); ui.label("–"); ui.add( - egui::DragValue::new(&mut edit.max) - .speed(speed) + egui_material3::MaterialNumberField::outlined(&mut edit.max) + .id_salt("range_max") + .step(f64::from(speed)) .range(default..=f32::MAX) - .max_decimals(3), + .decimals(3) + .width(84.0), ) .on_hover_text("The highest the control goes"); } diff --git a/crates/strobe-app/src/ui/m3.rs b/crates/strobe-app/src/ui/m3.rs new file mode 100644 index 00000000..d21d5902 --- /dev/null +++ b/crates/strobe-app/src/ui/m3.rs @@ -0,0 +1,208 @@ +// ============================================================================ +// Module: strobe_app::ui::m3 +// Description: The Material 3 adapter: Strobe's icons as Material Symbols, +// its palette as M3 colour roles, its density as the theme's, +// and the egui-material3 theme installed on the context. +// +// Dependencies: egui, egui_material3; crate::{color, icon, palette}, super::theme. +// ============================================================================ + +//! The seam between Strobe and `egui-material3` (D710). +//! +//! Three levers carry the whole control window, because every pane draws +//! through them: +//! +//! - **Colour.** [`scheme`] maps each M3 colour role a widget reads from the +//! theme's own [`Palette`], so a theme keeps its look and the library's +//! widgets agree with Strobe's hand-painted surfaces. +//! - **Size.** [`install`] gives the library Strobe's density as a theme-wide +//! M3 density and type scale, so no pane passes sizes to a widget. +//! - **Icons.** [`symbol`] names the Material Symbol for each [`Icon`]; +//! `super::icon::paint` draws the glyph. + +use super::theme::{self, Density}; +use crate::color::Rgb; +use crate::icon::Icon; +use crate::palette::{Mode, Palette}; +use egui::FontFamily; +use egui_material3::color::Variant; +use egui_material3::fonts::SymbolStyle; +use egui_material3::material_symbol as ms; +use egui_material3::{ColorRole, MaterialTheme}; +use std::sync::OnceLock; + +/// The Material Symbol name and code point for `icon`. +#[must_use] +pub fn symbol(icon: Icon) -> (&'static str, char) { + match icon { + Icon::Perform => ("play_circle", ms::ICON_PLAY_CIRCLE), + Icon::Library => ("photo_library", ms::ICON_PHOTO_LIBRARY), + Icon::Playlist => ("queue_music", ms::ICON_QUEUE_MUSIC), + Icon::Editor => ("code", ms::ICON_CODE), + Icon::Mapping => ("cable", ms::ICON_CABLE), + Icon::Diagnostics => ("monitoring", ms::ICON_MONITORING), + Icon::Settings => ("settings", ms::ICON_SETTINGS), + Icon::Prev => ("skip_previous", ms::ICON_SKIP_PREVIOUS), + Icon::Next => ("skip_next", ms::ICON_SKIP_NEXT), + Icon::Play => ("play_arrow", ms::ICON_PLAY_ARROW), + Icon::Pause => ("pause", ms::ICON_PAUSE), + Icon::Blackout => ("power_settings_new", ms::ICON_POWER_SETTINGS_NEW), + Icon::ChevronRight => ("chevron_right", ms::ICON_CHEVRON_RIGHT), + Icon::ChevronDown => ("expand_more", ms::ICON_EXPAND_MORE), + Icon::Search => ("search", ms::ICON_SEARCH), + Icon::Close => ("close", ms::ICON_CLOSE), + Icon::WindowMinimise => ("minimize", ms::ICON_MINIMIZE), + Icon::WindowMaximise => ("crop_square", ms::ICON_CROP_SQUARE), + Icon::WindowRestore => ("filter_none", ms::ICON_FILTER_NONE), + Icon::Check => ("check_circle", ms::ICON_CHECK_CIRCLE), + Icon::Warning => ("warning", ms::ICON_WARNING), + Icon::Error => ("error", ms::ICON_ERROR), + Icon::Info => ("info", ms::ICON_INFO), + Icon::Refresh => ("refresh", ms::ICON_REFRESH), + Icon::Reset => ("restart_alt", ms::ICON_RESTART_ALT), + Icon::Copy => ("content_copy", ms::ICON_CONTENT_COPY), + Icon::Folder => ("folder_open", ms::ICON_FOLDER_OPEN), + Icon::Import => ("download", ms::ICON_DOWNLOAD), + Icon::Output => ("desktop_windows", ms::ICON_DESKTOP_WINDOWS), + Icon::Fullscreen => ("fullscreen", ms::ICON_FULLSCREEN), + Icon::Audio => ("graphic_eq", ms::ICON_GRAPHIC_EQ), + Icon::Controls => ("tune", ms::ICON_TUNE), + Icon::Star => ("star", ms::ICON_STAR), + Icon::Dice => ("casino", ms::ICON_CASINO), + Icon::More => ("more_horiz", ms::ICON_MORE_HORIZ), + Icon::Camera => ("photo_camera", ms::ICON_PHOTO_CAMERA), + Icon::ArrowUp => ("arrow_upward", ms::ICON_ARROW_UPWARD), + Icon::ArrowDown => ("arrow_downward", ms::ICON_ARROW_DOWNWARD), + Icon::Plus => ("add", ms::ICON_ADD), + } +} + +/// The font family the outlined symbols are drawn in, built once so a +/// frame clones an `Arc` rather than formatting a name. +#[must_use] +pub fn symbol_family() -> FontFamily { + static FAMILY: OnceLock = OnceLock::new(); + FAMILY + .get_or_init(|| egui_material3::fonts::symbol_family(SymbolStyle::Outlined, false, 400)) + .clone() +} + +/// Adds Roboto (in front of the proportional faces) and the outlined +/// Material Symbols to `defs`. +pub fn add_fonts(defs: &mut egui::FontDefinitions) { + egui_material3::fonts::add_material_fonts_outlined(defs); +} + +/// The text colour that reads on `fill`: the theme's text or its +/// on-accent colour, whichever contrasts more. +fn on(palette: &Palette, fill: Rgb) -> Rgb { + if fill.contrast(palette.text) >= fill.contrast(palette.text_on_accent) { + palette.text + } else { + palette.text_on_accent + } +} + +/// The M3 colour scheme `palette` describes: every role the widgets read +/// mapped from the theme's own colours (D710), so a theme keeps its look +/// and Strobe's hand-painted surfaces and the library's widgets agree. The +/// fixed roles, shadow and scrim come from the tonal scheme of the accent, +/// which nothing in Strobe paints with. +#[must_use] +pub fn scheme(palette: &Palette) -> egui_material3::ColorScheme { + let dark = match palette.mode { + Mode::Dark => true, + Mode::Light => false, + }; + let mut colors = egui_material3::ColorScheme::from_seed( + theme::rgb(palette.accent), + Variant::TonalSpot, + dark, + 0.0, + ); + let error_container = palette.danger.lerp(palette.panel, 0.7); + let tertiary_container = palette.info.lerp(palette.panel, 0.7); + let roles = [ + (ColorRole::Primary, palette.accent), + (ColorRole::SurfaceTint, palette.accent), + (ColorRole::OnPrimary, palette.text_on_accent), + (ColorRole::PrimaryContainer, palette.accent_soft), + ( + ColorRole::OnPrimaryContainer, + on(palette, palette.accent_soft), + ), + (ColorRole::Secondary, palette.accent_hover), + (ColorRole::OnSecondary, on(palette, palette.accent_hover)), + (ColorRole::SecondaryContainer, palette.selection), + (ColorRole::OnSecondaryContainer, palette.selection_text), + (ColorRole::Tertiary, palette.info), + (ColorRole::OnTertiary, on(palette, palette.info)), + (ColorRole::TertiaryContainer, tertiary_container), + ( + ColorRole::OnTertiaryContainer, + on(palette, tertiary_container), + ), + (ColorRole::Error, palette.danger), + (ColorRole::OnError, on(palette, palette.danger)), + (ColorRole::ErrorContainer, error_container), + (ColorRole::OnErrorContainer, on(palette, error_container)), + (ColorRole::Background, palette.app), + (ColorRole::OnBackground, palette.text), + (ColorRole::Surface, palette.app), + (ColorRole::OnSurface, palette.text), + (ColorRole::SurfaceVariant, palette.raised), + (ColorRole::OnSurfaceVariant, palette.text_muted), + (ColorRole::Outline, palette.border_strong), + (ColorRole::OutlineVariant, palette.border), + (ColorRole::InverseSurface, palette.text), + (ColorRole::InverseOnSurface, palette.app), + ( + ColorRole::InversePrimary, + palette.accent.lerp(palette.app, 0.4), + ), + (ColorRole::SurfaceDim, palette.app), + (ColorRole::SurfaceBright, palette.hover), + (ColorRole::SurfaceContainerLowest, palette.app), + (ColorRole::SurfaceContainerLow, palette.panel), + ( + ColorRole::SurfaceContainer, + palette.panel.lerp(palette.raised, 0.5), + ), + (ColorRole::SurfaceContainerHigh, palette.raised), + (ColorRole::SurfaceContainerHighest, palette.hover), + ]; + for (role, colour) in roles { + colors.set(role, theme::rgb(colour)); + } + colors +} + +/// The library's density for Strobe's: the steps the panes used to pass to +/// each widget by hand, now theme-wide (D710). +const fn density_steps(density: Density) -> i8 { + match density { + Density::Comfortable => -3, + Density::Compact => -4, + } +} + +/// The size of M3's label-large style, which buttons, tabs and segments +/// draw their labels in. +const M3_LABEL_SIZE: f32 = 14.0; + +/// Installs the library's theme on `ctx` from `palette` at `density`. Its +/// type scale puts the widgets' labels at Strobe's body size. +pub fn install(ctx: &egui::Context, palette: &Palette, density: Density) { + let dark = match palette.mode { + Mode::Dark => true, + Mode::Light => false, + }; + let theme = MaterialTheme { + colors: scheme(palette), + ..MaterialTheme::baseline(dark) + } + .with_density(egui_material3::Density::new(density_steps(density))) + .with_type_scale(density.body() / M3_LABEL_SIZE); + MaterialTheme::set(ctx, theme); + MaterialTheme::set_reduce_motion(ctx, crate::motion::reduced()); +} diff --git a/crates/strobe-app/src/ui/macros.rs b/crates/strobe-app/src/ui/macros.rs index db2bd46b..52476617 100644 --- a/crates/strobe-app/src/ui/macros.rs +++ b/crates/strobe-app/src/ui/macros.rs @@ -431,19 +431,19 @@ fn cell( body(ui, theme, &flat, reach, view, width, actions); }); response.context_menu(|ui| { - if ui.button("Learn a MIDI or OSC source").clicked() { + if widgets::menu_item(ui, None, "Learn a MIDI or OSC source", true).clicked() { chosen = Some(Intent::Learn); ui.close(); } - if ui.button("Move earlier").clicked() { + if widgets::menu_item(ui, None, "Move earlier", true).clicked() { chosen = Some(Intent::Earlier); ui.close(); } - if ui.button("Move later").clicked() { + if widgets::menu_item(ui, None, "Move later", true).clicked() { chosen = Some(Intent::Later); ui.close(); } - if ui.button("Unpin").clicked() { + if widgets::menu_item(ui, None, "Unpin", true).clicked() { chosen = Some(Intent::Unpin); ui.close(); } @@ -590,17 +590,24 @@ fn control_body( (ControlKind::Dropdown { .. }, _) => { let selected = (target[0].round().max(0.0) as usize).min(def.labels.len().saturating_sub(1)); - let current = def.labels.get(selected).cloned().unwrap_or_default(); - egui::ComboBox::from_id_salt(("macro-dropdown", index)) - .width(width - 4.0) - .selected_text(current) - .show_ui(ui, |ui| { - for (option, label) in def.labels.iter().enumerate() { - if ui.selectable_label(option == selected, label).clicked() { - bank.set(index, Some(0), &[option as f32]); - } - } - }); + let options: Vec<(usize, &str)> = def + .labels + .iter() + .enumerate() + .map(|(option, label)| (option, label.as_str())) + .collect(); + let mut chosen = selected; + if widgets::select( + ui, + ("macro-dropdown", index), + &mut chosen, + &options, + width - 4.0, + ) + .changed() + { + bank.set(index, Some(0), &[chosen as f32]); + } } (ControlKind::Color { .. }, None) => { let mut rgb = target; diff --git a/crates/strobe-app/src/ui/map.rs b/crates/strobe-app/src/ui/map.rs index 29956294..513db298 100644 --- a/crates/strobe-app/src/ui/map.rs +++ b/crates/strobe-app/src/ui/map.rs @@ -55,6 +55,7 @@ use crate::palette::Palette; use crate::remote::{Evaluated, OscState, Remote}; use crate::workspace::Pane; use egui::Ui; +use egui_material3::MaterialNumberField; use strobe_io::engine::Armed; use strobe_io::target::{Resolution, State}; use strobe_io::{ButtonMode, Curve, Mapping, OscSettings, Source, Takeover, Target}; @@ -66,6 +67,12 @@ const ACTIVITY_LINES: usize = 8; /// The width of a short field: a port, a cue number. const SHORT_FIELD: f32 = 80.0; +/// The width of a number field in a settings row. +const NUMBER_FIELD: f32 = 84.0; + +/// The width of a select in a settings row. +const SELECT: f32 = 160.0; + /// The width of a name or address field. const FIELD: f32 = 180.0; @@ -804,9 +811,9 @@ fn macro_options(group: &mut form::Group<'_>, theme: &Palette, remote: &mut Remo low = 0.0; high = 1.0; } - ui.add(percent(&mut high)); + percent(ui, "macro-range-high", &mut high); ui.label(egui::RichText::new("to").color(theme::rgb(theme.text_muted))); - ui.add(percent(&mut low)); + percent(ui, "macro-range-low", &mut low); }, ); let range = Some([low, high]); @@ -819,11 +826,13 @@ fn macro_options(group: &mut form::Group<'_>, theme: &Palette, remote: &mut Remo ), |ui| { ui.add( - egui::DragValue::new(&mut glide) - .speed(0.01) + MaterialNumberField::new(&mut glide) + .id_salt("macro-glide") .range(0.0..=strobe_io::macros::MAX_GLIDE) - .max_decimals(2) - .suffix(" s"), + .step(0.01) + .decimals(2) + .suffix("s") + .width(NUMBER_FIELD), ); }, ); @@ -852,8 +861,7 @@ fn macro_options(group: &mut form::Group<'_>, theme: &Palette, remote: &mut Remo colour = Some(index); } } - if ui - .selectable_label(colour.is_none(), "none") + if widgets::text_button(ui, None, "None") .on_hover_text("The theme's accent") .clicked() { @@ -892,20 +900,33 @@ fn macro_options(group: &mut form::Group<'_>, theme: &Palette, remote: &mut Remo } } -/// A fraction edited as a percentage. -fn percent(value: &mut f32) -> egui::DragValue<'_> { - egui::DragValue::new(value) - .range(0.0..=1.0) - .speed(0.005) - .custom_formatter(|v, _| format!("{:.0}%", v * 100.0)) - .custom_parser(|text| { - text.trim() - .trim_end_matches('%') - .trim() - .parse::() - .ok() - .map(|v| v / 100.0) - }) +/// A fraction edited as a percentage: the field holds whole percent and +/// the fraction is written back only when the number changed. +fn percent(ui: &mut Ui, id: &str, value: &mut f32) { + ui.add( + MaterialNumberField::new(value) + .id_salt(id) + .range(0.0..=1.0) + .step(0.01) + .decimals(2) + .formatter(|fraction| format!("{:.0}", fraction * 100.0)) + .parser(|text| text.parse::().ok().map(|percent| percent / 100.0)) + .suffix("%") + .width(NUMBER_FIELD), + ); +} + +/// A two-decimal number between `low` and `high`, for a mapping's range +/// ends and press threshold. +fn fraction(ui: &mut Ui, id: &str, value: &mut f32, low: f32, high: f32) { + ui.add( + MaterialNumberField::new(value) + .id_salt(id) + .range(low..=high) + .step(0.01) + .decimals(2) + .width(NUMBER_FIELD), + ); } // ------------------------------------------------------------ mappings @@ -1050,30 +1071,23 @@ fn mapping_options( Row::new("Device") .description("Answer this device only, or the same message from any."), |ui| { - let current = mapping.source.device().unwrap_or("Any device").to_string(); - egui::ComboBox::from_id_salt("mapping-device") - .selected_text(current) - .show_ui(ui, |ui| { - if ui - .selectable_label(mapping.source.device().is_none(), "Any device") - .clicked() - { - mapping.source = mapping.source.for_any_device(); - } - let own = mapping.source.device().map(str::to_string); - let mut keys: Vec = devices.to_vec(); - if let Some(own) = own - && !keys.contains(&own) - { - keys.push(own); - } - for key in keys { - let current = mapping.source.device() == Some(key.as_str()); - if ui.selectable_label(current, &key).clicked() { - mapping.source = mapping.source.for_device(&key); - } - } - }); + // The device names, with the mapping's own when it is not + // among those heard now. + let mut keys: Vec = devices.to_vec(); + if let Some(own) = mapping.source.device() + && !keys.iter().any(|key| key == own) + { + keys.push(own.to_string()); + } + let mut chosen = mapping.source.device().map(str::to_string); + let mut options: Vec<(Option, &str)> = vec![(None, "Any device")]; + options.extend(keys.iter().map(|key| (Some(key.clone()), key.as_str()))); + if widgets::select(ui, "mapping-device", &mut chosen, &options, SELECT).changed() { + mapping.source = match chosen { + Some(device) => mapping.source.for_device(&device), + None => mapping.source.for_any_device(), + }; + } }, ); } @@ -1084,19 +1098,9 @@ fn mapping_options( ), |ui| { // Right to left: the high end, "to", the low end. - ui.add( - egui::DragValue::new(&mut mapping.range[1]) - .range(0.0..=1.0) - .speed(0.005) - .fixed_decimals(2), - ); + fraction(ui, "mapping-range-high", &mut mapping.range[1], 0.0, 1.0); ui.label(egui::RichText::new("to").color(theme::rgb(theme.text_muted))); - ui.add( - egui::DragValue::new(&mut mapping.range[0]) - .range(0.0..=1.0) - .speed(0.005) - .fixed_decimals(2), - ); + fraction(ui, "mapping-range-low", &mut mapping.range[0], 0.0, 1.0); }, ); group.toggle( @@ -1106,18 +1110,9 @@ fn mapping_options( group.row( Row::new("Curve").description("How the source's travel maps onto the range."), |ui| { - egui::ComboBox::from_id_salt("mapping-curve") - .selected_text(mapping.curve.label()) - .show_ui(ui, |ui| { - for curve in Curve::ALL { - if ui - .selectable_label(mapping.curve == curve, curve.label()) - .clicked() - { - mapping.curve = curve; - } - } - }); + let options: Vec<(Curve, &str)> = + Curve::ALL.into_iter().map(|c| (c, c.label())).collect(); + widgets::select(ui, "mapping-curve", &mut mapping.curve, &options, SELECT); }, ); group.row( @@ -1126,18 +1121,17 @@ fn mapping_options( Jump follows at once.", ), |ui| { - egui::ComboBox::from_id_salt("mapping-takeover") - .selected_text(mapping.takeover.label()) - .show_ui(ui, |ui| { - for mode in [Takeover::Pickup, Takeover::Jump] { - if ui - .selectable_label(mapping.takeover == mode, mode.label()) - .clicked() - { - mapping.takeover = mode; - } - } - }); + let options = [ + (Takeover::Pickup, Takeover::Pickup.label()), + (Takeover::Jump, Takeover::Jump.label()), + ]; + widgets::select( + ui, + "mapping-takeover", + &mut mapping.takeover, + &options, + SELECT, + ); }, ); group.row( @@ -1146,18 +1140,11 @@ fn mapping_options( held.", ), |ui| { - egui::ComboBox::from_id_salt("mapping-button") - .selected_text(mapping.button.label()) - .show_ui(ui, |ui| { - for mode in [ButtonMode::Toggle, ButtonMode::Momentary] { - if ui - .selectable_label(mapping.button == mode, mode.label()) - .clicked() - { - mapping.button = mode; - } - } - }); + let options = [ + (ButtonMode::Toggle, ButtonMode::Toggle.label()), + (ButtonMode::Momentary, ButtonMode::Momentary.label()), + ]; + widgets::select(ui, "mapping-button", &mut mapping.button, &options, SELECT); }, ); group.row( @@ -1165,12 +1152,7 @@ fn mapping_options( "Where a fader counts as pressed when it drives a button, a command or a toggle.", ), |ui| { - ui.add( - egui::DragValue::new(&mut mapping.threshold) - .range(0.05..=0.95) - .speed(0.005) - .fixed_decimals(2), - ); + fraction(ui, "mapping-threshold", &mut mapping.threshold, 0.05, 0.95); }, ); } @@ -1217,27 +1199,21 @@ fn add_rows( targets: &Targets<'_>, ) { rows.row(Row::new("Control"), |ui| { - egui::ComboBox::from_id_salt("add-kind") - .selected_text(kind_label(form.kind)) - .show_ui(ui, |ui| { - for kind in [ - AddKind::SceneControl, - AddKind::Meta, - AddKind::Command, - AddKind::Cue, - AddKind::Fav, - AddKind::Preset, - AddKind::Macro, - ] { - if ui - .selectable_label(form.kind == kind, kind_label(kind)) - .clicked() - { - form.kind = kind; - form.text.clear(); - } - } - }); + let kinds = [ + AddKind::SceneControl, + AddKind::Meta, + AddKind::Command, + AddKind::Cue, + AddKind::Fav, + AddKind::Preset, + AddKind::Macro, + ]; + let options: Vec<(AddKind, &str)> = kinds.into_iter().map(|k| (k, kind_label(k))).collect(); + let mut kind = form.kind; + if widgets::select(ui, "add-kind", &mut kind, &options, SELECT).changed() { + form.kind = kind; + form.text.clear(); + } }); let hint = match form.kind { AddKind::SceneControl => { @@ -1254,74 +1230,68 @@ fn add_rows( AddKind::SceneControl => control_picker(ui, theme, form, targets.scene, "control name"), AddKind::Meta => control_picker(ui, theme, form, targets.meta, "meta control name"), AddKind::Command => { - egui::ComboBox::from_id_salt("add-command") - .selected_text(if form.text.is_empty() { - "choose a command" - } else { - form.text.as_str() - }) - .show_ui(ui, |ui| { - for command in CommandId::ALL.into_iter().filter(|c| c.mappable()) { - if ui - .selectable_label(form.text == command.id(), command.name()) - .clicked() - { - form.text = command.id().to_string(); - } - } - }); + let options: Vec<(String, &str)> = CommandId::ALL + .into_iter() + .filter(|c| c.mappable()) + .map(|c| (c.id().to_string(), c.name())) + .collect(); + let mut chosen = form.text.clone(); + if widgets::select(ui, "add-command", &mut chosen, &options, FIELD).changed() { + form.text = chosen; + } } AddKind::Cue => { form::field(ui, theme, &mut form.text, "cue number", SHORT_FIELD); } AddKind::Fav => { - egui::ComboBox::from_id_salt("add-fav") - .selected_text(if form.text.is_empty() { - "choose a slot" - } else { - form.text.as_str() - }) - .show_ui(ui, |ui| { - for slot in 1..=strobe_scene::preset::FAV_SLOTS { - let text = slot.to_string(); - if ui.selectable_label(form.text == text, &text).clicked() { - form.text = text; - } - } - }); + let slots: Vec = (1..=strobe_scene::preset::FAV_SLOTS) + .map(|slot| slot.to_string()) + .collect(); + let options: Vec<(String, &str)> = slots + .iter() + .map(|slot| (slot.clone(), slot.as_str())) + .collect(); + let mut chosen = form.text.clone(); + if widgets::select(ui, "add-fav", &mut chosen, &options, SHORT_FIELD).changed() { + form.text = chosen; + } } AddKind::Preset => { if !targets.presets.is_empty() { - egui::ComboBox::from_id_salt("add-preset") - .selected_text("or pick one") - .show_ui(ui, |ui| { - for name in targets.presets { - if ui.selectable_label(form.text == *name, name).clicked() { - form.text.clone_from(name); - } - } - }); + let options: Vec<(String, &str)> = targets + .presets + .iter() + .map(|name| (name.clone(), name.as_str())) + .collect(); + // Picking fills the name field beside it; nothing stays chosen. + let mut chosen = String::new(); + if widgets::select(ui, "add-preset", &mut chosen, &options, FIELD * 0.8).changed() { + form.text = chosen; + } } form::field(ui, theme, &mut form.text, "preset name", FIELD * 0.8); } AddKind::Macro => { - egui::ComboBox::from_id_salt("add-macro") - .selected_text(if form.text.is_empty() { - "choose a macro" - } else { - form.text.as_str() + let labels: Vec<(String, String)> = remote + .engine + .macros + .all() + .iter() + .map(|found| { + ( + found.id.to_string(), + format!("{} (#{})", found.name, found.id), + ) }) - .show_ui(ui, |ui| { - for found in remote.engine.macros.all() { - let label = format!("{} (#{})", found.name, found.id); - if ui - .selectable_label(form.text == found.id.to_string(), label) - .clicked() - { - form.text = found.id.to_string(); - } - } - }); + .collect(); + let options: Vec<(String, &str)> = labels + .iter() + .map(|(id, label)| (id.clone(), label.as_str())) + .collect(); + let mut chosen = form.text.clone(); + if widgets::select(ui, "add-macro", &mut chosen, &options, FIELD).changed() { + form.text = chosen; + } } }); let bank = match form.kind { @@ -1333,13 +1303,17 @@ fn add_rows( rows.row( Row::new("Component").description("Which part of a pad or a colour the source moves."), |ui| { - // Right to left: the last component first. + // Right to left: the last component first. The chosen one is + // the filled button. for component in (0..dims).rev() { let name = ["x or red", "y or green", "z or blue"][component.min(2)]; - if ui - .selectable_label(usize::from(form.component) == component, name) - .clicked() - { + let chosen = usize::from(form.component) == component; + let response = if chosen { + widgets::primary_button(ui, theme, name) + } else { + widgets::button(ui, theme, None, name) + }; + if response.clicked() { form.component = component as u8; } } @@ -1437,19 +1411,17 @@ fn control_picker( if let Some(bank) = bank && !bank.defs().is_empty() { - egui::ComboBox::from_id_salt("add-control") - .selected_text("or pick one") - .show_ui(ui, |ui| { - for def in bank.defs() { - if ui - .selectable_label(form.text == def.name, &def.name) - .clicked() - { - form.text.clone_from(&def.name); - form.component = 0; - } - } - }); + let options: Vec<(String, &str)> = bank + .defs() + .iter() + .map(|def| (def.name.clone(), def.name.as_str())) + .collect(); + // Picking fills the name field beside it; nothing stays chosen. + let mut chosen = String::new(); + if widgets::select(ui, "add-control", &mut chosen, &options, FIELD * 0.8).changed() { + form.text = chosen; + form.component = 0; + } } form::field(ui, theme, &mut form.text, hint, FIELD * 0.8); } diff --git a/crates/strobe-app/src/ui/mod.rs b/crates/strobe-app/src/ui/mod.rs index d9195cee..e45bd11c 100644 --- a/crates/strobe-app/src/ui/mod.rs +++ b/crates/strobe-app/src/ui/mod.rs @@ -73,6 +73,7 @@ pub mod import; pub mod inspector; pub mod keys; pub mod lan; +pub mod m3; pub mod macros; pub mod map; pub mod modal; diff --git a/crates/strobe-app/src/ui/modal.rs b/crates/strobe-app/src/ui/modal.rs index bea16a0e..49069293 100644 --- a/crates/strobe-app/src/ui/modal.rs +++ b/crates/strobe-app/src/ui/modal.rs @@ -1,8 +1,8 @@ // ============================================================================ // Module: strobe_app::ui::modal -// Description: The one confirmation card, and the scrim behind it. +// Description: The one confirmation dialog (an M3 dialog with its scrim). // -// Dependencies: egui; super::{theme, widgets, motion}, crate::palette. +// Dependencies: egui, egui_material3; crate::palette. // Ported from rustaman's `gui::ui::modal` (D5, D130). // ============================================================================ @@ -34,22 +34,17 @@ //! binding it to a destructive button means a stray keystroke while the card //! is opening does the thing. -use super::motion; -use super::theme::{self, SPACE_LG, SPACE_SM}; -use super::widgets; use crate::palette::Palette; -use egui::{Align2, CornerRadius, Key, Sense, Ui, Vec2}; +use egui::Key; +use egui_material3::MaterialDialog; +use egui_material3::dialog::{DialogCloseReason, DialogType}; -/// The modal card's width: wide enough for a sentence naming a scene without +/// The dialog's width: wide enough for a sentence naming a scene without /// wrapping mid-name, narrow enough to read as a dialog rather than a page. const CARD_WIDTH: f32 = 420.0; -/// The scrim's opacity over the window behind, enough to push it back -/// without hiding it. -const SCRIM_ALPHA: u8 = 160; - -/// How far the card rises as it arrives. -const RISE: f32 = 6.0; +/// The id the dialog is shown under: one at a time, so one id. +const DIALOG_ID: &str = "strobe-confirmation"; /// What a pending confirmation asks. #[derive(Debug, Clone, PartialEq, Eq)] @@ -76,50 +71,42 @@ impl Confirmation { } } -/// Draws the card for `question` over a scrim. Returns the answer once given: -/// `Some(true)` to confirm, `Some(false)` to cancel. +/// Draws the dialog for `question` over its scrim. Returns the answer once +/// given: `Some(true)` to confirm, `Some(false)` to cancel. +/// +/// The M3 dialog draws its own scrim, takes the clicks that miss it, traps +/// focus and cancels on Escape. A click on the scrim does not dismiss it +/// (the old card did not either): a stray click during a show should not +/// answer a question about files. pub fn draw(ctx: &egui::Context, theme: &Palette, question: &Confirmation) -> Option { - let progress = motion::transition(ctx, egui::Id::unique("modal-card"), true, motion::QUICK); - let screen = ctx.content_rect(); - // Painted on a foreground layer so it covers every panel. - let painter = ctx.layer_painter(egui::LayerId::new( - egui::Order::Foreground, - egui::Id::unique("modal"), - )); - let scrim_alpha = (f32::from(SCRIM_ALPHA) * progress) as u8; - painter.rect_filled( - screen, - CornerRadius::ZERO, - theme::translucent(theme.app, scrim_alpha), - ); - + // The palette drives the M3 colours already (`ui::m3::scheme`). + let _ = theme; let mut answer = None; - // An `Area` rather than a `Window`: no title bar, no move handle, no - // close button, and it cannot be left open behind the main window. - egui::Area::new(egui::Id::unique("modal-card")) - .order(egui::Order::Foreground) - .anchor( - Align2::CENTER_CENTER, - Vec2::new(0.0, RISE * (1.0 - progress)), - ) - .show(ctx, |ui| { - ui.set_opacity(progress); - egui::Frame::new() - .fill(theme::rgb(theme.raised)) - .stroke(egui::Stroke::new(1.0, theme::rgb(theme.border))) - .corner_radius(CornerRadius::same(theme::RADIUS_LG)) - .inner_margin(theme::margin(SPACE_LG)) - .shadow(egui::epaint::Shadow { - offset: [0, 8], - blur: 24, - spread: 0, - // Alpha-only: a shadow is lighting, not a theme colour. - color: egui::Color32::from_black_alpha(96), - }) - .show(ui, |ui| { - buttons_and_text(ui, theme, question, &mut answer); - }); - }); + // Open for as long as the question is pending: the caller drops the + // question once it has an answer. + let mut open = true; + let response = MaterialDialog::new(egui::Id::unique(DIALOG_ID), &question.title, &mut open) + .dialog_type(DialogType::Confirm) + .supporting_text(&question.body) + .max_width(CARD_WIDTH) + .min_width(CARD_WIDTH) + .dismiss_on_scrim(false) + .quick(true) + .text_action(&question.cancel, || {}) + .filled_action(&question.confirm, || {}) + .destructive(question.destructive) + .show(ctx); + match response.close_reason { + Some(DialogCloseReason::Action(1)) => answer = Some(true), + Some( + DialogCloseReason::Action(_) + | DialogCloseReason::Escape + | DialogCloseReason::Scrim + | DialogCloseReason::CloseButton + | DialogCloseReason::Content, + ) => answer = Some(false), + None => {} + } ctx.input(|input| { if input.key_pressed(Key::Escape) { @@ -129,84 +116,9 @@ pub fn draw(ctx: &egui::Context, theme: &Palette, question: &Confirmation) -> Op answer = Some(true); } }); - - // The scrim swallows clicks so a click that misses the card does not - // reach the pane behind it. - egui::Area::new(egui::Id::unique("modal-scrim")) - .order(egui::Order::Middle) - .fixed_pos(screen.min) - .show(ctx, |ui| { - // The scrim only has to take the clicks; nothing reads them. - let _ = ui.allocate_exact_size(screen.size(), Sense::click()); - }); answer } -fn buttons_and_text( - ui: &mut Ui, - theme: &Palette, - question: &Confirmation, - answer: &mut Option, -) { - ui.set_width(CARD_WIDTH); - ui.label( - egui::RichText::new(&question.title) - .color(theme::rgb(theme.text)) - .size(16.0) - .strong(), - ); - ui.add_space(SPACE_SM); - ui.label( - egui::RichText::new(&question.body) - .color(theme::rgb(theme.text_muted)) - .text_style(egui::TextStyle::Small), - ); - ui.add_space(SPACE_LG); - ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - // The destructive button is on the right, where the eye ends up, but - // Cancel is adjacent to it rather than across the card: a gap - // between them is a gap the pointer travels through on the way to - // the wrong one. - let confirmed = if question.destructive { - danger_button(ui, theme, &question.confirm) - } else { - widgets::primary_button(ui, theme, &question.confirm) - }; - if confirmed.clicked() { - *answer = Some(true); - } - ui.add_space(SPACE_SM); - if widgets::button(ui, theme, None, &question.cancel).clicked() { - *answer = Some(false); - } - }); -} - -/// A destructive button: the danger colour, with the on-accent label. -fn danger_button(ui: &mut Ui, theme: &Palette, label: &str) -> egui::Response { - let font = egui::TextStyle::Button.resolve(ui.style()); - let galley = - ui.painter() - .layout_no_wrap(label.to_string(), font, theme::rgb(theme.text_on_accent)); - let size = galley.size() + Vec2::new(theme::SPACE_MD * 2.0, SPACE_SM); - let (rect, response) = ui.allocate_exact_size(size, Sense::click()); - let fill = widgets::hover_fill( - ui, - response.id, - response.hovered(), - theme.danger, - theme.danger, - ); - ui.painter() - .rect_filled(rect, CornerRadius::same(theme::RADIUS), fill); - ui.painter().galley( - rect.center() - galley.size() / 2.0, - galley, - theme::rgb(theme.text_on_accent), - ); - response.on_hover_cursor(egui::CursorIcon::PointingHand) -} - #[cfg(test)] mod tests { use super::*; @@ -250,12 +162,12 @@ mod tests { fn answer_with(events: Vec) -> Option { let ctx = egui::Context::default(); let theme = crate::palette::fallback().clone(); - theme::apply(&ctx, &theme, theme::Density::default()); + crate::ui::theme::apply(&ctx, &theme, crate::ui::theme::Density::default()); let question = replace(); let mut answer = None; let _ = crate::ui::testing::run( &ctx, - crate::ui::testing::input(Vec2::new(800.0, 600.0), events), + crate::ui::testing::input(egui::Vec2::new(800.0, 600.0), events), |ui| { answer = draw(ui.ctx(), &theme, &question); }, diff --git a/crates/strobe-app/src/ui/playlist.rs b/crates/strobe-app/src/ui/playlist.rs index 495a9176..1279c29a 100644 --- a/crates/strobe-app/src/ui/playlist.rs +++ b/crates/strobe-app/src/ui/playlist.rs @@ -107,8 +107,7 @@ fn disabled_cues(ui: &mut Ui, show: &Show, theme: &Palette, actions: &mut Vec, theme: &Palette, actions: & rows.wide_row( Row::new("Transition").description("How generated cues arrive."), |ui| { - // Right to left: the last choice first. - for choice in TransitionChoice::ALL.into_iter().rev() { - if ui - .selectable_label(form.transition == choice, choice.label()) - .clicked() - { - form.transition = choice; - changed = true; - } - } + let options = TransitionChoice::ALL.map(|choice| (choice, choice.label())); + changed |= widgets::select( + ui, + "generate-transition", + &mut form.transition, + &options, + 130.0, + ) + .changed(); }, ); if matches!( diff --git a/crates/strobe-app/src/ui/presets.rs b/crates/strobe-app/src/ui/presets.rs index debebf98..3bac1ab2 100644 --- a/crates/strobe-app/src/ui/presets.rs +++ b/crates/strobe-app/src/ui/presets.rs @@ -201,11 +201,11 @@ pub fn fav_row(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mu }); } response.context_menu(|ui| { - if ui.button("Store the playing scene here").clicked() { + if widgets::menu_item(ui, None, "Store the playing scene here", true).clicked() { actions.push(Action::StoreFav(slot)); ui.close(); } - if filled && ui.button("Clear this slot").clicked() { + if filled && widgets::menu_item(ui, None, "Clear this slot", true).clicked() { actions.push(Action::ClearFav(slot)); ui.close(); } diff --git a/crates/strobe-app/src/ui/projectors.rs b/crates/strobe-app/src/ui/projectors.rs index 431c977e..bbb5adfe 100644 --- a/crates/strobe-app/src/ui/projectors.rs +++ b/crates/strobe-app/src/ui/projectors.rs @@ -264,12 +264,12 @@ fn web(ui: &mut Ui, theme: &Palette, panel: &ProjectorPanel<'_>, actions: &mut V /// A password field: dots, unless the field is being edited. fn secret(ui: &mut Ui, theme: &Palette, text: &mut String, hint: &str) { + let _ = theme; // Colours reach the widget through the M3 theme (D710). ui.add( - egui::TextEdit::singleline(text) + egui_material3::MaterialInput::outlined(text) .password(true) - .hint_text(egui::RichText::new(hint).color(theme::rgb(theme.text_faint))) - .desired_width(FIELD) - .margin(theme::margin_xy(theme::SPACE_SM, theme::SPACE_XS)), + .placeholder(hint) + .width(FIELD), ); } diff --git a/crates/strobe-app/src/ui/settings.rs b/crates/strobe-app/src/ui/settings.rs index c411b509..5aa19201 100644 --- a/crates/strobe-app/src/ui/settings.rs +++ b/crates/strobe-app/src/ui/settings.rs @@ -178,6 +178,9 @@ pub const NAV_BESIDE: f32 = 620.0; /// The width of the category list. const NAV_WIDTH: f32 = 200.0; +/// The widest a dropdown in a settings row grows. +const SELECT_WIDTH: f32 = 220.0; + // Row titles. Each is drawn on its page and listed in `INDEX`, from one // constant, so a search result always names a row that exists. const OUTPUT_WINDOW: &str = "Output window"; @@ -522,19 +525,14 @@ fn search_field(ui: &mut Ui, theme: &Palette, query: &mut String) { /// The narrow layout's page picker. fn page_picker(ui: &mut Ui, settings: &mut SettingsUi) { - egui::ComboBox::from_id_salt("settings-page") - .selected_text(settings.page.title()) - .show_ui(ui, |ui| { - for page in SettingsPage::ALL { - if ui - .selectable_label(settings.page == page, page.title()) - .clicked() - { - settings.page = page; - settings.query.clear(); - } - } - }); + let options: Vec<(SettingsPage, &str)> = SettingsPage::ALL + .into_iter() + .map(|page| (page, page.title())) + .collect(); + let width = ui.available_width(); + if widgets::select(ui, "settings-page", &mut settings.page, &options, width).changed() { + settings.query.clear(); + } } /// The category list, or with a query, the rows it matches. @@ -887,18 +885,16 @@ fn sharing( readback.", ), |ui| { - egui::ComboBox::from_id_salt("ndi-fps") - .selected_text(rate_label(state.live.ndi_fps)) - .show_ui(ui, |ui| { - for rate in NDI_RATES { - if ui - .selectable_label(state.live.ndi_fps == rate, rate_label(rate)) - .clicked() - { - chosen = Some(SharingEdit::NdiFps(rate)); - } - } - }); + let labels = NDI_RATES.map(rate_label); + let options: Vec<(u32, &str)> = NDI_RATES + .into_iter() + .zip(labels.iter().map(String::as_str)) + .collect(); + let mut rate = state.live.ndi_fps; + let width = ui.available_width().min(SELECT_WIDTH); + if widgets::select(ui, "ndi-fps", &mut rate, &options, width).changed() { + chosen = Some(SharingEdit::NdiFps(rate)); + } }, ); group.row( @@ -907,20 +903,20 @@ fn sharing( the render scale, or a fixed size that stays put whatever the scene renders at.", ), |ui| { - egui::ComboBox::from_id_salt("share-size") - .selected_text(size_label(state.live.size)) - .show_ui(ui, |ui| { - let options = - std::iter::once(None).chain(SHARE_SIZES.into_iter().map(Some)); - for size in options { - if ui - .selectable_label(state.live.size == size, size_label(size)) - .clicked() - { - chosen = Some(SharingEdit::Size(size)); - } - } - }); + let sizes: Vec> = std::iter::once(None) + .chain(SHARE_SIZES.into_iter().map(Some)) + .collect(); + let labels: Vec = sizes.iter().map(|size| size_label(*size)).collect(); + let options: Vec<(Option<[u32; 2]>, &str)> = sizes + .iter() + .copied() + .zip(labels.iter().map(String::as_str)) + .collect(); + let mut size = state.live.size; + let width = ui.available_width().min(SELECT_WIDTH); + if widgets::select(ui, "share-size", &mut size, &options, width).changed() { + chosen = Some(SharingEdit::Size(size)); + } }, ); group.row( @@ -984,25 +980,31 @@ fn prerender( /// The output-monitor combo box. pub fn monitor_picker(ui: &mut Ui, model: &Model<'_>, actions: &mut Vec) { - let current = model - .output_monitor - .and_then(|index| model.monitors.get(index)) - .map_or("Output monitor", String::as_str); - egui::ComboBox::from_id_salt("output-monitor") - .selected_text(current) - .show_ui(ui, |ui| { - if model.monitors.is_empty() { - ui.label("No monitors reported"); - } - for (index, label) in model.monitors.iter().enumerate() { - if ui - .selectable_label(model.output_monitor == Some(index), label) - .clicked() - { - actions.push(Action::MoveToMonitor(index)); - } - } - }); + if model.monitors.is_empty() { + ui.label("No monitors reported"); + return; + } + let options: Vec<(usize, &str)> = model + .monitors + .iter() + .enumerate() + .map(|(index, label)| (index, label.as_str())) + .collect(); + // No monitor chosen yet says so; picking one moves the output there. + let mut chosen = model.output_monitor.unwrap_or(usize::MAX); + let width = ui.available_width().min(SELECT_WIDTH); + if widgets::select_with_placeholder( + ui, + "output-monitor", + &mut chosen, + &options, + width, + "Not chosen", + ) + .changed() + { + actions.push(Action::MoveToMonitor(chosen)); + } } fn appearance(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut Vec) { @@ -1019,30 +1021,37 @@ fn appearance(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut if !problems.is_empty() { row = row.note(&problems, theme.warning); } - let current = model.ui.palette().name.clone(); let mut chosen = None; group.row(row, |ui| { - egui::ComboBox::from_id_salt("theme") - .width(ui.available_width().min(200.0)) - .selected_text(current) - .show_ui(ui, |ui| { - for palette in model.ui.catalog().themes() { - let label = format!( - "{}{}", - palette.name, - match palette.mode { - crate::palette::Mode::Dark => "", - crate::palette::Mode::Light => " (light)", - } - ); - if ui - .selectable_label(palette.id == model.ui.theme_id(), label) - .clicked() - { - chosen = Some(palette.id.clone()); + let labels: Vec = model + .ui + .catalog() + .themes() + .iter() + .map(|palette| { + format!( + "{}{}", + palette.name, + match palette.mode { + crate::palette::Mode::Dark => "", + crate::palette::Mode::Light => " (light)", } - } - }); + ) + }) + .collect(); + let options: Vec<(String, &str)> = model + .ui + .catalog() + .themes() + .iter() + .map(|palette| palette.id.clone()) + .zip(labels.iter().map(String::as_str)) + .collect(); + let mut id = model.ui.theme_id().to_owned(); + let width = ui.available_width().min(200.0); + if widgets::select(ui, "theme", &mut id, &options, width).changed() { + chosen = Some(id); + } }); if let Some(id) = chosen { model.ui.set_theme(&id); @@ -1055,14 +1064,14 @@ fn appearance(ui: &mut Ui, model: &mut Model<'_>, theme: &Palette, actions: &mut tighter rows.", ), |ui| { - // Right to left: the last is added first. - for density in theme::Density::ALL.into_iter().rev() { - if ui - .selectable_label(current == density, density.label()) - .clicked() - { - picked = Some(density); - } + let options: Vec<(theme::Density, &str)> = theme::Density::ALL + .into_iter() + .map(|density| (density, density.label())) + .collect(); + let mut density = current; + let width = ui.available_width().min(SELECT_WIDTH); + if widgets::select(ui, "density", &mut density, &options, width).changed() { + picked = Some(density); } }, ); diff --git a/crates/strobe-app/src/ui/shell_tests.rs b/crates/strobe-app/src/ui/shell_tests.rs index 0d7c1108..176fe603 100644 --- a/crates/strobe-app/src/ui/shell_tests.rs +++ b/crates/strobe-app/src/ui/shell_tests.rs @@ -2365,14 +2365,20 @@ fn every_row_settings_search_finds_is_drawn_on_its_page() -> Result<()> { /// clip), in paint order. Rows, not galleys: a label wrapped in a /// horizontal layout starts mid-line, and its galley's box covers whatever /// sits before it on the first line. +/// +/// Icons are not text. They are Material Symbols glyphs (D710), in the +/// Unicode private use area, and a glyph's row box is its advance and line +/// height, wider than the icon's ink: a chevron set beside its label would +/// count as overlapping it. Rows made only of icon glyphs are left out. fn texts(drawn: &Drawn) -> Vec<(usize, String, Rect)> { + let icon = |c: char| ('\u{E000}'..='\u{F8FF}').contains(&c) || c >= '\u{F0000}'; let mut out = Vec::new(); for (index, clipped) in drawn.shapes.iter().enumerate() { let egui::Shape::Text(text) = &clipped.shape else { continue; }; for row in &text.galley.rows { - if row.glyphs.is_empty() { + if row.glyphs.is_empty() || row.glyphs.iter().all(|g| icon(g.chr)) { continue; } let rect = row diff --git a/crates/strobe-app/src/ui/side.rs b/crates/strobe-app/src/ui/side.rs index bc6b17f8..48e6d55a 100644 --- a/crates/strobe-app/src/ui/side.rs +++ b/crates/strobe-app/src/ui/side.rs @@ -367,102 +367,60 @@ pub fn audio_level(rms: f32) -> f32 { ((db + 60.0) / 60.0).clamp(0.0, 1.0) } -/// The tab bar: icon tabs in equal cells, the `shown` one a filled tile -/// with an accent underline. The names are in the tooltips, and beside the -/// icons when the panel is wide enough for them. With `controls_in_main` -/// the Controls tab is dimmed: the main view has them (D291). +/// The tab bar: M3 secondary tabs in equal cells, each with its icon. The +/// names are in the tooltips, and beside the icons when the panel is wide +/// enough for them. With `controls_in_main` the Controls tab is disabled: +/// the main view has them (D291). fn tab_bar( ui: &mut Ui, model: &mut Model<'_>, - theme: &Palette, + _theme: &Palette, shown: SideTab, controls_in_main: bool, ) { let width = ui.available_width(); let labelled = width >= LABELLED; - let cell = width / SideTab::ALL.len() as f32; - let (rect, _) = ui.allocate_exact_size(Vec2::new(width, 28.0), Sense::hover()); - let mut chosen = None; - for (index, tab) in SideTab::ALL.into_iter().enumerate() { - let cell_rect = egui::Rect::from_min_size( - egui::pos2(rect.left() + cell * index as f32, rect.top()), - Vec2::new(cell, rect.height()), - ); - let id = egui::Id::unique(("side-tab", tab.key())); - let elsewhere = controls_in_main && tab == SideTab::Controls; - let tooltip = if elsewhere { + let mut index = SideTab::ALL + .iter() + .position(|tab| *tab == shown) + .unwrap_or(0); + let before = index; + let mut tabs = egui_material3::MaterialTabs::secondary(&mut index).id_salt("side-tabs"); + let tooltip = |tab: SideTab| { + if controls_in_main && tab == SideTab::Controls { "Controls: shown large in the main view now. Switch it to Scenes to have them here." } else { tab.tooltip() - }; - let response = super::help::hovered(ui.interact(cell_rect, id, Sense::click()), tooltip); - let active = shown == tab; - let fill = widgets::hover_fill( - ui, - response.id, - response.hovered(), - if active { theme.raised } else { theme.panel }, - theme.raised, - ); - let painter = ui.painter(); - painter.rect_filled(cell_rect, egui::CornerRadius::same(theme::RADIUS), fill); - let colour = if active { - theme.accent - } else if elsewhere { - theme.text_faint - } else { - theme.text_muted - }; - let glyph = icons::INLINE; - let font = egui::FontId::new(10.5, egui::FontFamily::Proportional); - // Laid out only when it is drawn; egui caches the galley. - let galley = labelled - .then(|| painter.layout_no_wrap(tab.caption().to_owned(), font, theme::rgb(colour))); - let content = glyph + galley.as_ref().map_or(0.0, |g| SPACE_XS + g.size().x); - let x = cell_rect.center().x - content / 2.0; - icons::paint( - painter, - egui::Rect::from_center_size( - egui::pos2(x + glyph / 2.0, cell_rect.center().y), - Vec2::splat(glyph), - ), - tab.icon(), - theme::rgb(colour), - ); - if let Some(galley) = galley { - painter.galley( - egui::pos2( - x + glyph + SPACE_XS, - cell_rect.center().y - galley.size().y / 2.0, - ), - galley, - theme::rgb(colour), - ); } - // The underline grows out from the centre as the choice moves. - let grown = super::motion::toggle(ui.ctx(), id.with("under"), active, super::motion::QUICK); - if grown > 0.0 { - let underline = egui::Rect::from_center_size( - egui::pos2(cell_rect.center().x, cell_rect.bottom() - 1.0), - Vec2::new((cell_rect.width() - SPACE_SM) * grown, 2.0), - ); - painter.rect_filled( - underline, - egui::CornerRadius::same(1), - theme::rgb(theme.accent), - ); - } - if response.clicked() && !elsewhere { - chosen = Some(tab); + }; + for tab in SideTab::ALL { + let elsewhere = controls_in_main && tab == SideTab::Controls; + let (name, _) = super::m3::symbol(tab.icon()); + let label = if labelled { tab.caption() } else { "" }; + tabs = tabs.item( + egui_material3::TabItem::new(label) + .icon(name) + .tooltip(tooltip(tab)) + .accessible_label(tab.caption()) + .enabled(!elsewhere), + ); + } + let response = ui.add(tabs); + // Each tab shows its own tooltip; the help bar says the hovered one's + // too, picked by where the pointer is within the row. + if response.hovered() + && let Some(pos) = ui.ctx().pointer_hover_pos() + { + let cell = response.rect.width() / SideTab::ALL.len() as f32; + let hovered = ((pos.x - response.rect.left()) / cell).floor().max(0.0) as usize; + if let Some(tab) = SideTab::ALL.get(hovered) { + super::help::say(tooltip(*tab)); } } - ui.painter().hline( - rect.x_range(), - rect.bottom(), - egui::Stroke::new(1.0, theme::rgb(theme.border)), - ); - if let Some(tab) = chosen { - model.ui.side_tab = tab; + if index != before + && let Some(tab) = SideTab::ALL.get(index) + { + model.ui.side_tab = *tab; } } diff --git a/crates/strobe-app/src/ui/tags.rs b/crates/strobe-app/src/ui/tags.rs index 9a67ce98..de9fe0ad 100644 --- a/crates/strobe-app/src/ui/tags.rs +++ b/crates/strobe-app/src/ui/tags.rs @@ -25,6 +25,7 @@ //! came with and offers [`COPY_LABEL`] instead of Edit, so the field that //! would write into Synesthesia's folder is never drawn. +use super::form; use super::model::Action; use super::theme; use super::widgets; @@ -108,8 +109,7 @@ pub fn row( ); } if let Some(dir) = place.read_only { - if ui - .small_button(COPY_LABEL) + if widgets::text_button(ui, None, COPY_LABEL) .on_hover_text(READ_ONLY_HINT) .clicked() { @@ -117,8 +117,7 @@ pub fn row( } return; } - if ui - .small_button(if tags.is_empty() { "Add tags" } else { "Edit" }) + if widgets::text_button(ui, None, if tags.is_empty() { "Add tags" } else { "Edit" }) .on_hover_text( "Tags find the scene in the library and pick it when generating a playlist", ) @@ -135,20 +134,23 @@ pub fn row( }; let mut done = false; ui.horizontal(|ui| { - let field = ui.add( - egui::TextEdit::singleline(&mut editing.text) - .hint_text("dark, tunnel, audio reactive") - .desired_width((ui.available_width() - BUTTONS).max(MIN_FIELD)), + let width = (ui.available_width() - BUTTONS).max(MIN_FIELD); + let field = form::field( + ui, + theme, + &mut editing.text, + "dark, tunnel, audio reactive", + width, ); let entered = field.lost_focus() && ui.input(|input| input.key_pressed(egui::Key::Enter)); - if ui.small_button("Save").clicked() || entered { + if widgets::primary_button(ui, theme, "Save").clicked() || entered { actions.push(Action::SetSceneTags { scene: editing.scene.clone(), tags: strobe_scene::tags::parse_list(&editing.text), }); done = true; } - if ui.small_button("Cancel").clicked() { + if widgets::text_button(ui, None, "Cancel").clicked() { done = true; } }); @@ -202,7 +204,7 @@ mod tests { &tags, draft, |ui| { - let _ = ui.small_button("Use frame as picture"); + let _ = widgets::text_button(ui, None, "Use frame as picture"); }, actions, ); diff --git a/crates/strobe-app/src/ui/theme.rs b/crates/strobe-app/src/ui/theme.rs index a1b91c2b..253a46f9 100644 --- a/crates/strobe-app/src/ui/theme.rs +++ b/crates/strobe-app/src/ui/theme.rs @@ -122,7 +122,7 @@ impl Density { } /// Body and button text size. - const fn body(self) -> f32 { + pub(super) const fn body(self) -> f32 { match self { Self::Comfortable => 13.5, Self::Compact => 12.5, @@ -294,6 +294,7 @@ thread_local! { pub fn apply(ctx: &egui::Context, theme: &Palette, density: Density) { ACTIVE.with(|active| active.replace(Rc::new(theme.clone()))); DENSITY.with(|cell| cell.set(density)); + super::m3::install(ctx, theme, density); // egui keeps a separate `Style` for light and dark and picks between // them from the OS setting. The palette already decides which it is, so diff --git a/crates/strobe-app/src/ui/widgets.rs b/crates/strobe-app/src/ui/widgets.rs index 9a94f86c..4c67c495 100644 --- a/crates/strobe-app/src/ui/widgets.rs +++ b/crates/strobe-app/src/ui/widgets.rs @@ -158,32 +158,44 @@ pub fn nav_item( let (rect, response) = ui.allocate_exact_size(Vec2::new(width, height), sense); let painter = ui.painter(); - let id = egui::Id::unique(("nav", label)); - let fill = selection_fill( - ui, - theme, - response.id, - active, - enabled && response.hovered(), - theme.app, + // The M3 navigation-rail item: a 56x32 pill in the secondary + // container colour behind the icon marks the destination (it grows out + // from the centre), the hover state layer sits on the same pill, and + // the label sits under it. No accent bar. + const INDICATOR: Vec2 = Vec2::new(56.0, 32.0); + let icon_centre = if show_label { + egui::pos2(rect.center().x, rect.top() + 18.0) + } else { + rect.center() + }; + let grown = motion::toggle(ui.ctx(), response.id.with("active"), active, motion::QUICK); + let hovered = hover_t(ui, response.id, enabled && response.hovered()); + let pill = Rect::from_center_size( + icon_centre, + Vec2::new(INDICATOR.x * grown.max(0.5), INDICATOR.y), ); - painter.rect_filled(rect, CornerRadius::same(RADIUS), fill); - if active { - accent_bar(ui, painter, id, rect, Bar::Inset, theme.accent); + let pill_radius = CornerRadius::same((INDICATOR.y / 2.0) as u8); + if grown > 0.0 { + painter.rect_filled( + pill, + pill_radius, + theme::rgb(theme.app.lerp(theme.selection, grown)), + ); + } + if hovered > 0.0 { + painter.rect_filled( + Rect::from_center_size(icon_centre, INDICATOR), + pill_radius, + theme::translucent(theme.text, (hovered * 0.08 * 255.0) as u8), + ); } - let colour = if !enabled { theme.text_faint } else if active { - theme.accent + theme.selection_text } else { theme.text_muted }; - let icon_centre = if show_label { - egui::pos2(rect.center().x, rect.top() + 18.0) - } else { - rect.center() - }; icons::paint( painter, Rect::from_center_size(icon_centre, Vec2::splat(icons::NAV)), @@ -204,15 +216,12 @@ pub fn nav_item( /// A borderless square icon button, for the title bar and toolbars. pub fn icon_button(ui: &mut Ui, theme: &Palette, icon: Icon, tooltip: &str) -> Response { - let (rect, response) = ui.allocate_exact_size(Vec2::splat(28.0), Sense::click()); - let fill = hover_fill(ui, response.id, response.hovered(), theme.app, theme.hover); - ui.painter() - .rect_filled(rect, CornerRadius::same(RADIUS), fill); - icons::paint( - ui.painter(), - Rect::from_center_size(rect.center(), Vec2::splat(icons::INLINE)), - icon, - theme::rgb(theme.text), + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let response = ui.add( + egui_material3::MaterialIconButton::standard(super::m3::symbol(icon).1) + .size(egui_material3::IconButtonSize::ExtraSmall) + .min_touch_target(false) + .label(tooltip), ); super::help::hovered(response, tooltip) } @@ -272,69 +281,36 @@ pub fn tool_button_fitted( tooltip: &str, labelled: bool, ) -> Response { - let font = TextStyle::Button.resolve(ui.style()); - let colour = if active { theme.accent } else { theme.text }; - let galley = ui.painter().layout_no_wrap( - if labelled { - label.to_string() + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let (name, glyph) = super::m3::symbol(icon); + let response = if labelled { + let button = if active { + egui_material3::MaterialButton::filled_tonal(label) } else { - String::new() - }, - font, - theme::rgb(colour), - ); - let width = if labelled { - SPACE_SM * 2.0 + icons::INLINE + SPACE_XS + galley.size().x - } else { - SPACE_SM * 2.0 + icons::INLINE - }; - let (rect, response) = ui.allocate_exact_size(Vec2::new(width, 26.0), Sense::click()); - let rest = if active { - theme.accent_soft - } else { - theme.raised - }; - let lifted = if active { - theme.accent_soft + egui_material3::MaterialButton::outlined(label) + }; + ui.add( + button + .size(egui_material3::ButtonSize::ExtraSmall) + .leading_icon(name) + .selected(active), + ) } else { - theme.hover + let button = if active { + egui_material3::MaterialIconButton::filled_tonal(glyph) + } else { + egui_material3::MaterialIconButton::outlined(glyph) + }; + ui.add( + button + .size(egui_material3::IconButtonSize::ExtraSmall) + .min_touch_target(false) + .label(label), + ) }; - let fill = hover_fill(ui, response.id, response.hovered(), rest, lifted); - let painter = ui.painter(); - painter.rect_filled(rect, CornerRadius::same(RADIUS), fill); - if active { - painter.rect_stroke( - rect, - CornerRadius::same(RADIUS), - Stroke::new(1.0, theme::rgb(theme.accent)), - StrokeKind::Inside, - ); - } - icons::paint( - painter, - Rect::from_center_size( - egui::pos2( - rect.left() + SPACE_SM + icons::INLINE / 2.0, - rect.center().y, - ), - Vec2::splat(icons::INLINE), - ), - icon, - theme::rgb(colour), - ); - painter.galley( - egui::pos2( - rect.left() + SPACE_SM + icons::INLINE + SPACE_XS, - rect.center().y - galley.size().y / 2.0, - ), - galley, - theme::rgb(colour), - ); - response.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, true, active, label)); if labelled || !response.hovered() { super::help::hovered(response, tooltip) } else { - // The words the button no longer shows, built only while hovered. super::help::hovered(response, &format!("{label}. {tooltip}")) } } @@ -359,34 +335,18 @@ pub fn transport_button( look: Look, tooltip: &str, ) -> Response { - let sense = match look { - Look::Unavailable => Sense::hover(), - Look::Normal | Look::Active => Sense::click(), - }; - let (rect, response) = ui.allocate_exact_size(Vec2::splat(theme::TRANSPORT_BUTTON), sense); - let (rest, lifted, mark) = match look { - Look::Normal => (theme.raised, theme.hover, theme.text), - Look::Active => (theme.accent_soft, theme.accent_soft, theme.accent), - Look::Unavailable => (theme.panel, theme.panel, theme.text_faint), - }; - let fill = hover_fill(ui, response.id, response.hovered(), rest, lifted); - let painter = ui.painter(); - painter.rect_filled(rect, CornerRadius::same(RADIUS), fill); - let outline = match look { - Look::Active => theme.accent, - Look::Normal | Look::Unavailable => theme.border, + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let glyph = super::m3::symbol(icon).1; + let button = match look { + Look::Normal => egui_material3::MaterialIconButton::filled_tonal(glyph), + Look::Active => egui_material3::MaterialIconButton::filled(glyph), + Look::Unavailable => egui_material3::MaterialIconButton::standard(glyph).enabled(false), }; - painter.rect_stroke( - rect, - CornerRadius::same(RADIUS), - Stroke::new(1.0, theme::rgb(outline)), - StrokeKind::Inside, - ); - icons::paint( - painter, - Rect::from_center_size(rect.center(), Vec2::splat(icons::TRANSPORT)), - icon, - theme::rgb(mark), + let response = ui.add( + button + .size(theme::TRANSPORT_BUTTON) + .min_touch_target(false) + .label(tooltip), ); super::help::hovered(response, tooltip) } @@ -443,27 +403,11 @@ pub fn blackout_button(ui: &mut Ui, theme: &Palette, on: bool, tooltip: &str) -> /// A primary (accent-filled) button. pub fn primary_button(ui: &mut Ui, theme: &Palette, label: &str) -> Response { - let font = TextStyle::Button.resolve(ui.style()); - let galley = - ui.painter() - .layout_no_wrap(label.to_string(), font, theme::rgb(theme.text_on_accent)); - let size = galley.size() + Vec2::new(SPACE_MD * 2.0, SPACE_SM); - let (rect, response) = ui.allocate_exact_size(size, Sense::click()); - let fill = hover_fill( - ui, - response.id, - response.hovered(), - theme.accent, - theme.accent_hover, - ); - ui.painter() - .rect_filled(rect, CornerRadius::same(RADIUS), fill); - ui.painter().galley( - rect.center() - galley.size() / 2.0, - galley, - theme::rgb(theme.text_on_accent), - ); - response.on_hover_cursor(egui::CursorIcon::PointingHand) + let _ = theme; // Colours reach the widget through the M3 theme (D710). + ui.add( + egui_material3::MaterialButton::filled(label).size(egui_material3::ButtonSize::ExtraSmall), + ) + .on_hover_cursor(egui::CursorIcon::PointingHand) } /// The Browse button beside a path field (D470): disabled while a dialog @@ -483,51 +427,72 @@ pub const BUTTON_HEIGHT: f32 = 26.0; /// A secondary button: raised surface, outlined, an optional leading icon. pub fn button(ui: &mut Ui, theme: &Palette, icon: Option, label: &str) -> Response { - let font = TextStyle::Button.resolve(ui.style()); - let galley = ui - .painter() - .layout_no_wrap(label.to_string(), font, theme::rgb(theme.text)); - let lead = if icon.is_some() { - icons::INLINE + SPACE_XS - } else { - 0.0 - }; - let size = Vec2::new(galley.size().x + lead + SPACE_MD * 2.0, BUTTON_HEIGHT); - let (rect, response) = ui.allocate_exact_size(size, Sense::click()); - let fill = hover_fill( - ui, - response.id, - response.hovered(), - theme.raised, - theme.hover, - ); - let painter = ui.painter(); - painter.rect_filled(rect, CornerRadius::same(RADIUS), fill); - painter.rect_stroke( - rect, - CornerRadius::same(RADIUS), - Stroke::new(1.0, theme::rgb(theme.border)), - StrokeKind::Inside, - ); - let mut x = rect.left() + SPACE_MD; + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let mut button = egui_material3::MaterialButton::outlined(label) + .size(egui_material3::ButtonSize::ExtraSmall); if let Some(icon) = icon { - icons::paint( - painter, - Rect::from_center_size( - egui::pos2(x + icons::INLINE / 2.0, rect.center().y), - Vec2::splat(icons::INLINE), - ), - icon, - theme::rgb(theme.text), - ); - x += lead; + button = button.leading_icon(super::m3::symbol(icon).0); } - painter.galley( - egui::pos2(x, rect.center().y - galley.size().y / 2.0), - galley, - theme::rgb(theme.text), - ); - response.on_hover_cursor(egui::CursorIcon::PointingHand) + ui.add(button) + .on_hover_cursor(egui::CursorIcon::PointingHand) +} + +/// A text button (M3's lowest-emphasis button): a label, an optional +/// leading icon, no container until hovered. For the third action in a row +/// and actions inside dense rows. +pub fn text_button(ui: &mut Ui, icon: Option, label: &str) -> Response { + let mut button = egui_material3::MaterialButton::text(label); + if let Some(icon) = icon { + button = button.leading_icon(super::m3::symbol(icon).0); + } + ui.add(button) + .on_hover_cursor(egui::CursorIcon::PointingHand) +} + +/// An entry in a context menu or popup menu: M3's menu item, the menu's full +/// width, faint and unclickable when `enabled` is false. It does not close +/// the menu: the caller calls `ui.close()` when it acts. +pub fn menu_item(ui: &mut Ui, icon: Option, label: &str, enabled: bool) -> Response { + let mut item = egui_material3::MaterialMenuItem::new(label).enabled(enabled); + if let Some(icon) = icon { + item = item.leading_icon(super::m3::symbol(icon).0); + } + ui.add(item) +} + +/// A dropdown (M3's outlined select) choosing `current` from `options`, +/// each a value and its label, `width` wide. The response is marked +/// changed when the choice changed. `id` keeps two selects apart. A value +/// not among the options shows as none chosen. +pub fn select( + ui: &mut Ui, + id: impl egui::AsIdSalt, + current: &mut T, + options: &[(T, &str)], + width: f32, +) -> Response { + select_with_placeholder(ui, id, current, options, width, "") +} + +/// [`select`] that shows `placeholder` while `current` is none of the +/// options (a monitor not chosen yet), rather than the library's generic +/// "Select an option". +pub fn select_with_placeholder( + ui: &mut Ui, + id: impl egui::AsIdSalt, + current: &mut T, + options: &[(T, &str)], + width: f32, + placeholder: &str, +) -> Response { + let mut select = egui_material3::MaterialSelect::for_value(current) + .id_salt(id) + .width(width) + .options(options.iter().map(|(value, label)| (value.clone(), *label))); + if !placeholder.is_empty() { + select = select.placeholder(placeholder); + } + ui.add(select) } /// One cell of a [`segmented`] switch: its icon, its label and its @@ -547,82 +512,22 @@ pub fn segmented( active: usize, cell: f32, ) -> Option { - const HEIGHT: f32 = 30.0; - let count = segments.len().max(1) as f32; - let (track, _) = ui.allocate_exact_size(Vec2::new(cell * count, HEIGHT), Sense::hover()); - let painter = ui.painter(); - painter.rect_filled(track, CornerRadius::same(RADIUS), theme::rgb(theme.app)); - painter.rect_stroke( - track, - CornerRadius::same(RADIUS), - Stroke::new(1.0, theme::rgb(theme.border)), - StrokeKind::Inside, - ); - let font = TextStyle::Button.resolve(ui.style()); - let mut clicked = None; - for (index, (icon, label, tooltip)) in segments.iter().enumerate() { - let rect = Rect::from_min_size( - egui::pos2(track.left() + cell * index as f32, track.top()), - Vec2::new(cell, HEIGHT), - ) - .shrink(2.0); - let response = ui.interact(rect, egui::Id::unique((id, index)), Sense::click()); - let on = index == active; - let fill = if on { - theme::rgb(theme.accent) + let _ = theme; // Colours reach the widget through the M3 theme (D710). + let mut selected = active; + let mut group = egui_material3::SegmentedButton::single(&mut selected) + .id_salt(id) + .show_check(false); + for (icon, label, tooltip) in segments { + let fits = cell >= 96.0; + let segment = if fits { + egui_material3::Segment::new(*label).icon(super::m3::symbol(*icon).1) } else { - hover_fill(ui, response.id, response.hovered(), theme.app, theme.hover) + egui_material3::Segment::icon_only(super::m3::symbol(*icon).1, *label) }; - let ink = theme::rgb(if on { - theme.text_on_accent - } else { - theme.text_muted - }); - let painter = ui.painter(); - painter.rect_filled(rect, CornerRadius::same(RADIUS - 1), fill); - if response.has_focus() { - painter.rect_stroke( - rect, - CornerRadius::same(RADIUS - 1), - Stroke::new(1.5, theme::rgb(theme.accent_hover)), - StrokeKind::Inside, - ); - } - // Laid out each frame as every label is; egui caches the galley. - let galley = painter.layout_no_wrap((*label).to_owned(), font.clone(), ink); - let labelled = galley.size().x + icons::INLINE + SPACE_XS + SPACE_SM * 2.0 <= rect.width(); - let content = if labelled { - icons::INLINE + SPACE_XS + galley.size().x - } else { - icons::INLINE - }; - let x = rect.center().x - content / 2.0; - icons::paint( - painter, - Rect::from_center_size( - egui::pos2(x + icons::INLINE / 2.0, rect.center().y), - Vec2::splat(icons::INLINE), - ), - *icon, - ink, - ); - if labelled { - painter.galley( - egui::pos2( - x + icons::INLINE + SPACE_XS, - rect.center().y - galley.size().y / 2.0, - ), - galley, - ink, - ); - } - let response = - super::help::hovered(response, tooltip).on_hover_cursor(egui::CursorIcon::PointingHand); - if response.clicked() { - clicked = Some(index); - } + group = group.segment(segment.hover_text(*tooltip)); } - clicked + let response = group.show(ui); + (response.response.changed() && selected != active).then_some(selected) } /// A key, drawn as a key cap: outlined, in the monospace face, in `colour`. @@ -667,6 +572,17 @@ pub fn status_chip(ui: &mut Ui, icon: Icon, text: &str, color: Rgb) -> Response status_chip_over(ui, icon, text, color, None) } +/// The width [`status_chip`] takes for `text`, so a row can leave out a chip +/// that has no room rather than draw it under its neighbours. +#[must_use] +pub fn status_chip_width(ui: &Ui, text: &str) -> f32 { + let font = TextStyle::Small.resolve(ui.style()); + let galley = ui + .painter() + .layout_no_wrap(text.to_string(), font, egui::Color32::PLACEHOLDER); + galley.size().x + icons::DISCLOSURE + SPACE_XS + SPACE_SM * 2.0 +} + /// [`status_chip`] for a chip that sits over a picture: `plate` is the /// colour of an opaque-ish backing that keeps the words readable whatever /// the picture is doing. diff --git a/crates/xtask/src/credits.rs b/crates/xtask/src/credits.rs index c269cb22..df839b26 100644 --- a/crates/xtask/src/credits.rs +++ b/crates/xtask/src/credits.rs @@ -398,17 +398,27 @@ fn list(people: &[(String, &str)], packages: &[Package], angle: &str, spout: &st /// Whether `name` is a file a package keeps its licence or notices in. fn is_licence_file(name: &str) -> bool { + /// Files whose name may say "copyright" but whose content is a picture + /// or code (an icon set's `copyright.svg`), never a licence text. + const NOT_TEXT: [&str; 7] = [".svg", ".png", ".jpg", ".ttf", ".otf", ".rs", ".js"]; let lower = name.to_ascii_lowercase(); + if NOT_TEXT.iter().any(|ext| lower.ends_with(ext)) { + return false; + } ["licen", "copying", "notice", "copyright"] .iter() .any(|word| lower.contains(word)) || matches!(lower.as_str(), "ofl.txt" | "ufl.txt") } -/// A package's licence files, relative to its folder: at its top, one -/// folder down (a vendored C library keeps its own there), and every text +/// A package's licence files, relative to its folder: at its top, up to two +/// folders down (a vendored C library keeps its own one down, and bundled +/// fonts often sit in `resources/fonts/` or `assets/fonts/`, as +/// egui-material3's Roboto and Material Symbols do, D710), and every text /// file beside a bundled font (fonts carry their licences as `.txt`). fn licence_files(dir: &Path) -> Vec { + /// How many folders below the package's top are searched. + const DEPTH: usize = 2; const SKIP: [&str; 6] = ["target", "tests", "benches", "examples", ".git", "src"]; let mut found = Vec::new(); let mut folders = vec![(dir.to_path_buf(), 0)]; @@ -421,7 +431,7 @@ fn licence_files(dir: &Path) -> Vec { let path = entry.path(); let name = entry.file_name().to_string_lossy().into_owned(); if path.is_dir() { - if depth == 0 && !SKIP.contains(&name.as_str()) { + if depth < DEPTH && !SKIP.contains(&name.as_str()) { folders.push((path, depth + 1)); } } else { @@ -535,11 +545,43 @@ mod tests { ] { assert!(is_licence_file(name), "{name} is a licence file"); } - for name in ["README.md", "Cargo.toml", "lib.rs", "build.rs"] { + for name in [ + "README.md", + "Cargo.toml", + "lib.rs", + "build.rs", + "copyright.svg", + "license.rs", + ] { assert!(!is_licence_file(name), "{name} is not a licence file"); } } + #[test] + fn font_licences_two_folders_down_are_found() -> anyhow::Result<()> { + let dir = std::env::temp_dir().join(format!("strobe-credits-{}", std::process::id())); + let fonts = dir.join("resources").join("fonts"); + std::fs::create_dir_all(&fonts)?; + std::fs::create_dir_all(dir.join("src"))?; + for (path, text) in [ + (dir.join("LICENSE-MIT"), "mit"), + (fonts.join("Roboto-Regular.ttf"), "font"), + (fonts.join("OFL-Roboto.txt"), "ofl"), + (dir.join("src").join("LICENSE"), "not this one"), + ] { + std::fs::write(path, text)?; + } + let found = licence_files(&dir); + std::fs::remove_dir_all(&dir)?; + let roboto = Path::new("resources").join("fonts").join("OFL-Roboto.txt"); + assert_eq!( + found, + vec![PathBuf::from("LICENSE-MIT"), roboto], + "the top-level licence and the font's, not src/" + ); + Ok(()) + } + #[test] fn an_expression_names_its_licences() { assert_eq!( diff --git a/deny.toml b/deny.toml index 09178c65..c1707fd1 100644 --- a/deny.toml +++ b/deny.toml @@ -60,3 +60,6 @@ deny = [] [sources] unknown-registry = "deny" unknown-git = "deny" +# The Material 3 widgets (D710): the freeknet fork of egui-material3, pinned +# to a commit in the workspace Cargo.toml. +allow-git = ["https://github.com/freeknet/egui-material3"] diff --git a/docs/DECISIONS_BY_AREA.md b/docs/DECISIONS_BY_AREA.md index c01a6569..c92b4f27 100644 --- a/docs/DECISIONS_BY_AREA.md +++ b/docs/DECISIONS_BY_AREA.md @@ -501,7 +501,7 @@ crate" when it names none. The log itself, and how to add to it, is ## Not tied to one crate -234 decision(s). +235 decision(s). - [D1](decisions/D1.md): native OpenGL (glow + glutin), not wgpu - [D2](decisions/D2.md): ANGLE as the fallback context, not native-only @@ -737,3 +737,4 @@ crate" when it names none. The log itself, and how to add to it, is - [D572](decisions/D572.md): The Spout sender calls the 2.007 library's vtable, not mangled exports - [D574](decisions/D574.md): A second Spout sender carries a clean feed, before the post stage and never blacked out - [D701](decisions/D701.md): the owner's answers to Q20, Q30 and Q31: blackout stays as it is, imports may read a host `iTime`, and synthetic audio runs on one clock +- [D710](decisions/D710.md): The control window is drawn with Material 3 widgets from the freeknet egui-material3 fork, coloured by Strobe's own themes diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 6bc16f37..31248756 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -25,7 +25,7 @@ which backend proved a claim. | `strobe-bench` | Timings, frames, contact sheet; headless, window and auto contexts (D70-D72), now `strobe_gfx::offscreen` (D140) | llvmpipe; T480 ([BENCHMARKS.md](BENCHMARKS.md)) | | `strobe-forge` and the `scene-from-image` skill | One written pipeline for scenes made from a photo (D562): the skill's reading, archetypes, template, controls and critique; `check` with frames beside the reference, both dialects, 1080p timing, the From image gates and every control at its extremes; `make`, the same loop driven through the Anthropic API with compile repair and critique rounds. OpenAI and Google providers too (D600, canned bodies only). Open: real-key runs on each, and streaming (I-07) | LIGHTNING's RX 580, native and ANGLE D3D11: eight scenes built with the skill and checked with `check` (2026-11-07); `make` only against canned replies | | `strobe-app` | Control window (maximized) and output window on one context; the output starts hidden and the scene frame runs on its own schedule (D96); **Contextual Perform stage 1** (D130-D138): rail, custom title bar with health readouts, preview, transport (prev, next, blackout; hold shown as not wired), first-controls macros, and contextual panes for the scene browser (search, health filter, Preview apart from Load), inspector, diagnostics, import and settings, with saved layout, a focus-aware keyboard model and themes; `--diagnose`, adaptive resolution (D64), context-loss recovery with ANGLE fail-over (D66) | Xvfb (screenshots at 1280x720 and 1440x900 for every state, xdotool for keys); T480: smoke tests, recovery on real WGL (Task 8), hidden output, F11 and the close button (Task 9), the Perform UI at 150% scaling (Task 12) | -| `strobe-app` layout | **Synesthesia-style control window** (D281-D285), reworked from a screenshot review (docs/UI_REVIEW.md, D464-D484): an 84-point rail in words (Library, Controls, Import, Playlist, Editor, Mappings, Diagnostics, Settings; icons only below 1000 points, D473), with Controls a view of its own and no PLAY entry (D479); a persistent side panel at 31% of the window (preview, status strip, fav slots that look empty when they are, D478, and Playlist, Controls, Presets and Scene tabs); every pane on one form grammar (`ui::form`: pages, group cards, setting rows, toggle switches, outlined fields, Segoe UI, D465, D466), Settings as seven pages with search; control groups as ruled headers over one-row value bars (D510-D512, replacing D477's cards), a short dropdown's options side by side and a mapped control's source marked on its row (D563); the library header in one row (D480) with generated cover art (D474), and thumbnails read by their bytes and cropped to fill the card (D540); native file and folder pickers (D470); title bar readouts only when they need attention (D472); a help bar under the transport and BLACKOUT, which stay put. One click on a card makes it live (D291) | Headless shell tests (overflow, nothing over BLACKOUT, no text over text) on every state at ten sizes; screenshot-mode captures on TORNADO at 1600x1000 and 1280x720 for every step; the file pickers opened by the owner on Windows (2026-10-26); **not yet seen on the T480** (U-09 at 150%) | +| `strobe-app` layout | **Synesthesia-style control window** (D281-D285), reworked from a screenshot review (docs/UI_REVIEW.md, D464-D484): an 84-point rail in words (Library, Controls, Import, Playlist, Editor, Mappings, Diagnostics, Settings; icons only below 1000 points, D473), with Controls a view of its own and no PLAY entry (D479); a persistent side panel at 31% of the window (preview, status strip, fav slots that look empty when they are, D478, and Playlist, Controls, Presets and Scene tabs); every pane on one form grammar (`ui::form`: pages, group cards, setting rows, toggle switches, outlined fields, D465, D466; Material 3 widgets from the owner's `egui-material3` fork in the theme's colours and density, Roboto and Material Symbols since D710), Settings as seven pages with search; control groups as ruled headers over one-row value bars (D510-D512, replacing D477's cards), a short dropdown's options side by side and a mapped control's source marked on its row (D563); the library header in one row (D480) with generated cover art (D474), and thumbnails read by their bytes and cropped to fill the card (D540); native file and folder pickers (D470); title bar readouts only when they need attention (D472); a help bar under the transport and BLACKOUT, which stay put. One click on a card makes it live (D291) | Headless shell tests (overflow, nothing over BLACKOUT, no text over text) on every state at ten sizes; screenshot-mode captures on TORNADO at 1600x1000 and 1280x720 for every step; the file pickers opened by the owner on Windows (2026-10-26); **not yet seen on the T480** (U-09 at 150%) | | `strobe-audio` | Capture with retry and synthetic fallback, analysis, spectrum and level-trail textures, tap tempo (D20-D23, D61) | T480 live mic at 48 kHz | | `strobe-script` | QuickJS host: events, `update`, controls, `setUniform` compiled in at load, budget and faults (D62) | Xvfb; T480 (`11-script-orbits`) | | `strobe-diag` | Session logs, structured failures, panic reports, out-of-process minidumps, GL debug output (D40-D45) | Linux; T480 (`overflow` gives a `.dmp`, bug 2) | diff --git a/docs/UI_DESIGN.md b/docs/UI_DESIGN.md index ef238cfd..c8f3bcf5 100644 --- a/docs/UI_DESIGN.md +++ b/docs/UI_DESIGN.md @@ -2,7 +2,7 @@ _Last researched: 2026-10-08. Sections 2, 4, 5, 7, 12 and 22 were rewritten on 2026-10-14 for the Synesthesia-style layout (D281 to D285); sections 2, 4, 5, 7, 12, 24 and 25 were updated on 2026-10-15 for one-click scenes (D291). Sections 1, 4, 5, 7, 11, 12, 14, 16 and 24 were brought up to the app as built on 2026-10-26 (D465 to D484): the form grammar, a rail in words with Controls as a view and no PLAY, control groups as cards, approve-only remote pairing._ -**Where this document and the app disagree, the app and [UI_REVIEW.md](UI_REVIEW.md) win.** This is the design intent; UI_REVIEW is checked against screenshots, and its "Foundations" describe the component grammar every pane now uses (`ui::form`: a page, group cards, setting rows with a title and description on the left and the control on the right, toggle switches, outlined fields, D465 and D466). +**Where this document and the app disagree, the app and [UI_REVIEW.md](UI_REVIEW.md) win.** This is the design intent; UI_REVIEW is checked against screenshots, and its "Foundations" describe the component grammar every pane now uses (`ui::form`: a page, group cards, setting rows with a title and description on the left and the control on the right, toggle switches, outlined fields, D465 and D466). Since D710 those controls are Material 3 widgets from the `egui-material3` fork, coloured and sized by Strobe's theme. This is the UI contract for the Strobe desktop application. Synesthesia remains the compatibility reference for scene controls, presets, media, mapping and scripting. Since 2026-10-14 the owner's direction is also to follow its *layout* (three columns, a rail that switches the main view, one persistent right panel, a help bar), with Strobe's theme and every modern feature kept reachable. The target is a modern performance instrument for VJs and creative coders. diff --git a/docs/UI_REVIEW.md b/docs/UI_REVIEW.md index 07b74517..fd0fc54a 100644 --- a/docs/UI_REVIEW.md +++ b/docs/UI_REVIEW.md @@ -216,7 +216,7 @@ capture before and after, at 1600x1000 and at 1280x720. | Step | State | |---|---| -| Foundations | **Done (D465, D466).** Segoe UI regular and semibold from the system (D465); the type scale in `theme`; `ui::form` (page, group card, setting row, toggle switch, field, slider); field outlines in `border_strong`; `widgets::section` on the heading step; the banner's message laid out from the left. | +| Foundations | **Done (D465, D466).** Segoe UI regular and semibold from the system (D465; Roboto since D710); the type scale in `theme`; `ui::form` (page, group card, setting row, toggle switch, field, slider); field outlines in `border_strong`; `widgets::section` on the heading step; the banner's message laid out from the left. | | 1. Settings | **Done (D466).** Seven pages in a category list with search; every row in the form grammar; title-bar readouts open their page. Not yet: Browse buttons for the watched folder and the trust file, which come with `rfd` in step 3. | | 2. Map | **Done (D467).** Sources, Macros, Activity, OSC, MIDI, in that order; every mapping and macro a setting row with a state chip, its options in an inset card under it. Only seen in tests when open: screenshot mode cannot click, and screen capture reads the GL window as black. | | 3. Playlist and Import | **Done (D470).** Native file and folder pickers (`rfd`, off the frame loop) on every path field: playlist, Shadertoy export, watched folder, trust file. The owner used them on Windows on 2026-10-26 and they work. Import is a page; Playlist's empty state is a page, its loaded header carries the file commands, and Generate is a form. The selected-cue editor followed (D475). | @@ -225,6 +225,7 @@ capture before and after, at 1600x1000 and at 1280x720. | 6. Rail | **Done (D473).** Play, Library, Import, Playlist, Editor, Mappings, Diagnostics, Settings in an 84-point rail; 56 points of icons in a narrow window. | | 7. Library | **Done (D474).** The count as a sentence; generated cover art for scenes with no picture. | | 8. Leftovers | **Done (D476-D483).** Play shows one set of output buttons and macro cards share the strip (D476); control groups and the output controls are cards (D477); empty fav slots look empty (D478); Controls is a rail view and Play left the rail, at the owner's request (D479); the library header is one row with its filters in one group, and captions cut at a word (D480); recent playlists (D481); the Editor's status chip and one primary action (D482); Diagnostics as a page of cards with a fixed-height console (D483). | +| 10. Material 3 | **Done (D710), 2026-12-02.** Every standard control (buttons, icon, tool and transport buttons, segmented buttons, switches, text fields, selects in place of combo boxes, number fields in place of drag values, checkboxes, tabs, dialogs) comes from the owner's `egui-material3` fork, coloured by the theme's palette (`ui::m3::scheme`) and sized by the theme's density (Comfortable is M3 density -3, Compact -4). Roboto replaces Segoe UI and Material Symbols replace the stroked icons. The value bars, XY pads, meters, scene cards and preview stay Strobe's own. The editor's toolbar gives its name and chips only the room its actions leave. Captured at 1600x1000 on LIGHTNING; no text over text at every size in the shell tests. | | 9. Control density | **Done (D510-D512), 2026-10-28.** Researched dense parameter panels and mocked up three directions; the owner chose value bars. Every float control is one row (name and value inside, default notch, smoothing line, MACRO mark), 24/20 points in the side panel and 30/24 on the page; every other kind is a property row in the same frame (switch, swatch, list or readout at the right end), and a bang an outlined row-sized button in capitals; a drag is relative, a click types, a double click resets; groups are a ruled header instead of D477's cards. The segmented dropdown and the mark for MIDI and OSC mappings followed (D563, 2026-11-07); the macro cards are what is left of backlog U-11. | ## 5. Owner's answers (2026-10-23) diff --git a/docs/decisions/D710.md b/docs/decisions/D710.md new file mode 100644 index 00000000..7b7f3b06 --- /dev/null +++ b/docs/decisions/D710.md @@ -0,0 +1,74 @@ +# D710: The control window is drawn with Material 3 widgets from the freeknet egui-material3 fork, coloured by Strobe's own themes + +Date: 2026-12-02 +Status: Accepted +Areas: app, ui +Related: D5, D130, D291, D464, D470, D484, D491 + +## Context + +The control window was drawn by Strobe's own widget layer (`ui::widgets`, +`ui::form`, a stroked vector icon set) on top of raw egui. It was consistent +(D464-D484) but every control was ours to design, draw, animate and make +accessible, and egui's raw controls (combo boxes, drag values, checkboxes) +looked like egui wherever a pane reached past the shared layer. + +The owner maintains a Material Design 3 widget crate for egui 0.37, the +`freeknet` fork of `egui-material3`: token-driven widgets (colour roles, type +scale, shape, state layers, motion), AccessKit roles on every control, +keyboard focus and one-Tab-stop composites. A spike converted the shared layer +and showed two things to settle before a full conversion: regenerating each +theme from its accent's M3 tonal scheme turned Strobe's blue-black surfaces +neutral grey and made the themes look alike, and M3's default sizes (40 dp +buttons, 16 px field text) are larger than Strobe's 26 px controls. + +## Decision + +1. **Material 3 widgets for every standard control.** Buttons, icon buttons, + tool and transport buttons, segmented buttons, switches, text fields, + selects (in place of combo boxes), number fields (in place of drag + values), checkboxes, radios, sliders, tabs and dialogs come from + `egui-material3`. Strobe's shared helpers keep their signatures and wrap + the library, so panes call `widgets::button`, `widgets::select`, + `form::field` and so on as before. +2. **Strobe's themes drive the M3 colour roles** (`ui::m3::scheme`). Every + role a widget reads is mapped from the theme's palette (surfaces to the + surface containers, accent to primary, selection to secondary container, + danger to error). A theme keeps its look, the theme catalogue keeps its + meaning, and hand-painted surfaces agree with the library's widgets. Only + the fixed roles, shadow and scrim come from the accent's tonal scheme. +3. **Density is a theme setting in the library.** `MaterialTheme` carries a + density (Compose's VisualDensity, extended to the desktop steps -4 and -5) + and a type scale, and the widgets honour them unless a call overrides + them. Strobe maps Comfortable to density -3 and Compact to -4 (the steps + the panes had been passing by hand), with a type scale that puts M3's + 14 px labels at Strobe's body size (13.5 and 12.5 px), so no pane passes + sizes to a widget. +4. **Material Symbols replace the stroked icon set.** `ui::icon::paint` draws + the symbol `ui::m3::symbol` names for each `Icon`, so every icon changes in + one place. Roboto replaces Segoe UI as the interface face. +5. **The performance instruments stay ours.** The control-value bars, XY pads, + colour rows, meters, the scene grid's cards and the live preview have no M3 + equivalent that suits live use (M3's slider is a thumb on a track, not a + whole row that is the value). They keep their interaction and paint with + the palette and M3 shapes and state layers. +6. **The dependency is the fork on GitHub, pinned to a commit** in the + workspace `Cargo.toml`, and `deny.toml` allows that one git source. Work on + the fork lands on topic branches merged into `freeknet`; Strobe moves its + pin when it needs a change. + +## Consequences + +- The binary grows by about 2.1 MB: Roboto (three weights) and the outlined + Material Symbols are embedded. +- Layout tests treat icons as icons: rows made only of private-use glyphs are + not text to `no_text_is_drawn_over_other_text_at_any_size`. +- M3 buttons are wider than the painted ones were (16 to 24 dp of padding), + so a row that shares its width between text and actions measures first: + the editor's toolbar draws its actions, then gives the scene's name and + status chips what is left, leaving out a chip with no room. +- egui's own popups, tooltips, scroll areas and the code editor stay egui, + themed through Visuals from the same palette. +- A bug in the library is a bug in Strobe's control window, and the release + build aborts on a panic: the fork's tests run in its own CI, and the text + field's clamp panic found by the spike was fixed there first.