S017: new tab page elements: clock, shortcuts, Now playing and Weather cards, search pill, three cards on a grid

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-11 22:17:08 -06:00
commit 6eb090632d
21 changed files with 1157 additions and 298 deletions

View file

@ -63,10 +63,11 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| Tool | Role | Available after |
|---|---|---|
| `nice cargo build --release -j 2` | compile check, produces `target/release/nacre` | now |
| `nice cargo test --release -j 2` | unit tests (38, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint) | first successful build; not alongside a build |
| `nice cargo test --release -j 2` | unit tests (44, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint, ui::pages::newtab) | first successful build; not alongside a build |
| `src/selftest.rs` | in-app self test: `NACRE_SCRIPT=<file>` runs script commands (listed at its top) | now |
| `tools/smoke.sh <script> [outdir]` | smoke run on a hidden Xvfb display with a throwaway home and software GL; outdir (default `target/smoke/<name>-<time>`) gets `nacre.log`, `selftest.log`, `<shot>.png`, `<status>.json`, `home/`; exits non-zero on crash, panic or no `status done`. Scripts in `tests/smoke/` (`launch.txt` offline, `https.txt` needs internet, `restore.txt` with `SMOKE_HOME=<launch outdir>/home`, `chrome.txt` chrome and every flyout dark and light, offline); header documents env vars and commands. `SMOKE_VISIBLE=1` shows the run on the user's screen (DP-1, real GPU, niri tiles the window so shots are narrower); use it whenever the user is watching (D-009). Read the PNGs | now (S003) |
| `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) |
| `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,13 +13,13 @@ Rebuild the new tab page layout and elements to match the video (UI-BRIEF "The n
- `src/ui/pages/newtab.rs` (whole), `src/media.rs` (visualizer API only)
## Steps
- [ ] Layout grid and spacing matching the frames, responsive to window width
- [ ] Greeting, clock (thin Outfit digits, accent tint, seconds, AM baseline) and date
- [ ] Shortcuts row with round icons, labels and dashed Add shortcut
- [ ] Now playing card: cookie artwork spinning while playing, dotted visualizer ring from `media.rs` levels, seek line, buttons including the missing shuffle/repeat, source chip
- [ ] Weather card with all fields from the brief (Open-Meteo data already exists)
- [ ] Pill search with accent button; Notes, Reading list and Top sites as three cards (Top sites becomes its own card)
- [ ] Smoke shots light/dark, with and without media playing; compare with `docs/ui-reference/` frames and fix
- [x] Layout grid and spacing matching the frames, responsive to window width
- [x] Greeting, clock (thin Outfit digits, accent tint, seconds, AM baseline) and date
- [x] Shortcuts row with round icons, labels and dashed Add shortcut
- [x] Now playing card: cookie artwork spinning while playing, dotted visualizer ring from `media.rs` levels, seek line, buttons including the missing shuffle/repeat, source chip
- [x] Weather card with all fields from the brief (Open-Meteo data already exists)
- [x] Pill search with accent button; Notes, Reading list and Top sites as three cards (Top sites becomes its own card)
- [x] Smoke shots light/dark, with and without media playing; compare with `docs/ui-reference/` frames and fix
- [ ] PROGRESS entry, INDEX line, commit `S017: …` and push
## End criteria

View file

@ -27,7 +27,7 @@ Tracker: https://claude.ai/artifact/9AD7fPfwJ4ASFzVTJGKU4h
## 04 UI redesign
- [x] [S015 — Material You foundation](04%20UI%20redesign/S015-material-foundation.md) · Opus high
- [x] [S016 — Chrome and menus redesign](04%20UI%20redesign/S016-ui-chrome.md) · Opus medium
- [ ] [S017 — New tab page: elements](04%20UI%20redesign/S017-ntp-elements.md) · Opus medium
- [x] [S017 — New tab page: elements](04%20UI%20redesign/S017-ntp-elements.md) · Opus medium
- [ ] [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
- [ ] [S020 — Other pages and dialogs redesign](04%20UI%20redesign/S020-ui-pages.md) · Sonnet high

View file

@ -179,7 +179,7 @@ pills `FULL`, small egui widgets `S` (`theme::corner`).
**Type.** Outfit (OFL, `assets/fonts/Outfit[wght].ttf`, one variable font) at `theme::Weight` Thin 200, Light 300,
Regular 400 (egui's Proportional), Medium 500, SemiBold 600; `theme::font(size, weight)`. Sizes `SMALL` 12, `BODY` 14,
`TITLE` 18, `HEADLINE` 24, `DISPLAY` 64 (clock: Thin, primary). egui text styles: Small/Body/Button/Heading(24
`TITLE` 18, `HEADLINE` 24, `DISPLAY` 64, `DISPLAY_LARGE` 96 (new tab clock: Thin, primary), `DISPLAY_SMALL` 40 (figures in cards). egui text styles: Small/Body/Button/Heading(24
Medium)/Monospace 13. Outfit is Latin only: every family falls back to Material Symbols, then egui's Ubuntu-Light
(Cyrillic, Greek). No CJK font is bundled.
@ -232,6 +232,21 @@ history, bookmarks, downloads, qr, apps, devtools, pip, screenshot, adblock, med
per the toolbar setting). Status on buttons: badges (blocked count, running downloads), a progress ring round
downloads, a coloured dot on the VPN, a slash through the shield when off. All icons are Material Symbols (D-009).
**New tab page** (S017, `src/ui/pages/newtab.rs`). A column of at most 920 pt (24 pt side margins) centred in the
page card, and centred vertically when it fits (measured the frame before; a `DEFAULT` spring moves it when elements
change). Elements come in `Settings::ntp.elements` order; `blocks()` groups card elements that follow each other into
rows on a 3-column grid (2 below 720 pt, 1 below 480 pt), Now playing spanning two columns; a short row is centred.
Rows: Now playing/Weather 224 pt (Now playing below 440 pt wide puts its artwork above, +136 pt), other cards 176 pt;
cards are `surface_container`, radius `L`, title = 18 pt icon + Body Medium in `primary`. Clock: `DISPLAY_LARGE` 96
(`DISPLAY` 64 under 560 pt) Thin `primary`, every digit in a cell as wide as the widest digit (no shifting), AM/PM
Headline Regular on the digits' baseline; date `util::format_long_date`. Shortcuts: 56 pt circles in 88 pt cells,
favicon of an open tab on that site else the first letter; dashed `outline` circle for Add; right-click opens/removes.
Search pill 640×56, `surface_container_high`, `primary` ring while focused, 40 pt `primary` go button. Media art,
visualizer ring (72 dots following the cookie's scallops, `outline` when still), seek bar, play button and titles
are shared with the media flyout: `menus::media_art`, `seek_bar`, `play_button`, `media_title`. Weather:
`newtab::Weather` (Open-Meteo current + daily, `Shared::weather` = `Option<Result<Weather, String>>`), fetched when
shown and missing, older than 30 min, or for another place/unit (after the place stays unchanged for 1 s).
**Floating surfaces** (`src/ui/menus.rs`). `menus::floating(ctx, id, pos, pivot, open, |ui| ..)` draws a
`menus::surface` (surface_container_high, radius `L`, popup shadow) that grows from its pivot corner (scale 0.9 to
1, `DEFAULT`) and fades in (`EFFECT`); with `open` false it shrinks and fades without input, then returns None.

View file

@ -84,6 +84,23 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- egui limits hit: Area capped at 600×400 unless `default_size`; Xvfb never focuses the window, so text focus drops
(selftest `type` sends Focused(true)); stale TextEdit selection shows after focus leaves (cleared by hand).
## S017 — New tab page elements (2026-11-11)
- Done: newtab.rs rebuilt: greeting, Thin clock in fixed digit cells + AM on its baseline + long date, shortcut
circles + dashed Add (right-click open/remove), Now playing card (shared `menus::media_art/seek_bar/play_button/
media_title`; ring follows the cookie's scallops; shuffle via the page's own button, repeat = loop; source chip),
Weather card (Open-Meteo feels-like, high/low, rain %, humidity, wind, place; empty/loading/failed states), search
pill, Notes / Reading list / Top sites cards on a 3/2/1-column grid. Defaults: video order, all on, seconds on.
- Handoff for S018: elements are `ntp.elements` keys greeting, clock, shortcuts, media, weather, search, notes,
reading, recent (= "Top sites"); `blocks()` packs consecutive cards into rows, so reorder/toggle is just that list.
Background code untouched (image texture now `f.ui.ntp_bg_texture`). User feedback on Shapes in the notes folder.
- Shots (`SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt`, target/smoke/s017-e): ntp-dark/light,
ntp-playing-dark/light, ntp-tall-dark/light, ntp-weather-error-dark, ntp-shapes-dark, ntp-narrow-dark,
ntp-phone-dark; target/smoke/s017-w weather-dark/light (real data). Checked against the video frames.
- Verified: 44 unit tests (+blocks, clock_text, weather parse, long date); newtab, launch, chrome smoke exit 0.
- Not done/seen: hover/press on shortcuts and cards, the stacked phone media card below the fold (no scroll command),
shuffle against a real player (YouTube Music, Spotify), real-GPU check.
## 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).
- Shortcut icons: a favicon cache by host (today only open tabs' favicons show); a `scroll` selftest command.

View file

@ -1971,28 +1971,40 @@ impl App {
if city.trim().is_empty() {
return;
}
self.spawn("weather", move || -> Result<(String, f64, u32, Option<(f64, f64)>), String> {
self.spawn("weather", move || -> Result<(crate::ui::pages::newtab::Weather, (f64, f64)), String> {
let (lat, lon) = match loc {
Some(l) => l,
None => {
let geo = crate::net::fetch::get_json(&format!("https://geocoding-api.open-meteo.com/v1/search?count=1&name={}", util::encode_query(&city)), Duration::from_secs(10))?;
let r = geo.get("results").and_then(|r| r.get(0)).ok_or("city not found")?;
let r = geo.get("results").and_then(|r| r.get(0)).ok_or("no place with that name")?;
(r.get("latitude").and_then(|v| v.as_f64()).unwrap_or(0.0), r.get("longitude").and_then(|v| v.as_f64()).unwrap_or(0.0))
},
};
let unit = if units == "f" || (units == "auto" && std::env::var("LANG").unwrap_or_default().contains("US")) { "&temperature_unit=fahrenheit" } else { "" };
let w = crate::net::fetch::get_json(&format!("https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current=temperature_2m,weather_code{unit}"), Duration::from_secs(10))?;
let temp = w.pointer("/current/temperature_2m").and_then(|v| v.as_f64()).unwrap_or(0.0);
let code = w.pointer("/current/weather_code").and_then(|v| v.as_u64()).unwrap_or(0) as u32;
Ok((city, temp, code, Some((lat, lon))))
let fahrenheit = crate::ui::pages::newtab::fahrenheit(&units);
let unit = if fahrenheit { "&temperature_unit=fahrenheit&wind_speed_unit=mph" } else { "" };
let w = crate::net::fetch::get_json(
&format!(
"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&timezone=auto&forecast_days=1\
&current=temperature_2m,apparent_temperature,relative_humidity_2m,weather_code,wind_speed_10m,is_day\
&daily=temperature_2m_max,temperature_2m_min,precipitation_probability_max{unit}"
),
Duration::from_secs(10),
)?;
Ok((crate::ui::pages::newtab::Weather::from_open_meteo(&city, &w, fahrenheit), (lat, lon)))
}, |app, result| {
if let Ok((city, temp, code, loc)) = result {
*app.shared.weather.borrow_mut() = Some((city, temp, code));
if app.shared.settings.borrow().ntp.city_loc.is_none() {
app.shared.settings.borrow_mut().ntp.city_loc = loc;
}
app.redraw_all();
match result {
Ok((weather, loc)) => {
// The place may have changed while this ran; keep the coordinates only for the place asked about.
let mut s = app.shared.settings.borrow_mut();
if s.ntp.city == weather.place && s.ntp.city_loc.is_none() {
s.ntp.city_loc = Some(loc);
}
drop(s);
*app.shared.weather.borrow_mut() = Some(Ok(weather));
},
Err(error) => *app.shared.weather.borrow_mut() = Some(Err(error)),
}
app.redraw_all();
});
}

View file

@ -110,7 +110,8 @@ pub struct Shared {
pub import_sources: RefCell<Vec<crate::importer::Source>>,
pub import_status: RefCell<String>,
pub toasts: RefCell<Vec<Toast>>,
pub weather: RefCell<Option<(String, f64, u32)>>,
/// Last weather answer for the new tab page, or why it failed.
pub weather: RefCell<Option<Result<crate::ui::pages::newtab::Weather, String>>>,
pub adblock_status: RefCell<String>,
pub system_dark: RefCell<bool>,
/// Hosts the user chose to open over plain http this session.
@ -1156,7 +1157,9 @@ impl App {
self.redraw_all();
}
// The visualizer runs only while someone looks at it.
let wanted = self.windows.values().any(|w| w.ui.flyout == Some(crate::ui::Flyout::Media)) && self.shared.settings.borrow().media.visualizer == crate::store::settings::Visualizer::Auto && self.shared.media_now.borrow().as_ref().is_some_and(|m| !m.state.paused);
let ntp_media = self.shared.settings.borrow().ntp.elements.iter().any(|(k, on)| k == "media" && *on);
let looked_at = self.windows.values().any(|w| w.ui.flyout == Some(crate::ui::Flyout::Media) || (ntp_media && w.tab().is_some_and(|t| t.page == Some(crate::tabs::Page::NewTab))));
let wanted = looked_at && self.shared.settings.borrow().media.visualizer == crate::store::settings::Visualizer::Auto && self.shared.media_now.borrow().as_ref().is_some_and(|m| !m.state.paused);
let mut cava = self.shared.cava.borrow_mut();
if wanted && !cava.running() && Cava::available() {
cava.start(&self.shared.paths.cache);

View file

@ -137,8 +137,11 @@ const MEDIA_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.media)
const creator = () => { const a = document.querySelector('ytd-watch-metadata ytd-channel-name a, #owner ytd-channel-name a,'
+ ' ytmusic-player-bar .byline a, .content-info-wrapper .byline a, a[href*="/channel/"], a[rel=author]');
return a && a.href && a.href.startsWith('https://') ? a.href : ''; };
// Players with their own shuffle button (YouTube Music, Spotify, SoundCloud and others that label it).
const shuf = () => document.querySelector('ytmusic-player-bar .shuffle, [data-testid=control-button-shuffle],'
+ ' button.shuffleControl, button[aria-label*="huffle"], [role=button][aria-label*="huffle"]');
const state = () => {
const m = pick(), md = navigator.mediaSession && navigator.mediaSession.metadata;
const m = pick(), md = navigator.mediaSession && navigator.mediaSession.metadata, sh = shuf();
if (!m && !md) return null;
let art = '';
if (md && md.artwork && md.artwork.length) {
@ -150,7 +153,8 @@ const MEDIA_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.media)
paused: m ? m.paused : !(navigator.mediaSession && navigator.mediaSession.playbackState === 'playing'),
muted: m ? m.muted : false, loop: m ? m.loop : false, has_next: !!H.nexttrack, has_prev: !!H.previoustrack,
creator_url: creator(), ad: !!document.querySelector('#movie_player.ad-showing, ytmusic-player.ad-showing'),
is_video: !!(m && m.tagName === 'VIDEO') };
is_video: !!(m && m.tagName === 'VIDEO'), has_shuffle: !!sh,
shuffle: !!sh && (sh.getAttribute('aria-pressed') === 'true' || sh.getAttribute('aria-checked') === 'true' || sh.classList.contains('m-active')) };
};
let last = '', timer = 0;
const report = () => { timer = 0; const s = state(); const k = JSON.stringify(s && Object.assign({}, s, { position: Math.round((s.position || 0) / 5) }));
@ -171,6 +175,7 @@ const MEDIA_JS: &str = r#"(() => { if (!window.__nacre || window.__nacre.media)
else if (a === 'seek' && m) m.currentTime = v;
else if (a === 'skip' && m) m.currentTime = Math.max(0, m.currentTime + v);
else if (a === 'loop' && m) m.loop = !m.loop;
else if (a === 'shuffle') { const b = shuf(); if (b) b.click(); }
else if (a === 'mute') document.querySelectorAll('video,audio').forEach(e => e.muted = !!v);
else if (a === 'volume' && m) { m.volume = Math.min(1, Math.max(0, v)); m.muted = false; }
setTimeout(report, 50);

View file

@ -29,6 +29,9 @@ pub struct MediaState {
/// A YouTube ad is showing: keep the previous Discord activity.
pub ad: bool,
pub is_video: bool,
/// The page has a shuffle button of its own, and whether it is on.
pub has_shuffle: bool,
pub shuffle: bool,
}
impl MediaState {

View file

@ -457,7 +457,8 @@ pub struct Ntp {
impl Default for Ntp {
fn default() -> Self {
let elements = [("clock", true), ("greeting", false), ("search", true), ("shortcuts", true), ("media", true), ("weather", false), ("notes", false), ("reading", false), ("recent", false)];
// The order of the page in the user's recording (docs/UI-BRIEF.md); "recent" is the Top sites card.
let elements = [("greeting", true), ("clock", true), ("shortcuts", true), ("media", true), ("weather", true), ("search", true), ("notes", true), ("reading", true), ("recent", true)];
let shortcuts = [
("YouTube", "https://www.youtube.com"),
("GitHub", "https://github.com"),
@ -476,7 +477,7 @@ impl Default for Ntp {
bg_blur: 0.0,
elements: elements.iter().map(|(k, on)| ((*k).to_owned(), *on)).collect(),
clock24: false,
seconds: false,
seconds: true,
name: String::new(),
city: String::new(),
city_loc: None,

View file

@ -347,6 +347,10 @@ pub const BODY: f32 = 14.0;
pub const TITLE: f32 = 18.0;
pub const HEADLINE: f32 = 24.0;
pub const DISPLAY: f32 = 64.0;
/// The new tab clock.
pub const DISPLAY_LARGE: f32 = 96.0;
/// Big figures inside cards (the weather temperature).
pub const DISPLAY_SMALL: f32 = 40.0;
/// Outfit weights registered as font families (`ui::fonts`). Regular is egui's Proportional family.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]

View file

@ -140,6 +140,14 @@ pub const RAINY: &str = "\u{f176}";
pub const WEATHER_SNOWY: &str = "\u{e2cd}";
pub const THUNDERSTORM: &str = "\u{ebdb}";
pub const FOGGY: &str = "\u{e818}";
pub const THERMOSTAT: &str = "\u{f076}";
pub const UMBRELLA: &str = "\u{f1ad}";
pub const HUMIDITY_PERCENTAGE: &str = "\u{f87e}";
pub const AIR: &str = "\u{efd8}";
pub const PLACE: &str = "\u{f1db}";
pub const STICKY_NOTE_2: &str = "\u{f1fc}";
pub const TRENDING_UP: &str = "\u{e8e5}";
pub const REPEAT_ONE: &str = "\u{e041}";
pub const SAVE: &str = "\u{e161}";
pub const FIND_IN_PAGE: &str = "\u{e880}";
pub const POWER_SETTINGS_NEW: &str = "\u{f8c7}";
@ -290,6 +298,14 @@ pub const ALL: &[(&str, &str)] = &[
("weather_snowy", WEATHER_SNOWY),
("thunderstorm", THUNDERSTORM),
("foggy", FOGGY),
("thermostat", THERMOSTAT),
("umbrella", UMBRELLA),
("humidity_percentage", HUMIDITY_PERCENTAGE),
("air", AIR),
("place", PLACE),
("sticky_note_2", STICKY_NOTE_2),
("trending_up", TRENDING_UP),
("repeat_one", REPEAT_ONE),
("save", SAVE),
("find_in_page", FIND_IN_PAGE),
("power_settings_new", POWER_SETTINGS_NEW),

View file

@ -817,91 +817,22 @@ fn media(ui: &mut Ui, f: &mut Frame) {
});
return;
};
let settings = f.shared.settings.borrow().media.clone();
let state = &now.state;
let time = ui.input(|i| i.time);
let playing = !state.paused;
// Artwork in a cookie that turns while it plays; the visualizer as dots round it.
let still = crate::perf::still(&f.shared.settings.borrow());
let spin = settings.spin && playing && !still;
let angle = if spin { (time * 0.3) as f32 % std::f32::consts::TAU } else { 0.0 };
let (art, _) = ui.allocate_exact_size(vec2(ui.available_width(), 168.0), Sense::hover());
let center = art.center();
let texture = if state.art.is_empty() {
None
} else {
let image = f.shared.art_images.borrow().get(&state.art).cloned();
match image {
None => {
f.send(Command::FetchArt(state.art.clone()));
None
},
Some(Some(image)) => {
let key = state.art.clone();
Some(match &f.ui.art_texture {
Some((k, t)) if *k == key => t.clone(),
_ => {
let t = ui.ctx().load_texture(format!("art:{key}"), image, egui::TextureOptions::LINEAR);
f.ui.art_texture = Some((key, t.clone()));
t
},
})
},
Some(None) => None,
}
};
if settings.visualizer != Visualizer::Off && playing {
let target = f.shared.cava.borrow().levels().unwrap_or_else(|| crate::media::simulated_levels(time));
let dt = ui.input(|i| i.stable_dt).min(0.1);
crate::media::ease_levels(&mut f.ui.levels, &target, dt);
let n = f.ui.levels.len().max(1);
for i in 0..48 {
let a = angle + i as f32 / 48.0 * std::f32::consts::TAU;
let level = f.ui.levels.get(i * n / 48).copied().unwrap_or(0.0);
let r = 68.0 + 12.0 * level;
ui.painter().circle_filled(center + r * vec2(a.cos(), a.sin()), 1.5 + level, p.primary);
}
ui.ctx().request_repaint();
}
match texture {
Some(texture) => crate::ui::paint::cookie_image(ui.painter(), texture.id(), center, 62.0, 9, angle),
None => {
crate::ui::paint::cookie(ui.painter(), center, 62.0, 9, angle, p.secondary_container, Stroke::NONE);
icon(ui, center, icons::MUSIC_NOTE, theme::ICON_LARGE, false, p.on_secondary_container);
},
}
if spin {
ui.ctx().request_repaint();
}
media_art(ui, f, art.center(), 62.0, Some(state));
ui.add_space(theme::GAP_S);
ui.vertical_centered(|ui| {
let width = ui.available_width() - 2.0 * theme::GAP_S;
let title = if state.title.is_empty() { &now.title } else { &state.title };
ui.label(one_line(ui, title, theme::font(theme::TITLE, Weight::Medium), p.on_surface, width));
let by = if state.artist.is_empty() { &now.host } else { &state.artist };
ui.label(one_line(ui, by, theme::font(theme::BODY, Weight::Regular), p.on_surface_variant, width));
let (title, by) = media_title(f, &now);
ui.label(one_line(ui, &title, theme::font(theme::TITLE, Weight::Medium), p.on_surface, width));
ui.label(one_line(ui, &by, theme::font(theme::BODY, Weight::Regular), p.on_surface_variant, width));
});
// Position: a wave while playing, flat when paused; drag or click to seek.
if state.duration > 0.0 {
let pos = state.position_at(now.received_ms);
let (rect, response) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::click_and_drag());
let bar = rect.shrink2(vec2(theme::GAP_S, 6.0));
let pointer_value = response.interact_pointer_pos().map(|p| ((p.x - bar.left()) / bar.width()).clamp(0.0, 1.0) * state.duration as f32);
if response.dragged()
&& let Some(v) = pointer_value
{
f.ui.media_seek = Some(v);
}
let value = f.ui.media_seek.unwrap_or(pos as f32);
if (response.drag_stopped() || response.clicked())
&& let Some(v) = pointer_value
{
f.ui.media_seek = None;
f.send(Command::Media { tab: now.tab, action: "seek".into(), value: v as f64 });
}
let amplitude = theme::spring(ui.ctx(), Id::new("media-wave"), if playing { 3.0 } else { 0.0 }, theme::DEFAULT);
let phase = if playing { time as f32 * 4.0 } else { 0.0 };
crate::ui::paint::wavy_progress(ui.painter(), bar, value / state.duration as f32, amplitude, phase, &p);
let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), 24.0), Sense::hover());
seek_bar(ui, f, Some(&now), rect.shrink2(vec2(theme::GAP_S, 0.0)));
let small = theme::font(theme::SMALL, Weight::Regular);
ui.horizontal(|ui| {
ui.add_space(theme::GAP_S);
@ -954,15 +885,119 @@ fn media(ui: &mut Ui, f: &mut Frame) {
});
}
/// Artwork (or a note) in a cookie that turns while it plays, with the visualizer as a ring of dots round it that
/// lies still while nothing plays. Used by the media flyout and the new tab page.
pub fn media_art(ui: &mut Ui, f: &mut Frame, center: Pos2, radius: f32, state: Option<&crate::media::MediaState>) {
let p = theme::palette(ui.ctx());
let settings = f.shared.settings.borrow().media.clone();
let time = ui.input(|i| i.time);
let playing = state.is_some_and(|s| !s.paused);
let still = crate::perf::still(&f.shared.settings.borrow());
let spin = settings.spin && playing && !still;
let angle = if spin { (time * 0.3) as f32 % std::f32::consts::TAU } else { 0.0 };
let art = state.map(|s| s.art.clone()).unwrap_or_default();
let texture = if art.is_empty() {
None
} else {
let image = f.shared.art_images.borrow().get(&art).cloned();
match image {
None => {
f.send(Command::FetchArt(art.clone()));
None
},
Some(Some(image)) => Some(match &f.ui.art_texture {
Some((k, t)) if *k == art => t.clone(),
_ => {
let t = ui.ctx().load_texture(format!("art:{art}"), image, egui::TextureOptions::LINEAR);
f.ui.art_texture = Some((art, t.clone()));
t
},
}),
Some(None) => None,
}
};
let live = settings.visualizer != Visualizer::Off && playing;
if live {
let target = f.shared.cava.borrow().levels().unwrap_or_else(|| crate::media::simulated_levels(time));
let dt = ui.input(|i| i.stable_dt).min(0.1);
crate::media::ease_levels(&mut f.ui.levels, &target, dt);
ui.ctx().request_repaint();
}
// The dots follow the cookie's scallops just outside its edge and turn with it; loud bands push them out.
const DOTS: usize = 72;
let n = f.ui.levels.len().max(1);
for i in 0..DOTS {
let a = angle + i as f32 / DOTS as f32 * std::f32::consts::TAU;
let level = if live { f.ui.levels.get(i * n / DOTS).copied().unwrap_or(0.0) } else { 0.0 };
let edge = radius * (1.0 - crate::ui::paint::COOKIE_DEPTH * (1.0 - (9.0 * (a - angle)).cos()) / 2.0);
let r = edge + radius * 0.12 + radius * 0.22 * level;
let color = if live { p.primary } else { p.outline };
ui.painter().circle_filled(center + r * vec2(a.cos(), a.sin()), radius / 48.0 + level, color);
}
match texture {
Some(texture) => crate::ui::paint::cookie_image(ui.painter(), texture.id(), center, radius, 9, angle),
None => {
crate::ui::paint::cookie(ui.painter(), center, radius, 9, angle, p.secondary_container, Stroke::NONE);
icon(ui, center, icons::MUSIC_NOTE, radius * 0.6, false, p.on_secondary_container);
},
}
if spin {
ui.ctx().request_repaint();
}
}
/// Title and second line for media: the page's metadata, else the tab's title (pages without metadata report
/// their title, which may still be the address while it loads), and the artist, else the site.
pub fn media_title(f: &Frame, now: &crate::app::MediaNow) -> (String, String) {
let tab_title = f.tabs.iter().find(|t| t.id == now.tab).map(|t| t.display_title()).unwrap_or_else(|| now.title.clone());
let title = if now.state.title.is_empty() || now.state.title.contains("://") { tab_title } else { now.state.title.clone() };
let by = [&now.state.artist, &now.host].into_iter().find(|s| !s.is_empty()).cloned().unwrap_or_else(|| "Playing in a tab".to_owned());
(title, by)
}
/// The position line inside `rect`: a wave while playing, flat when paused; drag or click to seek. Without media
/// (`now` None) a flat empty line.
pub fn seek_bar(ui: &mut Ui, f: &mut Frame, now: Option<&crate::app::MediaNow>, rect: Rect) {
let p = theme::palette(ui.ctx());
let bar = rect.shrink2(vec2(0.0, (rect.height() - 12.0).max(0.0) / 2.0));
let Some(now) = now.filter(|n| n.state.duration > 0.0) else {
crate::ui::paint::wavy_progress(ui.painter(), bar, 0.0, 0.0, 0.0, &p);
return;
};
let state = &now.state;
let playing = !state.paused;
let response = ui.interact(rect, ui.id().with("seek"), Sense::click_and_drag());
let pointer_value = response.interact_pointer_pos().map(|p| ((p.x - bar.left()) / bar.width()).clamp(0.0, 1.0) * state.duration as f32);
if response.dragged()
&& let Some(v) = pointer_value
{
f.ui.media_seek = Some(v);
}
let value = f.ui.media_seek.unwrap_or(state.position_at(now.received_ms) as f32);
if (response.drag_stopped() || response.clicked())
&& let Some(v) = pointer_value
{
f.ui.media_seek = None;
f.send(Command::Media { tab: now.tab, action: "seek".into(), value: v as f64 });
}
let amplitude = theme::spring(ui.ctx(), ui.id().with("seek-wave"), if playing { 3.0 } else { 0.0 }, theme::DEFAULT);
let phase = if playing { ui.input(|i| i.time) as f32 * 4.0 } else { 0.0 };
crate::ui::paint::wavy_progress(ui.painter(), bar, value / state.duration as f32, amplitude, phase, &p);
if playing {
ui.ctx().request_repaint_after(std::time::Duration::from_millis(500));
}
}
/// The big play/pause button: a filled circle that turns into a rounded square while playing (M3 Expressive).
fn play_button(ui: &mut Ui, playing: bool) -> Response {
pub fn play_button(ui: &mut Ui, playing: bool) -> Response {
let p = theme::palette(ui.ctx());
let (rect, response) = ui.allocate_exact_size(Vec2::splat(56.0), Sense::click());
let s = interaction(ui, &response);
let square = theme::spring(ui.ctx(), response.id.with("shape"), if playing { 1.0 } else { 0.0 }, theme::DEFAULT);
let radius = egui::lerp(28.0..=theme::radius(ui.ctx(), theme::L), square.clamp(0.0, 1.2)) - s.press.clamp(0.0, 1.0) * 4.0;
ui.painter().rect_filled(rect.shrink(s.press.clamp(0.0, 1.0) * 2.0), theme::corner_radius(radius), s.layer(p.primary, p.on_primary));
icon(ui, rect.center(), if playing { icons::PAUSE } else { icons::PLAY_ARROW }, theme::ICON_LARGE * 0.9, true, p.on_primary);
let (fill, content) = if s.enabled { (s.layer(p.primary, p.on_primary), p.on_primary) } else { (p.on_surface.gamma_multiply(theme::DISABLED_CONTAINER), p.on_surface.gamma_multiply(theme::DISABLED_CONTENT)) };
ui.painter().rect_filled(rect.shrink(s.press.clamp(0.0, 1.0) * 2.0), theme::corner_radius(radius), fill);
icon(ui, rect.center(), if playing { icons::PAUSE } else { icons::PLAY_ARROW }, theme::ICON_LARGE * 0.9, true, content);
if s.focus {
focus_ring(ui, rect, radius, &p);
}

View file

@ -86,6 +86,8 @@ pub struct WindowUi {
pub dragging_tab: Option<(u64, f32)>,
pub qr_texture: Option<(String, egui::TextureHandle)>,
pub art_texture: Option<(String, egui::TextureHandle)>,
/// New tab background image (its own slot, so it doesn't fight the artwork for `art_texture`).
pub ntp_bg_texture: Option<(String, egui::TextureHandle)>,
/// Visualizer bars shown in the media flyout.
pub levels: Vec<f32>,
pub last_level_poll: f64,

File diff suppressed because it is too large Load diff

View file

@ -922,7 +922,10 @@ fn newtab(ui: &mut Ui, f: &mut Frame, s: &mut Settings) {
switch_row(ui, "24-hour clock", "", &mut s.ntp.clock24);
switch_row(ui, "Show seconds", "", &mut s.ntp.seconds);
row(ui, "Your name", "For the greeting", |ui| ui.add(egui::TextEdit::singleline(&mut s.ntp.name)));
row(ui, "City", "For the weather (Open-Meteo)", |ui| ui.add(egui::TextEdit::singleline(&mut s.ntp.city)));
if row(ui, "City", "For the weather (Open-Meteo)", |ui| ui.add(egui::TextEdit::singleline(&mut s.ntp.city))).changed() {
// The saved coordinates belong to the old place.
s.ntp.city_loc = None;
}
row(ui, "Units", "", |ui| {
let mut u = s.ntp.units.clone();
ui.selectable_value(&mut u, "auto".to_owned(), "Auto");
@ -1000,7 +1003,7 @@ fn element_label(key: &str) -> &'static str {
"weather" => "Weather",
"notes" => "Notes",
"reading" => "Reading list",
"recent" => "Recently visited",
"recent" => "Top sites",
_ => "Other",
}
}

View file

@ -194,6 +194,13 @@ pub fn format_day_heading(at: u64) -> String {
}
}
const MONTHS_LONG: [&str; 12] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
/// "Wednesday, November 11"
pub fn format_long_date(t: DateTime) -> String {
format!("{}, {} {}", WEEKDAYS[t.weekday as usize], MONTHS_LONG[(t.month - 1) as usize], t.day)
}
/// Day number in local time, for grouping entries by day.
pub fn local_day(at: u64) -> i64 {
(at as i64 + local_offset(at)).div_euclid(86_400)
@ -459,6 +466,12 @@ mod tests {
const DDG: &str = "https://duckduckgo.com/?q=%s";
#[test]
fn long_date() {
let t = DateTime { year: 2026, month: 11, day: 11, hour: 6, minute: 11, second: 34, weekday: 2 };
assert_eq!(format_long_date(t), "Wednesday, November 11");
}
#[test]
fn address_bar_input() {
assert_eq!(address_to_url("example.com", DDG).unwrap().as_str(), "https://example.com/");

View file

@ -0,0 +1,14 @@
# New tab weather card with real Open-Meteo data (needs internet; no proxy). Run with tools/smoke.sh; read the PNGs.
wait 3
set /theme/mode "dark"
set /ntp/bg "off"
set /ntp/city "Trenton"
set /ntp/units "f"
page nacre://newtab
wait 8
shot weather-dark
set /theme/mode "light"
wait 1
shot weather-light
status done
quit

49
tests/smoke/newtab.txt Normal file
View file

@ -0,0 +1,49 @@
# New tab page elements (S017) in dark and light, with nothing playing and with a video playing in another tab,
# plus a narrow window. Offline: the weather card shows its no-place and failed states (newtab-weather.txt has the
# real one). Run with SMOKE_SIZE=1400x1200 tools/smoke.sh (for the tall shots); read the PNGs.
wait 3
set /theme/mode "dark"
set /ntp/name "Sam"
set /ntp/bg "off"
newtab @PAGES@/hello.html
waitload 30
newtab @PAGES@/color.html
waitload 30
page nacre://newtab
set /ntp/notes "Call the bank\nBuy oat milk"
wait 1
shot ntp-dark
set /theme/mode "light"
wait 1
shot ntp-light
newtab @PAGES@/video.html
waitload 30
wait 2
cmd mute
page nacre://newtab
wait 2
shot ntp-playing-light
set /theme/mode "dark"
wait 1
shot ntp-playing-dark
set /ntp/city "Qqqzzx"
wait 4
shot ntp-weather-error-dark
set /ntp/bg "shapes"
wait 1
shot ntp-shapes-dark
resize 1360 1140
wait 1
shot ntp-tall-dark
set /theme/mode "light"
wait 1
shot ntp-tall-light
set /theme/mode "dark"
resize 700 760
wait 1
shot ntp-narrow-dark
resize 420 760
wait 1
shot ntp-phone-dark
status done
quit

Some files were not shown because too many files have changed in this diff Show more