S019: settings pages redesign: navigation rail with sliding pill and search, cards of rows that stack when narrow, search through every row, colour section with live scheme preview and scheme swatches, limit and unavailable rows, shared chips/slider/stepper, selftest tap

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-11 23:21:48 -06:00
commit 7efd263b6e
14 changed files with 1466 additions and 653 deletions

View file

@ -69,6 +69,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| `nacre://gallery` + `SMOKE_SIZE=1400x2800 tools/smoke.sh tests/smoke/gallery.txt` | every design token and widget, dark and light (+ new tab and settings shots); read the PNGs | now (S015) |
| `SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt` | new tab page dark/light, nothing playing and a video playing, weather failed state, tall/narrow/phone widths (offline); `tests/smoke/newtab-weather.txt` shoots the real weather card (needs internet); read the PNGs | now (S017) |
| `SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt` | every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; `perf-*-a/b.json` `frames` (median/max draw ms, `drawn` count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest `pointer x y`, `customize`; `@PAGESDIR@` = path of tests/smoke/pages | now (S018) |
| `tools/smoke.sh tests/smoke/settings.txt` (+ `SMOKE_SIZE=1280x1100`) | every settings section and sub-page dark and light, search results (`nacre://settings/?search=…`), narrow width; `settings-write.txt` (hidden, `SMOKE_SIZE=1280x1100`, fresh outdir) taps controls with selftest `tap x y`, then check `home/.config/nacre-servo/Default/settings.json` (expected values in its header) | now (S019) |
| `python tools/icons.py` | rebuilds the icon font subset and `src/ui/icons.rs` from `tools/icons.txt` (needs fontTools and Arch's ttf-material-symbols-variable) | now (S015) |
| appimagetool, wine + Inno Setup, VM "Windows 10" | packaging and Windows checks | see the user's global CLAUDE.md "Building" |

View file

@ -13,12 +13,12 @@ Redo every settings section in the new system: navigation rail, large rounded ca
- `src/ui/pages/settings.rs` (whole)
## Steps
- [ ] Navigation rail/sidebar with section icons and the selected-pill indicator; search box
- [ ] Sections as cards of rows; consistent row anatomy (title, subtitle, control)
- [ ] Colour/theme section: seed source, palette swatches, custom colour, live preview using S015's scheme
- [ ] Partial and engine-limit settings keep their label/reason, styled consistently
- [ ] Every settings section screenshot light/dark; check by eye; check a sample of controls still writes settings (stores smoke script from S008)
- [ ] PROGRESS entry, INDEX line, commit `S019: …` and push
- [x] Navigation rail/sidebar with section icons and the selected-pill indicator; search box
- [x] Sections as cards of rows; consistent row anatomy (title, subtitle, control)
- [x] Colour/theme section: seed source, palette swatches, custom colour, live preview using S015's scheme
- [x] Partial and engine-limit settings keep their label/reason, styled consistently
- [x] Every settings section screenshot light/dark; check by eye; check a sample of controls still writes settings (stores smoke script from S008)
- [x] PROGRESS entry, INDEX line, commit `S019: …` and push
## End criteria
- Stores smoke scripts green.

View file

@ -29,6 +29,6 @@ Tracker: https://claude.ai/artifact/9AD7fPfwJ4ASFzVTJGKU4h
- [x] [S016 — Chrome and menus redesign](04%20UI%20redesign/S016-ui-chrome.md) · Opus medium
- [x] [S017 — New tab page: elements](04%20UI%20redesign/S017-ntp-elements.md) · Opus medium
- [x] [S018 — New tab page: backgrounds and Customize](04%20UI%20redesign/S018-ntp-backgrounds.md) · Opus medium
- [ ] [S019 — Settings pages redesign](04%20UI%20redesign/S019-ui-settings.md) · Opus medium
- [x] [S019 — Settings pages redesign](04%20UI%20redesign/S019-ui-settings.md) · Opus medium
- [ ] [S020 — Other pages and dialogs redesign](04%20UI%20redesign/S020-ui-pages.md) · Sonnet high
- [ ] [S021 — Phase 4 review with the user](04%20UI%20redesign/S021-phase4-review.md) · Sonnet medium · 🧑

View file

@ -207,7 +207,21 @@ Slow 1.8; stiffness ÷ factor²); `theme::animation_time` drives egui's own anim
- `card(ui, |ui| ...)`: `surface_container`, radius `L`; rows inside get hairlines between them (not above the first).
- `row(ui, title, description, |ui| control)`, `switch_row`, `link_row(ui, title, description) -> clicked` (whole
row is the button, chevron at the end), `section(ui, title)` (group title in `primary`, above a card).
- `text_field`, `number`, `page_column`, `glyph(toolbar key) -> icon`.
- `text_field`, `number` (stepper: − value +, fixed width so rows line up), `page_column`, `glyph(toolbar key) -> icon`.
- Rows (S019): `icon_row` / `icon_link_row` (leading icon), `wide_row` (control under the text, for chips and
lists), `limited_row` (partial engine support: a tertiary info line under the description), `unavailable_row`
(engine can't: reason + "Not available" label). A row remembers its control's width and moves the control under
the text when it doesn't fit beside 220 pt of text (`request_discard`, no flicker). `highlight_rows(ctx, query)`
tints and counts matching rows (settings search). `chip`, `choice_chips` (one of many), `toggle_chips` (any of),
`input_chip` (label + ×), `slider` (M3 Expressive, moved from Customize).
**Settings** (S019, `src/ui/pages/settings.rs`). Rail 264 pt (title, search pill, 48 pt entries, sliding
`secondary_container` pill); under 760 pt page width an 88 pt icon rail (56×32 pill, short label under) with the
search pill above the content. Content column 760 pt; header = Headline title, sub-pages get a back button and the
section name above. Search draws every section unseen (`UiBuilder::invisible`, own id salt) to count matching rows,
then shows only sections with matches, rows highlighted; `nacre://settings/?search=<words>` opens it. Appearance:
scheme preview (mini browser in the live roles + key colours), palette swatches built per preset with the current
mode/style/contrast (cached), custom colour = hex field + picker.
**Shapes** (`ui::paint`): `cookie(painter, center, radius, lobes, rotation, fill, stroke)`,
`cookie_image(painter, texture, center, radius, lobes, rotation)` (artwork in a cookie), `cookie_points`,

View file

@ -114,6 +114,22 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Not seen: place suggestions (network + typing; parse tested only), Upload dialog, slider drag, Escape; pointer
shots partly follow the user's real mouse in visible runs. Shortcut editing still lives in the old sub-page.
## S019 — Settings pages redesign (2026-11-12)
- Done: settings.rs rewritten: navigation rail with icons, sliding selected pill and search pill (icon rail under
760 pt); every section and sub-page as titled cards of rows; search covers every row (unseen pass), highlights
matches, empty state, `?search=` link. Appearance: live scheme preview, preset swatches as schemes, custom colour
picker + hex, style chips, contrast slider snapping to M3 levels. Limits: Freeze tabs, Save data, DNT = limited
rows; third-party cookies, Widevine = "Not available". New tab sub-page = Customize link + shortcut editor.
- Widgets (reusable): icon_row, icon_link_row, wide_row, limited_row, unavailable_row, highlight_rows, chip,
choice_chips, toggle_chips, input_chip, slider, stepper `number` (DESIGN.md "Widgets", "Settings"). Selftest `tap`.
- Shots: target/smoke/s019-v (visible, compact rail) and s019-w (hidden 1280×1100, wide rail): <section>-dark/light
for general appearance toolbar performance privacy adblock passwords downloads media about profiles search spell
keys import newtab permissions lists managers discord, search(-empty)-dark/light, narrow-dark/light.
- Verified: 51 unit tests (+stepper); settings.txt exit 0 visible and hidden; settings-write.txt (fresh home) wrote
startup Restore, privacy mode on, lock after 30, palette fallback #006A6A. S008's stores script doesn't exist yet.
- Not seen: page scrolled below the fold (no scroll command), hover/press in shots, colour picker popup, key capture;
backgrounds/chrome smoke not rerun after moving chip/slider out of customize.rs (same code, it compiles).
## Later
- Reader mode, split view, translate, real gamepad rumble (D-002: not planned for now).
- Packaging and first release (D-001: plan when the user asks).

View file

@ -19,6 +19,8 @@
//! js <script> run JavaScript in the current tab; the result goes to the log
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left)
//! pointer <x> <y> | off move the interface's pointer to x,y in the page area (new tab backgrounds follow it)
//! tap <x> <y> click the interface (not the web page) at x,y in the window (logical px, as in a
//! 1:1 screenshot): press, then release a frame later; for the chrome and Nacre's pages
//! customize [close] open (or close) the new tab page's Customize panel
//! log <text> write a line to the log
//! quit
@ -42,6 +44,8 @@ pub struct SelfTest {
dir: PathBuf,
/// A screenshot was asked for and hasn't been written yet.
pending_shot: bool,
/// `tap` pressed here; release once a frame has seen the press.
pending_release: Option<egui::Pos2>,
}
impl SelfTest {
@ -50,7 +54,7 @@ impl SelfTest {
let text = std::fs::read_to_string(&path).ok()?;
let dir = path.parent().map(|p| p.to_owned()).unwrap_or_else(|| PathBuf::from("."));
let lines = text.lines().map(|l| l.trim().to_owned()).filter(|l| !l.is_empty() && !l.starts_with('#')).collect();
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false })
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false, pending_release: None })
}
fn log(&self, text: &str) {
@ -73,6 +77,14 @@ impl App {
}
test.wait_until = None;
}
if let Some(pos) = test.pending_release.take() {
test.wait_until = Some(Instant::now() + Duration::from_millis(150));
if let Some(win) = self.windows.get_mut(&window) {
win.egui.egui_winit.egui_input_mut().events.push(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: false, modifiers: egui::Modifiers::NONE });
}
self.redraw(window);
continue;
}
if test.pending_shot {
// Written by the window after its next frame.
if let Some(shooting) = self.windows.iter().find(|(_, w)| w.shot_request.is_some()).map(|(id, _)| *id) {
@ -298,6 +310,20 @@ impl App {
}
self.redraw(window);
},
"tap" => {
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f32>().ok());
if let (Some(x), Some(y), Some(win)) = (parts.next(), parts.next(), self.windows.get_mut(&window)) {
let pos = egui::pos2(x, y);
let input = win.egui.egui_winit.egui_input_mut();
input.events.push(egui::Event::PointerMoved(pos));
input.events.push(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed: true, modifiers: egui::Modifiers::NONE });
if let Some(t) = self.selftest.as_mut() {
t.pending_release = Some(pos);
t.wait_until = Some(Instant::now() + Duration::from_millis(150));
}
}
self.redraw(window);
},
"log" => self.selftest_log(rest),
"quit" => self.quit(),
_ => self.selftest_log(&format!("unknown line: {line}")),

View file

@ -162,6 +162,15 @@ pub const WAVING_HAND: &str = "\u{e766}";
pub const GRAIN: &str = "\u{e3ea}";
pub const GIF_BOX: &str = "\u{e7a3}";
pub const BRIGHTNESS_6: &str = "\u{e3ab}";
pub const TOOLBAR: &str = "\u{e9f7}";
pub const KEYBOARD: &str = "\u{e312}";
pub const SPELLCHECK: &str = "\u{e8ce}";
pub const INPUT: &str = "\u{e890}";
pub const DASHBOARD_CUSTOMIZE: &str = "\u{e99b}";
pub const MEMORY: &str = "\u{e322}";
pub const COLORIZE: &str = "\u{e3b8}";
pub const FORMAT_COLOR_FILL: &str = "\u{e23a}";
pub const RESTART_ALT: &str = "\u{f053}";
/// Every icon with its name, for the gallery.
pub const ALL: &[(&str, &str)] = &[
@ -326,4 +335,13 @@ pub const ALL: &[(&str, &str)] = &[
("grain", GRAIN),
("gif_box", GIF_BOX),
("brightness_6", BRIGHTNESS_6),
("toolbar", TOOLBAR),
("keyboard", KEYBOARD),
("spellcheck", SPELLCHECK),
("input", INPUT),
("dashboard_customize", DASHBOARD_CUSTOMIZE),
("memory", MEMORY),
("colorize", COLORIZE),
("format_color_fill", FORMAT_COLOR_FILL),
("restart_alt", RESTART_ALT),
];

View file

@ -5,7 +5,7 @@ use egui::{Align2, Id, Rect, RichText, Sense, Stroke, StrokeKind, Ui, Vec2, pos2
use super::super::Frame;
use super::super::menus::one_line;
use super::super::widgets::{ButtonKind, button, focus_ring, icon, icon_button, interaction, segmented, switch};
use super::super::widgets::{ButtonKind, button, chip, focus_ring, icon, icon_button, interaction, segmented, slider, switch};
use crate::actions::Command;
use crate::store::settings::{Ntp, NtpBackground};
use crate::theme::{self, Weight};
@ -160,81 +160,6 @@ fn line<R>(ui: &mut Ui, glyph: &str, label: &str, control: impl FnOnce(&mut Ui)
.inner
}
/// A filter chip: icon and label in an outlined pill; the selected one is filled.
fn chip(ui: &mut Ui, glyph: &str, label: &str, selected: bool) -> egui::Response {
let p = theme::palette(ui.ctx());
let font = theme::font(theme::BODY, Weight::Medium);
let galley = ui.painter().layout_no_wrap(label.to_owned(), font, p.on_surface);
let size = vec2(theme::GAP_M + 18.0 + theme::GAP_S + galley.size().x + theme::GAP_L, theme::CONTROL_SMALL + 4.0);
let (rect, response) = ui.allocate_exact_size(size, Sense::click());
let s = interaction(ui, &response);
let on = theme::effect(ui.ctx(), response.id.with("on"), selected);
let radius = theme::radius(ui.ctx(), theme::S);
let container = theme::layer(p.surface_container_high, p.secondary_container, on);
let content = theme::layer(p.on_surface_variant, p.on_secondary_container, on);
ui.painter().rect_filled(rect, theme::corner_radius(radius), s.layer(container, content));
if on < 0.99 {
ui.painter().rect_stroke(rect, theme::corner_radius(radius), Stroke::new(1.0, p.outline_variant.gamma_multiply(1.0 - on)), StrokeKind::Inside);
}
icon(ui, pos2(rect.left() + theme::GAP_M + 9.0, rect.center().y), glyph, 18.0, on > 0.5, content);
ui.painter().galley(pos2(rect.left() + theme::GAP_M + 18.0 + theme::GAP_S, rect.center().y - galley.size().y / 2.0), galley, content);
if s.focus {
focus_ring(ui, rect, radius, &p);
}
response
}
/// An M3 Expressive slider: a thick track, the active part in the accent, a bar for a handle with a gap round
/// it. Drag or click to set; arrow keys step by a twentieth. Returns true when the value changed.
fn slider(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, width: f32, tooltip: &str) -> bool {
let p = theme::palette(ui.ctx());
let (rect, response) = ui.allocate_exact_size(vec2(width, theme::CONTROL), Sense::click_and_drag());
let (lo, hi) = (*range.start(), *range.end());
let mut fraction = ((*value - lo) / (hi - lo)).clamp(0.0, 1.0);
let before = fraction;
let track = rect.shrink2(vec2(2.0, 0.0));
if (response.dragged() || response.clicked())
&& let Some(at) = response.interact_pointer_pos()
{
fraction = ((at.x - track.left()) / track.width()).clamp(0.0, 1.0);
}
if response.has_focus() {
let step = ui.input(|i| i.key_pressed(egui::Key::ArrowRight) as i32 - i.key_pressed(egui::Key::ArrowLeft) as i32);
fraction = (fraction + step as f32 * 0.05).clamp(0.0, 1.0);
}
let changed = fraction != before;
if changed {
*value = lo + fraction * (hi - lo);
}
let s = interaction(ui, &response);
let enabled = s.enabled;
let dim = |c: egui::Color32, k: f32| if enabled { c } else { p.on_surface.gamma_multiply(k) };
let x = track.left() + fraction * track.width();
let thickness = 16.0;
let gap = 6.0;
let handle_width = 4.0 - 2.0 * s.press.clamp(0.0, 1.0);
let r = theme::corner_radius(thickness / 2.0);
let y = track.center().y;
let active = Rect::from_min_max(pos2(track.left(), y - thickness / 2.0), pos2((x - gap).max(track.left()), y + thickness / 2.0));
let rest = Rect::from_min_max(pos2((x + gap).min(track.right()), y - thickness / 2.0), pos2(track.right(), y + thickness / 2.0));
if active.width() > 0.5 {
ui.painter().rect_filled(active, r, dim(p.primary, theme::DISABLED_CONTENT));
}
if rest.width() > 0.5 {
ui.painter().rect_filled(rest, r, dim(p.secondary_container, theme::DISABLED_CONTAINER));
}
let handle = Rect::from_center_size(pos2(x, y), vec2(handle_width, 36.0));
if s.amount() > 0.0 {
ui.painter().rect_filled(handle.expand(4.0), theme::corner_radius(6.0), p.primary.gamma_multiply(s.amount()));
}
ui.painter().rect_filled(handle, theme::corner_radius(2.0), dim(p.primary, theme::DISABLED_CONTENT));
if s.focus {
focus_ring(ui, handle.expand(4.0), 6.0, &p);
}
response.on_hover_text(tooltip);
changed
}
fn background_section(ui: &mut Ui, ntp: &mut Ntp) {
heading(ui, "Background");
ui.horizontal_wrapped(|ui| {
@ -242,7 +167,7 @@ fn background_section(ui: &mut Ui, ntp: &mut Ntp) {
// The order of the video, None first (the enum's first variant is the default, Shapes).
let order = [NtpBackground::Off, NtpBackground::Shapes, NtpBackground::Blobs, NtpBackground::Particles, NtpBackground::Waves, NtpBackground::Dots];
for bg in order {
if chip(ui, background_icon(bg), bg.label(), ntp.bg == bg).clicked() {
if chip(ui, Some(background_icon(bg)), bg.label(), ntp.bg == bg).clicked() {
ntp.bg = bg;
}
}

File diff suppressed because it is too large Load diff

View file

@ -238,46 +238,164 @@ fn first_row_id(ui: &Ui) -> Id {
ui.id().with("first-row")
}
/// A setting: title and description on the left, the control on the right.
pub fn row<R>(ui: &mut Ui, title: &str, description: &str, control: impl FnOnce(&mut Ui) -> R) -> R {
row_frame(ui, title, description, None, control).0
/// Rows whose title or description contains this text (lower case) are highlighted and counted.
fn highlight_id() -> Id {
Id::new("row-highlight")
}
fn row_frame<R>(ui: &mut Ui, title: &str, description: &str, click: Option<Id>, control: impl FnOnce(&mut Ui) -> R) -> (R, Option<Response>) {
/// Highlight rows matching `query` from now on (empty: none). `highlighted` counts the matches since.
pub fn highlight_rows(ctx: &egui::Context, query: &str) {
ctx.data_mut(|d| {
d.insert_temp(highlight_id(), query.to_lowercase());
d.insert_temp(highlight_id().with("count"), 0usize);
});
}
pub fn highlighted(ctx: &egui::Context) -> usize {
ctx.data(|d| d.get_temp(highlight_id().with("count"))).unwrap_or(0)
}
/// What a row shows besides its control.
#[derive(Clone, Copy, Default)]
struct RowText<'a> {
title: &'a str,
description: &'a str,
/// Leading icon.
lead: Option<&'a str>,
/// What the engine can't do for this setting, under the description.
note: Option<&'a str>,
/// The control always goes under the text (chips and lists that wrap).
below: bool,
}
/// Text needs at least this much room beside a control; with less the control goes under the text.
const ROW_TEXT_MIN: f32 = 220.0;
/// A setting: title and description on the left, the control on the right.
pub fn row<R>(ui: &mut Ui, title: &str, description: &str, control: impl FnOnce(&mut Ui) -> R) -> R {
row_frame(ui, RowText { title, description, ..Default::default() }, None, control).0
}
/// A row with a leading icon.
pub fn icon_row<R>(ui: &mut Ui, glyph: &str, title: &str, description: &str, control: impl FnOnce(&mut Ui) -> R) -> R {
row_frame(ui, RowText { title, description, lead: Some(glyph), ..Default::default() }, None, control).0
}
/// A row whose control sits under the text, full width: wrapping chips, lists, wide fields.
pub fn wide_row<R>(ui: &mut Ui, title: &str, description: &str, control: impl FnOnce(&mut Ui) -> R) -> R {
row_frame(ui, RowText { title, description, below: true, ..Default::default() }, None, control).0
}
/// A setting the engine only partly supports: `limit` says what doesn't work, under the description.
pub fn limited_row<R>(ui: &mut Ui, title: &str, description: &str, limit: &str, control: impl FnOnce(&mut Ui) -> R) -> R {
row_frame(ui, RowText { title, description, note: Some(limit), ..Default::default() }, None, control).0
}
/// A setting the engine can't do at all: kept in its place with the reason and a "Not available" label.
pub fn unavailable_row(ui: &mut Ui, title: &str, reason: &str) {
let p = theme::palette(ui.ctx());
row_frame(ui, RowText { title, description: reason, ..Default::default() }, None, |ui| {
let font = theme::font(theme::SMALL, Weight::Medium);
let galley = ui.painter().layout_no_wrap("Not available".to_owned(), font, p.on_surface_variant);
let (rect, _) = ui.allocate_exact_size(vec2(theme::GAP_M + 16.0 + theme::GAP_XS + galley.size().x + theme::GAP_M, theme::CONTROL_SMALL - 4.0), Sense::hover());
let r = theme::corner_radius(theme::radius(ui.ctx(), theme::S));
ui.painter().rect_stroke(rect, r, Stroke::new(1.0, p.outline_variant), StrokeKind::Inside);
icon(ui, pos2(rect.left() + theme::GAP_M + 8.0, rect.center().y), icons::BLOCK, 16.0, false, p.on_surface_variant);
ui.painter().galley(pos2(rect.left() + theme::GAP_M + 16.0 + theme::GAP_XS, rect.center().y - galley.size().y / 2.0), galley, p.on_surface_variant);
});
}
fn row_frame<R>(ui: &mut Ui, text: RowText, click: Option<Id>, control: impl FnOnce(&mut Ui) -> R) -> (R, Option<Response>) {
let p = theme::palette(ui.ctx());
let first = ui.data_mut(|d| d.remove_temp::<bool>(first_row_id(ui))).unwrap_or(false);
let query: String = ui.data(|d| d.get_temp(highlight_id())).unwrap_or_default();
let matched = !query.is_empty() && (text.title.to_lowercase().contains(&query) || text.description.to_lowercase().contains(&query));
if matched {
ui.data_mut(|d| *d.get_temp_mut_or(highlight_id().with("count"), 0usize) += 1);
}
let background = ui.painter().add(Shape::Noop);
// The control's width from the last frame decides whether it fits beside the text.
let width_id = ui.id().with(("row-control", text.title));
let known: Option<Vec2> = ui.data(|d| d.get_temp(width_id));
let lead = if text.lead.is_some() { theme::ICON + theme::GAP_L } else { 0.0 };
let inner_width = ui.available_width() - 2.0 * theme::GAP_L - lead;
let control_width = known.map_or(260.0, |k| k.x);
let control_height = known.map_or(0.0, |k| k.y);
let stacked = text.below || control_width > inner_width - ROW_TEXT_MIN;
let mut result = None;
let mut measured = Vec2::ZERO;
// Runs in one of two places below.
let mut control = Some(control);
let lines = 20.0 + if text.description.is_empty() { 0.0 } else { 16.0 } + if text.note.is_some() { 16.0 } else { 0.0 };
let inner = egui::Frame::NONE.inner_margin(egui::Margin::symmetric(theme::GAP_L as i8, theme::GAP_M as i8)).show(ui, |ui| {
ui.set_min_height(theme::ROW - 2.0 * theme::GAP_M);
ui.set_min_width(ui.available_width());
ui.horizontal(|ui| {
if lead > 0.0 {
ui.add_space(lead - ui.spacing().item_spacing.x);
}
ui.vertical(|ui| {
ui.set_max_width((ui.available_width() - 260.0).max(200.0));
ui.add_space((theme::ROW - 2.0 * theme::GAP_M - if description.is_empty() { 20.0 } else { 36.0 }).max(0.0) / 2.0);
ui.label(RichText::new(title).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface));
if !description.is_empty() {
ui.label(RichText::new(description).font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
let width = if stacked { ui.available_width() } else { (ui.available_width() - control_width - theme::GAP_L).max(ROW_TEXT_MIN) };
ui.set_max_width(width);
if !stacked {
ui.add_space(((theme::ROW - 2.0 * theme::GAP_M).max(control_height) - lines).max(0.0) / 2.0);
}
ui.label(RichText::new(text.title).font(theme::font(theme::BODY, Weight::Regular)).color(p.on_surface));
if !text.description.is_empty() {
ui.label(RichText::new(text.description).font(theme::font(theme::SMALL, Weight::Regular)).color(p.on_surface_variant));
}
if let Some(note) = text.note {
let mut job = egui::text::LayoutJob::default();
let format = |color| egui::TextFormat { font_id: theme::font(theme::SMALL, Weight::Regular), color, ..Default::default() };
job.append(&format!("{} ", icons::INFO), 0.0, format(p.tertiary));
job.append(note, 0.0, format(p.on_surface_variant));
ui.label(job);
}
if stacked {
ui.add_space(theme::GAP_S);
result = control.take().map(|c| ui.horizontal_wrapped(|ui| c(ui)).inner);
}
});
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
result = Some(control(ui));
});
if !stacked {
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let right = ui.max_rect().right();
result = control.take().map(|c| c(ui));
measured = vec2(right - ui.min_rect().left(), ui.min_rect().height());
});
}
});
});
// Remember the control's natural width (measured beside the text); redo the frame unseen when the control
// turns out not to fit, so it moves under the text without a flicker.
if !stacked && known.is_none_or(|k| (k - measured).length() > 1.0) {
ui.data_mut(|d| d.insert_temp(width_id, measured));
if known.is_none() || measured.x > inner_width - ROW_TEXT_MIN {
ui.ctx().request_discard("row control moves under its text");
}
}
let rect = inner.response.rect;
if !first {
ui.painter().hline(rect.x_range().shrink(theme::GAP_L), rect.top(), Stroke::new(1.0, p.outline_variant));
}
if let Some(glyph) = text.lead {
let y = if stacked { rect.top() + theme::GAP_M + 10.0 } else { rect.center().y };
icon(ui, pos2(rect.left() + theme::GAP_L + theme::ICON / 2.0, y), glyph, theme::ICON, false, p.on_surface_variant);
}
let highlight = if matched { theme::layer(p.surface_container, p.secondary_container, 0.7) } else { Color32::TRANSPARENT };
let radius = theme::corner_radius(theme::radius(ui.ctx(), theme::M));
let response = click.map(|id| {
let response = ui.interact(rect, id, Sense::click());
let s = interaction(ui, &response);
let tint = p.on_surface.gamma_multiply(s.amount());
ui.painter().set(background, Shape::rect_filled(rect, theme::corner_radius(theme::radius(ui.ctx(), theme::XS)), tint));
let fill = if matched { s.layer(highlight, p.on_surface) } else { p.on_surface.gamma_multiply(s.amount()) };
ui.painter().set(background, Shape::rect_filled(rect.shrink2(vec2(theme::GAP_XS, 2.0)), radius, fill));
if s.focus {
focus_ring(ui, rect.shrink(2.0), theme::radius(ui.ctx(), theme::XS), &p);
focus_ring(ui, rect.shrink(2.0), theme::radius(ui.ctx(), theme::M), &p);
}
response
});
if response.is_none() && matched {
ui.painter().set(background, Shape::rect_filled(rect.shrink2(vec2(theme::GAP_XS, 2.0)), radius, highlight));
}
(result.expect("control ran"), response)
}
@ -288,9 +406,18 @@ pub fn switch_row(ui: &mut Ui, title: &str, description: &str, on: &mut bool) ->
/// A row that opens something: the whole row is the button, with a chevron at the end.
pub fn link_row(ui: &mut Ui, title: &str, description: &str) -> bool {
link(ui, RowText { title, description, ..Default::default() })
}
/// `link_row` with a leading icon.
pub fn icon_link_row(ui: &mut Ui, glyph: &str, title: &str, description: &str) -> bool {
link(ui, RowText { title, description, lead: Some(glyph), ..Default::default() })
}
fn link(ui: &mut Ui, text: RowText) -> bool {
let p = theme::palette(ui.ctx());
let id = ui.id().with("link-row").with(title);
let (_, response) = row_frame(ui, title, description, Some(id), |ui| {
let id = ui.id().with("link-row").with(text.title);
let (_, response) = row_frame(ui, text, Some(id), |ui| {
let (rect, _) = ui.allocate_exact_size(Vec2::splat(24.0), Sense::hover());
icon(ui, rect.center(), icons::CHEVRON_RIGHT, theme::ICON, false, p.on_surface_variant);
});
@ -353,9 +480,190 @@ pub fn text_field(ui: &mut Ui, text: &mut String, hint: &str, width: f32) -> Res
ui.add(egui::TextEdit::singleline(text).hint_text(hint).desired_width(width).margin(vec2(theme::GAP_M, theme::GAP_S)))
}
/// A number field limited to `range`. Returns true when it changed.
/// A number with − and + buttons either side; the number itself can be dragged or typed. Returns true when it
/// changed.
pub fn number(ui: &mut Ui, value: &mut u32, range: std::ops::RangeInclusive<u32>, suffix: &str) -> bool {
ui.add(egui::DragValue::new(value).range(range).suffix(suffix)).changed()
let before = *value;
let (lo, hi) = (*range.start(), *range.end());
// Steps that reach the far end in about 30 presses.
let step = match hi - lo {
0..=60 => 1,
61..=300 => 5,
301..=900 => 15,
_ => 30,
};
ui.scope(|ui| {
ui.spacing_mut().item_spacing.x = theme::GAP_XS;
// Laid out right to left inside rows, so the + comes first.
let rtl = ui.layout().prefer_right_to_left();
let plus = |ui: &mut Ui, value: &mut u32| {
if ui.add_enabled_ui(*value < hi, |ui| icon_button(ui, icons::ADD, "More")).inner.clicked() {
*value = (*value + step - *value % step).min(hi);
}
};
if rtl {
plus(ui, value);
} else {
minus(ui, value, lo, step);
}
// One width for every stepper, so the buttons line up from row to row.
ui.add_sized(vec2(112.0, theme::CONTROL_SMALL), egui::DragValue::new(value).range(range.clone()).suffix(suffix));
if rtl {
minus(ui, value, lo, step);
} else {
plus(ui, value);
}
});
*value != before
}
fn minus(ui: &mut Ui, value: &mut u32, lo: u32, step: u32) {
if ui.add_enabled_ui(*value > lo, |ui| icon_button(ui, icons::REMOVE, "Less")).inner.clicked() {
let down = if *value % step == 0 { step } else { *value % step };
*value = value.saturating_sub(down).max(lo);
}
}
/// A filter chip: icon (optional) and label in an outlined pill; the selected one is filled.
pub fn chip(ui: &mut Ui, glyph: Option<&str>, label: &str, selected: bool) -> Response {
let p = theme::palette(ui.ctx());
let font = theme::font(theme::BODY, Weight::Medium);
let galley = ui.painter().layout_no_wrap(label.to_owned(), font, p.on_surface);
let lead = if glyph.is_some() { 18.0 + theme::GAP_S } else { 0.0 };
let size = vec2(theme::GAP_M + lead + galley.size().x + if glyph.is_some() { theme::GAP_L } else { theme::GAP_M }, theme::CONTROL_SMALL + 4.0);
let (rect, response) = ui.allocate_exact_size(size, Sense::click());
if !ui.is_rect_visible(rect) {
return response;
}
let s = interaction(ui, &response);
let on = theme::effect(ui.ctx(), response.id.with("on"), selected);
let radius = theme::radius(ui.ctx(), theme::S);
let container = theme::layer(p.surface_container_high, p.secondary_container, on);
let content = theme::layer(p.on_surface_variant, p.on_secondary_container, on);
let content = disabled(content, s.enabled, theme::DISABLED_CONTENT);
ui.painter().rect_filled(rect, theme::corner_radius(radius), s.layer(container, content));
if on < 0.99 {
ui.painter().rect_stroke(rect, theme::corner_radius(radius), Stroke::new(1.0, p.outline_variant.gamma_multiply(1.0 - on)), StrokeKind::Inside);
}
if let Some(glyph) = glyph {
icon(ui, pos2(rect.left() + theme::GAP_M + 9.0, rect.center().y), glyph, 18.0, on > 0.5, content);
}
ui.painter().galley(pos2(rect.left() + theme::GAP_M + lead, rect.center().y - galley.size().y / 2.0), galley, content);
if s.focus {
focus_ring(ui, rect, radius, &p);
}
response
}
/// One of `options` as a wrapping row of chips, the chosen one with a check. For lists too long for a segmented
/// button. Returns true when it changed.
pub fn choice_chips<T: Clone + PartialEq>(ui: &mut Ui, value: &mut T, options: &[(T, &str)]) -> bool {
let mut changed = false;
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(theme::GAP_S, theme::GAP_S);
for (option, label) in options {
let selected = *value == *option;
if chip(ui, selected.then_some(icons::CHECK), label, selected).clicked() && !selected {
*value = option.clone();
changed = true;
}
}
});
changed
}
/// Any of `options` (keys in `chosen`) as toggling chips. Returns true when it changed.
pub fn toggle_chips(ui: &mut Ui, chosen: &mut Vec<String>, options: &[(&str, &str)]) -> bool {
let mut changed = false;
ui.horizontal_wrapped(|ui| {
ui.spacing_mut().item_spacing = vec2(theme::GAP_S, theme::GAP_S);
for (key, label) in options {
let on = chosen.iter().any(|k| k == key);
if chip(ui, on.then_some(icons::CHECK), label, on).clicked() {
if on {
chosen.retain(|k| k != key);
} else {
chosen.push((*key).to_owned());
}
changed = true;
}
}
});
changed
}
/// An input chip: a label with a × that removes it. Returns true when the × was clicked.
pub fn input_chip(ui: &mut Ui, label: &str, remove_tooltip: &str) -> bool {
let p = theme::palette(ui.ctx());
let font = theme::font(theme::BODY, Weight::Regular);
let galley = ui.painter().layout_no_wrap(label.to_owned(), font, p.on_surface_variant);
let size = vec2(theme::GAP_M + galley.size().x + theme::GAP_XS + 24.0 + theme::GAP_XS, theme::CONTROL_SMALL);
let (rect, _) = ui.allocate_exact_size(size, Sense::hover());
let radius = theme::corner_radius(theme::radius(ui.ctx(), theme::S));
ui.painter().rect_stroke(rect, radius, Stroke::new(1.0, p.outline_variant), StrokeKind::Inside);
ui.painter().galley(pos2(rect.left() + theme::GAP_M, rect.center().y - galley.size().y / 2.0), galley, p.on_surface_variant);
let x = Rect::from_center_size(pos2(rect.right() - theme::GAP_XS - 12.0, rect.center().y), Vec2::splat(24.0));
let response = ui.interact(x, ui.id().with(("input-chip", label)), Sense::click());
let s = interaction(ui, &response);
if s.amount() > 0.0 {
ui.painter().circle_filled(x.center(), 12.0, p.on_surface.gamma_multiply(s.amount()));
}
icon(ui, x.center(), icons::CLOSE, 16.0, false, p.on_surface_variant);
if s.focus {
focus_ring(ui, x, 12.0, &p);
}
response.on_hover_text(remove_tooltip).clicked()
}
/// An M3 Expressive slider: a thick track, the active part in the accent, a bar for a handle with a gap round
/// it. Drag or click to set; arrow keys step by a twentieth. Returns true when the value changed.
pub fn slider(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, width: f32, tooltip: &str) -> bool {
let p = theme::palette(ui.ctx());
let (rect, response) = ui.allocate_exact_size(vec2(width, theme::CONTROL), Sense::click_and_drag());
let (lo, hi) = (*range.start(), *range.end());
let mut fraction = ((*value - lo) / (hi - lo)).clamp(0.0, 1.0);
let before = fraction;
let track = rect.shrink2(vec2(2.0, 0.0));
if (response.dragged() || response.clicked())
&& let Some(at) = response.interact_pointer_pos()
{
fraction = ((at.x - track.left()) / track.width()).clamp(0.0, 1.0);
}
if response.has_focus() {
let step = ui.input(|i| i.key_pressed(egui::Key::ArrowRight) as i32 - i.key_pressed(egui::Key::ArrowLeft) as i32);
fraction = (fraction + step as f32 * 0.05).clamp(0.0, 1.0);
}
let changed = fraction != before;
if changed {
*value = lo + fraction * (hi - lo);
}
let s = interaction(ui, &response);
let enabled = s.enabled;
let dim = |c: Color32, k: f32| if enabled { c } else { p.on_surface.gamma_multiply(k) };
let x = track.left() + fraction * track.width();
let thickness = 16.0;
let gap = 6.0;
let handle_width = 4.0 - 2.0 * s.press.clamp(0.0, 1.0);
let r = theme::corner_radius(thickness / 2.0);
let y = track.center().y;
let active = Rect::from_min_max(pos2(track.left(), y - thickness / 2.0), pos2((x - gap).max(track.left()), y + thickness / 2.0));
let rest = Rect::from_min_max(pos2((x + gap).min(track.right()), y - thickness / 2.0), pos2(track.right(), y + thickness / 2.0));
if active.width() > 0.5 {
ui.painter().rect_filled(active, r, dim(p.primary, theme::DISABLED_CONTENT));
}
if rest.width() > 0.5 {
ui.painter().rect_filled(rest, r, dim(p.secondary_container, theme::DISABLED_CONTAINER));
}
let handle = Rect::from_center_size(pos2(x, y), vec2(handle_width, 36.0));
if s.amount() > 0.0 {
ui.painter().rect_filled(handle.expand(4.0), theme::corner_radius(6.0), p.primary.gamma_multiply(s.amount()));
}
ui.painter().rect_filled(handle, theme::corner_radius(2.0), dim(p.primary, theme::DISABLED_CONTENT));
if s.focus {
focus_ring(ui, handle.expand(4.0), 6.0, &p);
}
response.on_hover_text(tooltip);
changed
}
/// Icon for a toolbar button key.
@ -449,6 +757,32 @@ mod tests {
assert_eq!(value, 2);
}
/// The stepper's + moves to the next step (15 min steps to 30 in 0..=1440), − back down, and both stop at the range.
#[test]
fn number_steps_and_clamps() {
let ctx = egui::Context::default();
let mut value = 15;
let mut draw = |ui: &mut Ui| {
number(ui, &mut value, 0..=1440, " min");
};
let rect = frame(&ctx, 0.0, vec![], &mut draw);
let plus = egui::pos2(rect.right() - theme::CONTROL_SMALL / 2.0, rect.center().y);
let minus = egui::pos2(rect.left() + theme::CONTROL_SMALL / 2.0, rect.center().y);
let mut t = 0.0;
let mut click = |pos, draw: &mut dyn FnMut(&mut Ui)| {
for events in click_at(pos) {
t += 0.02;
frame(&ctx, t, events, draw);
}
};
click(plus, &mut draw);
click(minus, &mut draw);
click(minus, &mut draw);
click(minus, &mut draw);
drop(draw);
assert_eq!(value, 0, "15 → 30 → 0 → stays at 0");
}
/// Hover fades in with the effect spring and a press squeezes, both settling back once the pointer leaves.
#[test]
fn hover_and_press_animate_and_settle() {

View file

@ -0,0 +1,32 @@
# Settings controls still write settings (S019): taps a segmented button, a switch, a stepper, a palette swatch and
# the rail, then saves status. Needs the hidden 1280x1100 layout (tap positions): SMOKE_SIZE=1280x1100, no
# SMOKE_VISIBLE. Afterwards check home/.config/nacre*/settings.json: startup.mode "Restore", privacy.mode true,
# vault.autolock_min 30, theme.fallback "Palette" (source stays Website), theme.preset "#006A6A".
wait 3
resize 1280 1060
set /theme/mode "light"
page nacre://settings/general
wait 1
tap 958 264
wait 0.5
shot write-general
page nacre://settings/privacy
wait 1
tap 1110 592
wait 0.5
shot write-privacy
page nacre://settings/passwords
wait 1
tap 1120 606
wait 0.5
shot write-passwords
page nacre://settings/appearance
wait 1
tap 614 690
wait 1
shot write-appearance
tap 108 382
wait 1
shot write-rail
status done
quit

152
tests/smoke/settings.txt Normal file
View file

@ -0,0 +1,152 @@
# Settings pages (S019): every section and sub-page dark and light, search results, a narrow window. Offline.
# Run with SMOKE_SIZE=1280x1100 tools/smoke.sh tests/smoke/settings.txt; read the PNGs (only the top of long pages shows).
wait 3
resize 1280 1060
set /theme/mode "dark"
page nacre://settings/general
wait 0.6
shot general-dark
page nacre://settings/appearance
wait 0.6
shot appearance-dark
page nacre://settings/toolbar
wait 0.6
shot toolbar-dark
page nacre://settings/performance
wait 0.6
shot performance-dark
page nacre://settings/privacy
wait 0.6
shot privacy-dark
page nacre://settings/adblock
wait 0.6
shot adblock-dark
page nacre://settings/passwords
wait 0.6
shot passwords-dark
page nacre://settings/downloads
wait 0.6
shot downloads-dark
page nacre://settings/media
wait 0.6
shot media-dark
page nacre://settings/about
wait 0.6
shot about-dark
page nacre://settings/profiles
wait 0.6
shot profiles-dark
page nacre://settings/search
wait 0.6
shot search-dark
page nacre://settings/spell
wait 0.6
shot spell-dark
page nacre://settings/keys
wait 0.6
shot keys-dark
page nacre://settings/import
wait 0.6
shot import-dark
page nacre://settings/newtab
wait 0.6
shot newtab-dark
page nacre://settings/permissions
wait 0.6
shot permissions-dark
page nacre://settings/lists
wait 0.6
shot lists-dark
page nacre://settings/managers
wait 0.6
shot managers-dark
page nacre://settings/discord
wait 0.6
shot discord-dark
page nacre://settings/?search=cookie
wait 0.8
shot search-dark
page nacre://settings/?search=zzzz
wait 0.6
shot search-empty-dark
page nacre://settings/?search=
wait 0.3
set /theme/mode "light"
page nacre://settings/general
wait 0.6
shot general-light
page nacre://settings/appearance
wait 0.6
shot appearance-light
page nacre://settings/toolbar
wait 0.6
shot toolbar-light
page nacre://settings/performance
wait 0.6
shot performance-light
page nacre://settings/privacy
wait 0.6
shot privacy-light
page nacre://settings/adblock
wait 0.6
shot adblock-light
page nacre://settings/passwords
wait 0.6
shot passwords-light
page nacre://settings/downloads
wait 0.6
shot downloads-light
page nacre://settings/media
wait 0.6
shot media-light
page nacre://settings/about
wait 0.6
shot about-light
page nacre://settings/profiles
wait 0.6
shot profiles-light
page nacre://settings/search
wait 0.6
shot search-light
page nacre://settings/spell
wait 0.6
shot spell-light
page nacre://settings/keys
wait 0.6
shot keys-light
page nacre://settings/import
wait 0.6
shot import-light
page nacre://settings/newtab
wait 0.6
shot newtab-light
page nacre://settings/permissions
wait 0.6
shot permissions-light
page nacre://settings/lists
wait 0.6
shot lists-light
page nacre://settings/managers
wait 0.6
shot managers-light
page nacre://settings/discord
wait 0.6
shot discord-light
page nacre://settings/?search=cookie
wait 0.8
shot search-light
page nacre://settings/?search=zzzz
wait 0.6
shot search-empty-light
page nacre://settings/?search=
wait 0.3
resize 700 900
page nacre://settings/appearance
wait 1
shot narrow-light
set /theme/mode "dark"
page nacre://settings/privacy
wait 1
shot narrow-dark
status done
quit

View file

@ -170,3 +170,12 @@ waving_hand
grain
gif_box
brightness_6
toolbar
keyboard
spellcheck
input
dashboard_customize
memory
colorize
format_color_fill
restart_alt