S016: R1-21 controls hold still under the pointer

segmented keys its animation state on its widget id instead of its screen
position (the recording showed wrong checks while scrolling); Interface size
uses a new settled_slider that shows a value label while dragged and sets the
value on release; filter_chip keeps one width; zoom resets at 100 %.
Selftest press/drag/release and scroll; smoke scripts sliders(-visible).txt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
astar76 2026-11-12 07:41:24 -06:00
commit 8049f6aa33
10 changed files with 273 additions and 24 deletions

View file

@ -70,6 +70,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| `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) |
| `SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt` | controls hold still (R1-21): Interface size drag (value label while held, applied on release), Contrast live, Style chip pick; `SMOKE_VISIBLE=1 tools/smoke.sh tests/smoke/sliders-visible.txt` the same plus scrolling for the user's window (~772 px). Selftest `press`/`drag`/`release`, `scroll x y dy`; read the PNGs | now (R1-21) |
| `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

@ -204,6 +204,7 @@ Slow 1.8; stiffness ÷ factor²); `theme::animation_time` drives egui's own anim
selected = `secondary_container` fill and filled icon.
- `switch(ui, &mut bool) -> changed`: M3 switch, handle travels (FAST) and grows with a check when on, hover halo.
- `segmented(ui, &mut T, &[(T, label)]) -> changed`: equal-width segments, selected = tonal fill + check that slides in.
Animation state is keyed on the widget's id, never its position (a position key breaks while the page scrolls).
- `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).
@ -214,6 +215,11 @@ Slow 1.8; stiffness ÷ factor²); `theme::animation_time` drives egui's own anim
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).
- Still under the pointer (R1-21): a control never changes the layout around itself while it is used.
`filter_chip(ui, label, on)` (used by `choice_chips` / `toggle_chips` and on/off chips) keeps one width, the check
slides in over reserved space. `slider` sets its value live, for settings that only repaint (contrast, dim,
blur); `settled_slider(…, &|v| label)` is for settings that re-lay out the page (interface size): while dragged
only the handle and an M3 value label move, the value is set on release (a click or arrow key sets it at once).
**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

View file

@ -194,8 +194,22 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Later: the original's history, bookmarks and passwords toolbar flyouts (search pill, timed rows); today those
buttons open the pages.
## S016 follow-up — R1-21 controls hold still under the pointer (2026-11-12)
- Recording: Appearance page while scrolling; segmented buttons showed other controls' checks. Cause: `segmented`
keyed its animation state on its screen position. Now on its own widget id (DESIGN.md "Widgets").
- Interface size: new `settled_slider` (value label while dragged, set on release; click and arrows at once), so the
page no longer rescales under the pointer. Contrast, dim, blur stay live (repaint only). Going back to 100 % now
resets the zoom (`style_window` skipped 1.0).
- `filter_chip` keeps one width (check slides into reserved space): Style chips, toggle chips, import chips, the
permission prompt's Remember and find's Match case no longer push their neighbours.
- Selftest `press` / `drag` / `release`, `scroll x y dy`. Tests: settled slider, filter chip width (58 green).
- Verified: `SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt` and `SMOKE_VISIBLE=1 … sliders-visible.txt`
shots (held: label, page 100 %; released: 125 %; scroll: right checks). Not proven: the recording's tearing-like
frames (looks like capture tearing, not reproduced); no regression test for the segmented id.
## Later
- System accent: watch caelestia scheme.json / the portal `accent-color` and restyle live (R1-11).
- 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).
- Shortcut icons: a favicon cache by host (today only open tabs' favicons show); a `scroll` selftest command.
- Shortcut icons: a favicon cache by host (today only open tabs' favicons show).
- Interface size above ~110 % on a narrow (772 px) window clips wide segmented rows at the right (R1-21 visible run).

View file

@ -1364,9 +1364,8 @@ impl App {
let palette = theme::Palette::new(theme::seed(&settings, site, self.shared.system_accent), dark, &settings.theme.variant, settings.theme.contrast);
let ctx = &win.egui.egui_ctx;
theme::apply(ctx, &palette, &settings);
if (settings.ui.scale - 1.0).abs() > 0.01 {
ctx.set_zoom_factor(settings.ui.scale.clamp(0.5, 3.0));
}
// Always, so going back to 100 % takes effect too.
ctx.set_zoom_factor(settings.ui.scale.clamp(0.5, 3.0));
win.ui.palette = Some(palette);
win.ui.site_colour = site;
}

View file

@ -25,6 +25,10 @@
//! key <name> press and release a key in the interface: enter, escape, tab, space or a letter
//! 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
//! press <x> <y> hold the interface's button down at x,y (as `tap`), for a drag
//! drag <x> <y> move the held pointer to x,y
//! release let the button go where the pointer is
//! scroll <x> <y> <dy> turn the wheel over x,y in the window by dy points (positive scrolls down)
//! welcome <step> show step 0..5 of the welcome page
//! customize [close] open (or close) the new tab page's Customize panel
//! log <text> write a line to the log
@ -51,6 +55,8 @@ pub struct SelfTest {
pending_shot: bool,
/// `tap` pressed here; release once a frame has seen the press.
pending_release: Option<egui::Pos2>,
/// `press` holds the button down; `drag` moves it, `release` lets it go here.
held: Option<egui::Pos2>,
}
impl SelfTest {
@ -59,7 +65,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, pending_release: None })
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false, pending_release: None, held: None })
}
fn log(&self, text: &str) {
@ -351,6 +357,37 @@ impl App {
}
self.redraw(window);
},
"press" | "drag" => {
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));
if verb == "press" {
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.held = Some(pos);
}
}
self.redraw(window);
},
"scroll" => {
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f32>().ok());
if let (Some(x), Some(y), Some(dy), Some(win)) = (parts.next(), parts.next(), parts.next(), self.windows.get_mut(&window)) {
let input = win.egui.egui_winit.egui_input_mut();
input.events.push(egui::Event::PointerMoved(egui::pos2(x, y)));
// egui's delta moves the content, so scrolling down is negative.
input.events.push(egui::Event::MouseWheel { unit: egui::MouseWheelUnit::Point, delta: egui::vec2(0.0, -dy), phase: egui::TouchPhase::Move, source: egui::MouseWheelSource::Wheel, modifiers: egui::Modifiers::NONE });
}
self.redraw(window);
},
"release" => {
if let (Some(pos), Some(win)) = (self.selftest.as_mut().and_then(|t| t.held.take()), 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);
},
"fakeload" => {
// Hold the active tab in the middle of a load (local pages load too fast to catch), or end it.
if let Some(tab) = self.windows.get_mut(&window).and_then(|w| w.tabs.get_mut(w.active)) {

View file

@ -4,7 +4,7 @@
use egui::{Align2, Id, Rect, RichText, Sense, Ui, Vec2, pos2, vec2};
use super::menus::{menu_item, surface};
use super::widgets::{ButtonKind, button, chip, icon, icon_button, password_field, text_field};
use super::widgets::{ButtonKind, button, filter_chip, icon, icon_button, password_field, text_field};
use super::{Frame, paint};
use crate::actions::{Command, DialogResult, PromptAnswer};
use crate::tabs::{Dialog, Prompt};
@ -118,7 +118,7 @@ pub fn prompt_bars(root: &mut Ui, f: &mut Frame) {
if button(&mut buttons, ButtonKind::Tonal, None, "Block").clicked() {
answer = Some(PromptAnswer::Deny { remember });
}
if chip(&mut buttons, if remember { Some(icons::CHECK) } else { None }, "Remember", remember).clicked() {
if filter_chip(&mut buttons, "Remember", remember).clicked() {
remember = !remember;
}
buttons.data_mut(|d| d.insert_temp(remember_id, remember));
@ -198,7 +198,7 @@ pub fn find_bar(root: &mut Ui, f: &mut Frame) {
if icon_button(ui, icons::ARROW_DOWNWARD, "Next (Enter)").clicked() {
f.send(Command::Find { text: find.text.clone(), forward: true, case: find.case_sensitive });
}
if chip(ui, if find.case_sensitive { Some(icons::CHECK) } else { None }, "Match case", find.case_sensitive).clicked() {
if filter_chip(ui, "Match case", find.case_sensitive).clicked() {
find.case_sensitive = !find.case_sensitive;
f.send(Command::Find { text: find.text.clone(), forward: true, case: find.case_sensitive });
}

View file

@ -8,8 +8,8 @@ use egui::{Align2, Color32, Id, Rect, RichText, Sense, Shape, Stroke, StrokeKind
use super::super::Frame;
use super::super::widgets::{
ButtonKind, button, card, choice_chips, chip, focus_ring, highlight_rows, highlighted, icon, icon_button, icon_link_row, icon_row, icon_toggle, input_chip, interaction,
limited_row, number, row, section, segmented, slider, switch, switch_row, text_field, toggle_chips, unavailable_row, wide_row,
ButtonKind, button, card, choice_chips, filter_chip, focus_ring, highlight_rows, highlighted, icon, icon_button, icon_link_row, icon_row, icon_toggle, input_chip, interaction,
limited_row, number, row, section, segmented, settled_slider, slider, switch, switch_row, text_field, toggle_chips, unavailable_row, wide_row,
};
use crate::actions::Command;
use crate::keys::{Action, Shortcut};
@ -483,7 +483,7 @@ fn appearance(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
row(ui, "Roundness", "Corners of cards, buttons and fields", |ui| segmented(ui, &mut s.ui.roundness, Roundness::ALL));
row(ui, "Interface size", &format!("{:.0} %", s.ui.scale * 100.0), |ui| {
let mut v = s.ui.scale;
if slider(ui, &mut v, 0.75..=1.75, 200.0, "Interface size") {
if settled_slider(ui, &mut v, 0.75..=1.75, 200.0, &|v| format!("{:.0} %", (v * 20.0).round() * 5.0)) {
s.ui.scale = (v * 20.0).round() / 20.0;
}
});
@ -1220,7 +1220,7 @@ fn import(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
let done = s.startup.import_done.contains(&src.name());
wide_row(ui, &src.name(), if done { "Imported before" } else { "" }, |ui| {
for (on, label) in [(&mut b, "Bookmarks"), (&mut h, "History"), (&mut st, "Home page and search engine")] {
if chip(ui, on.then_some(icons::CHECK), label, *on).clicked() {
if filter_chip(ui, label, *on).clicked() {
*on = !*on;
}
}

View file

@ -135,8 +135,10 @@ pub fn segmented<T: Copy + PartialEq>(ui: &mut Ui, value: &mut T, options: &[(T,
let widest = options.iter().map(|(_, label)| ui.painter().layout_no_wrap((*label).to_owned(), font.clone(), p.on_surface).size().x).fold(0.0, f32::max);
let segment = vec2((widest + check + 2.0 * theme::GAP_M).max(64.0), theme::CONTROL);
let total = vec2(segment.x * options.len() as f32, segment.y);
let (rect, _) = ui.allocate_exact_size(total, Sense::hover());
let id = ui.id().with("segmented").with(rect.min.x as i32).with(rect.min.y as i32);
// Keyed on the widget's own id, not its place: a position key changes while the page scrolls, so the segments
// would pick up another control's animation state.
let (rect, response) = ui.allocate_exact_size(total, Sense::hover());
let id = response.id;
let mut changed = false;
let last = options.len().saturating_sub(1);
for (i, (option, label)) in options.iter().enumerate() {
@ -555,6 +557,40 @@ pub fn chip(ui: &mut Ui, glyph: Option<&str>, label: &str, selected: bool) -> Re
response
}
/// A chip that is on or off: on, it is filled and a check slides in before the label. It keeps one width either
/// way, so picking it doesn't move the chips after it (or wrap them onto another line).
pub fn filter_chip(ui: &mut Ui, 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 = 18.0 + theme::GAP_S;
let size = vec2(theme::GAP_M + lead + galley.size().x + theme::GAP_L, 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);
}
// Off, the label sits in the middle; the check pushes it to its place at the end.
let x = rect.center().x - (galley.size().x + lead * on) / 2.0;
if on > 0.01 {
icon(ui, pos2(x + 9.0 * on, rect.center().y), icons::CHECK, 18.0 * on, false, content);
}
ui.painter().galley(pos2(x + lead * on, 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 {
@ -563,7 +599,7 @@ pub fn choice_chips<T: Clone + PartialEq>(ui: &mut Ui, value: &mut T, options: &
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 {
if filter_chip(ui, label, selected).clicked() && !selected {
*value = option.clone();
changed = true;
}
@ -579,7 +615,7 @@ pub fn toggle_chips(ui: &mut Ui, chosen: &mut Vec<String>, options: &[(&str, &st
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 filter_chip(ui, label, on).clicked() {
if on {
chosen.retain(|k| k != key);
} else {
@ -616,24 +652,58 @@ pub fn input_chip(ui: &mut Ui, label: &str, remove_tooltip: &str) -> bool {
}
/// 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.
/// it. Drag or click to set; arrow keys step by a twentieth. Sets the value live, for settings that only repaint
/// (colours, dim, blur). 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 {
track(ui, value, range, width, &|_| tooltip.to_owned(), false)
}
/// A slider for settings that re-lay out the page (interface size): while dragging, only the handle and a value
/// label above it move, and the value is set on release, so the page doesn't move under the pointer. A click or
/// an arrow key sets it at once. `label` formats a value for the label and the tooltip.
pub fn settled_slider(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, width: f32, label: &dyn Fn(f32) -> String) -> bool {
track(ui, value, range, width, label, true)
}
/// Where a settled slider stands: `pending` is the dragged fraction (kept while `dragging`). Returns the fraction
/// to draw, what to keep as pending, and whether to set the value now.
fn settle(committed: f32, pending: Option<f32>, pointer: Option<f32>, dragging: bool) -> (f32, Option<f32>, bool) {
let fraction = pointer.or(pending).unwrap_or(committed);
if dragging { (fraction, Some(fraction), false) } else { (fraction, None, fraction != committed) }
}
fn track(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, width: f32, label: &dyn Fn(f32) -> String, settled: bool) -> 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 committed = ((*value - lo) / (hi - lo)).clamp(0.0, 1.0);
let track = rect.shrink2(vec2(2.0, 0.0));
let mut pointer = None;
if (response.dragged() || response.clicked())
&& let Some(at) = response.interact_pointer_pos()
{
fraction = ((at.x - track.left()) / track.width()).clamp(0.0, 1.0);
pointer = Some(((at.x - track.left()) / track.width()).clamp(0.0, 1.0));
}
if response.has_focus() {
let pending_id = response.id.with("pending");
let (mut fraction, pending, mut changed) = if settled {
// Only while this drag lasts: a value left from a drag the slider wasn't drawn for to the end is dropped.
let pending = if response.dragged() || response.drag_stopped() { ui.data(|d| d.get_temp::<f32>(pending_id)) } else { None };
settle(committed, pending, pointer, response.dragged())
} else {
let fraction = pointer.unwrap_or(committed);
(fraction, None, fraction != committed)
};
ui.data_mut(|d| match pending {
Some(f) => drop(d.insert_temp(pending_id, f)),
None => drop(d.remove_temp::<f32>(pending_id)),
});
if response.has_focus() && pending.is_none() {
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);
if step != 0 {
fraction = (fraction + step as f32 * 0.05).clamp(0.0, 1.0);
changed = fraction != committed;
}
}
let changed = fraction != before;
if changed {
*value = lo + fraction * (hi - lo);
}
@ -662,7 +732,17 @@ pub fn slider(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>
if s.focus {
focus_ring(ui, handle.expand(4.0), 6.0, &p);
}
response.on_hover_text(tooltip);
let shown = lo + fraction * (hi - lo);
if pending.is_some() {
// The M3 value label: a pill above the handle, over everything so the row doesn't clip it.
let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Tooltip, response.id));
let galley = painter.layout_no_wrap(label(shown), theme::font(theme::SMALL, Weight::Medium), p.inverse_on_surface);
let pill = Rect::from_center_size(pos2(x, handle.top() - theme::GAP_XS - 14.0), vec2(galley.size().x + 2.0 * theme::GAP_M, 28.0));
painter.rect_filled(pill, CornerRadius::same(14), p.inverse_surface);
painter.galley(pill.center() - galley.size() / 2.0, galley, p.inverse_on_surface);
} else {
response.on_hover_text(label(shown));
}
changed
}
@ -783,6 +863,49 @@ mod tests {
assert_eq!(value, 0, "15 → 30 → 0 → stays at 0");
}
/// A settled slider keeps the value while it is dragged and sets it on release; a live one follows the pointer.
#[test]
fn settled_slider_sets_on_release() {
assert_eq!(settle(0.2, None, Some(0.6), true), (0.6, Some(0.6), false), "dragging previews only");
assert_eq!(settle(0.2, Some(0.6), None, true), (0.6, Some(0.6), false), "the pending value stays while held");
assert_eq!(settle(0.2, Some(0.6), None, false), (0.6, None, true), "release sets it");
assert_eq!(settle(0.2, None, Some(0.9), false), (0.9, None, true), "a click sets it at once");
assert_eq!(settle(0.2, None, None, false), (0.2, None, false), "nothing happens");
let ctx = egui::Context::default();
let mut value = 1.0;
let mut seen = Vec::new();
let mut draw = |ui: &mut Ui| {
settled_slider(ui, &mut value, 0.0..=2.0, 200.0, &|v| format!("{v:.2}"));
seen.push(value);
};
let rect = frame(&ctx, 0.0, vec![], &mut draw);
let at = |f: f32| egui::pos2(rect.left() + 2.0 + f * (rect.width() - 4.0), rect.center().y);
let button = |pos, pressed| Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE };
let steps = [vec![Event::PointerMoved(at(0.5))], vec![button(at(0.5), true)], vec![Event::PointerMoved(at(0.6))], vec![Event::PointerMoved(at(0.75))], vec![]];
for (i, events) in steps.into_iter().enumerate() {
frame(&ctx, 0.02 * (i + 1) as f64, events, &mut draw);
}
frame(&ctx, 0.2, vec![button(at(0.75), false)], &mut draw);
frame(&ctx, 0.22, vec![], &mut draw);
drop(draw);
let held = &seen[..seen.len() - 2];
assert!(held.iter().all(|v| *v == 1.0), "unchanged while dragging: {seen:?}");
assert!((value - 1.5).abs() < 0.02, "set on release, got {value}");
}
/// Picking a filter chip doesn't change its width, so the chips after it stay put.
#[test]
fn filter_chip_keeps_its_width() {
let ctx = egui::Context::default();
let width = |selected| {
let mut w = 0.0;
frame(&ctx, 0.0, vec![], &mut |ui: &mut Ui| w = filter_chip(ui, "Vibrant", selected).rect.width());
w
};
assert_eq!(width(false), width(true));
}
/// 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 @@
# sliders.txt for the visible window (SMOKE_VISIBLE=1, about 772x815 on DP-1): scrolls Appearance down, drags the
# Interface size slider to 125 % (drag-held: value label, page still 100 %; released: page at 125 %), then scrolls
# back and forth (scroll-a/b: every segmented button keeps its own check while the page moves). Positions are for
# that window size; re-shoot `before` and adjust them if the window differs.
wait 3
set /theme/mode "light"
page nacre://settings/appearance
wait 1.5
scroll 400 500 700
wait 1.5
shot before
press 582 765
wait 0.3
drag 600 765
wait 0.3
drag 632 765
wait 0.8
shot drag-held
release
wait 1.5
shot released
set /ui/scale 1.0
wait 1
scroll 400 500 -300
wait 0.05
shot scroll-a
scroll 400 500 -300
wait 0.05
shot scroll-b
wait 1
status done
quit

37
tests/smoke/sliders.txt Normal file
View file

@ -0,0 +1,37 @@
# Controls on Nacre's pages hold still under the pointer (R1-21): drags the Interface size slider (the page keeps its
# layout and shows a value label while held, the size is set on release), drags Contrast (live), picks a Style chip
# (no chip moves). Needs the hidden tall layout (drag positions): SMOKE_SIZE=1280x1600, no SMOKE_VISIBLE.
# Expect: drag-held shows the 125 % label over the handle and the page still at 100 %; released shows the page at
# 125 %; chip-picked (back at 100 %) has Vibrant checked and no chip moved; contrast-held shows the scheme and the
# "Medium" label changed while held. home/.config/nacre-servo/Default/settings.json ends with ui.scale 1.0.
wait 3
resize 1280 1560
set /theme/mode "light"
page nacre://settings/appearance
wait 1.5
shot before
press 987 1351
wait 0.2
drag 1010 1351
wait 0.2
drag 1036 1351
wait 0.5
shot drag-held
status held
release
wait 1
shot released
set /ui/scale 1.0
wait 1
tap 585 889
wait 1
shot chip-picked
press 1036 1001
wait 0.2
drag 1100 1001
wait 0.5
shot contrast-held
release
wait 0.5
status done
quit