diff --git a/docs/ui-workspace-audit.md b/docs/ui-workspace-audit.md index 9f6a571..810cb84 100644 --- a/docs/ui-workspace-audit.md +++ b/docs/ui-workspace-audit.md @@ -177,3 +177,27 @@ Subsequent computer-control captures can display macOS's capture badge over the traffic lights. Fullscreen floating controls and mixed-DPI moves were not tested. Offline all-target Clippy with warnings denied, formatting, release app bundling and git whitespace checks passed; no cargo test or automated smoke script ran. + + +### Hover fades with immediate selection — 2026-10-25 + +Tab bodies, the + button and close-button hover backgrounds now use the same +160 ms cubic ease-out for entering and leaving. Each tab is tracked by its +stable ID; reversing a fade starts from the current sampled intensity. Adjacent +inactive dividers fade with the tab hover instead of disappearing abruptly. +Close-button colors interpolate from the tab's actual current background, +including the selected white surface. + +Hover state runs separately from geometry animation. The event loop schedules +frames until either transition finishes, including after the pointer stops or +leaves the window. Selected backgrounds and label colors still read the current +active flag directly, so selection has no color fade or animation delay. +Existing insertion/closure movement and native control alignment are retained. + +Native manual checks covered an inactive tab hover, leaving that tab, the + +hover, selecting a different tab and moving back into page content. Settled +screenshots confirmed hover does not select the tab, + has its hover surface, +selection changes to the clicked tab and idle separators return after leaving. +The capture API does not establish frame-accurate 160 ms timing. Offline +all-target Clippy, formatting, release bundling and whitespace checks passed; +no cargo test, automated smoke script or Docker task was run. diff --git a/src/app.rs b/src/app.rs index 61bdc79..d728151 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1156,6 +1156,11 @@ impl TesseraApp { size.width as f32 / window.scale_factor() as f32, ); self.tab_offset = self.tab_motion.offset; + self.tab_motion.sample_hover( + &mut self.tab_visual, + &namespace.document.frame.tabs, + pointer, + ); let scene = scene::build_scene( size.width, size.height, diff --git a/src/tabs.rs b/src/tabs.rs index 15f5900..eee96fc 100644 --- a/src/tabs.rs +++ b/src/tabs.rs @@ -6,6 +6,7 @@ use crate::{ }; use serde::{Deserialize, Serialize}; +mod hover; mod motion; pub use motion::{Motion, Visual}; @@ -264,7 +265,7 @@ pub fn draw( tabs: &[Tab], width: f32, scale: f32, - pointer: Option, + _pointer: Option, visual: &Visual, ) { let scaled = |rect: Rect| { @@ -281,14 +282,14 @@ pub fn draw( color: crate::system_ui::theme::BAR, }); let plus = visual.plus; - if pointer.is_some_and(|point| plus.contains(point)) { + if visual.plus_hover > 0.0 { list.push(DrawCommand::FillRoundedRect { rect: scaled(plus), radius: 6.0 * scale, color: crate::system_ui::theme::mix( crate::system_ui::theme::BAR, crate::system_ui::theme::TEXT, - 0.06, + 0.06 * visual.plus_hover, ), }); } @@ -327,19 +328,21 @@ pub fn draw( } let pill = scaled(pill_rect(item.rect)); let active = item.tab.active; - if active || pointer.is_some_and(|point| pill_rect(item.rect).contains(point)) { + let hover = visual.hover(item.tab.id); + let background = if active { + crate::system_ui::theme::BG + } else { + crate::system_ui::theme::mix( + crate::system_ui::theme::BAR, + crate::system_ui::theme::TEXT, + 0.06 * hover, + ) + }; + if active || hover > 0.0 { list.push(DrawCommand::FillRoundedRect { rect: pill, radius: 6.0 * scale, - color: if active { - crate::system_ui::theme::BG - } else { - crate::system_ui::theme::mix( - crate::system_ui::theme::BAR, - crate::system_ui::theme::TEXT, - 0.06, - ) - }, + color: background, }); } { @@ -381,14 +384,19 @@ pub fn draw( }); list.push(DrawCommand::PopClip); if item.rect.width >= 44.0 { - if pointer.is_some_and(|point| close_rect(item.rect).contains(point)) { + let close_hover = visual.close_hover(item.tab.id); + if close_hover > 0.0 { list.push(DrawCommand::FillRoundedRect { rect: scaled(close_rect(item.rect)), radius: 5.0 * scale, color: crate::system_ui::theme::mix( - crate::system_ui::theme::BAR, - crate::system_ui::theme::TEXT, - 0.12, + background, + crate::system_ui::theme::mix( + crate::system_ui::theme::BAR, + crate::system_ui::theme::TEXT, + 0.12, + ), + close_hover, ), }); } @@ -415,11 +423,8 @@ pub fn draw( list.push(DrawCommand::PushClip(scaled(visual.viewport))); for pair in tabs.windows(2) { let left = visual.rect(pair[0].id, Rect::default()); - let right = visual.rect(pair[1].id, Rect::default()); - let hovered = pointer.is_some_and(|point| { - pill_rect(left).contains(point) || pill_rect(right).contains(point) - }); - if !pair[0].active && !pair[1].active && !hovered { + let hover = visual.hover(pair[0].id).max(visual.hover(pair[1].id)); + if !pair[0].active && !pair[1].active && hover < 1.0 { list.push(DrawCommand::FillRoundedRect { rect: scaled(Rect::new( left.x + left.width - 0.5, @@ -431,7 +436,7 @@ pub fn draw( color: crate::system_ui::theme::mix( crate::system_ui::theme::BAR, crate::system_ui::theme::TEXT, - 0.18, + 0.18 * (1.0 - hover), ), }); } diff --git a/src/tabs/hover.rs b/src/tabs/hover.rs new file mode 100644 index 0000000..574dca1 --- /dev/null +++ b/src/tabs/hover.rs @@ -0,0 +1,63 @@ +//! Hover color transitions are independent of tab layout and selected state. +use super::{Point, Tab, Visual}; +use std::{collections::BTreeMap, time::Instant}; + +#[derive(Default)] +struct Fade { + from: f32, + target: f32, + started: Option, +} + +impl Fade { + fn sample(&mut self, hovered: bool, now: Instant) -> (f32, bool) { + let t = self.started.map_or(1.0, |start| { + (now.duration_since(start).as_secs_f32() / 0.16).min(1.0) + }); + let value = self.from + (self.target - self.from) * (1.0 - (1.0 - t).powi(3)); + let target = if hovered { 1.0 } else { 0.0 }; + if target != self.target { + // Reversing mid-fade starts at the currently visible color. + self.from = value; + self.target = target; + self.started = Some(now); + (value, true) + } else { + (value, t < 1.0) + } + } +} + +#[derive(Default)] +pub(super) struct Hover { + tabs: BTreeMap, + plus: Fade, +} + +impl Hover { + pub fn sample( + &mut self, + visual: &mut Visual, + tabs: &[Tab], + pointer: Option, + now: Instant, + ) -> bool { + let hit = pointer.and_then(|point| visual.hit(point)); + let (plus, mut animating) = self.plus.sample( + pointer.is_some_and(|point| visual.plus.contains(point)), + now, + ); + visual.plus_hover = plus; + self.tabs + .retain(|id, _| tabs.iter().any(|tab| tab.id == *id)); + visual.hovers.clear(); + for tab in tabs { + let (body, close) = self.tabs.entry(tab.id).or_default(); + let (body, body_animating) = body.sample(hit.is_some_and(|hit| hit.0 == tab.id), now); + let (close, close_animating) = close.sample(hit == Some((tab.id, true)), now); + visual.hovers.push((tab.id, body, close)); + animating |= body_animating || close_animating; + } + animating + } +} diff --git a/src/tabs/motion.rs b/src/tabs/motion.rs index 2c78c8e..aeb24c0 100644 --- a/src/tabs/motion.rs +++ b/src/tabs/motion.rs @@ -8,8 +8,22 @@ pub struct Visual { pub exiting: Vec<(Tab, Rect)>, pub viewport: Rect, pub plus: Rect, + pub hovers: Vec<(u64, f32, f32)>, + pub plus_hover: f32, } impl Visual { + pub fn hover(&self, id: u64) -> f32 { + self.hovers + .iter() + .find(|entry| entry.0 == id) + .map_or(0.0, |entry| entry.1) + } + pub fn close_hover(&self, id: u64) -> f32 { + self.hovers + .iter() + .find(|entry| entry.0 == id) + .map_or(0.0, |entry| entry.2) + } pub fn rect(&self, id: u64, fallback: Rect) -> Rect { self.rects .iter() @@ -29,6 +43,7 @@ impl Visual { } #[derive(Default)] pub struct Motion { + hover: super::hover::Hover, target: Visual, from: Visual, current: Visual, @@ -48,6 +63,13 @@ fn blend(a: Rect, b: Rect, t: f32) -> Rect { ) } impl Motion { + pub fn sample_hover(&mut self, visual: &mut Visual, tabs: &[Tab], pointer: Option) { + let now = Instant::now(); + if self.hover.sample(visual, tabs, pointer, now) { + let next = now + Duration::from_millis(16); + self.next_frame = Some(self.next_frame.map_or(next, |old| old.min(next))); + } + } pub fn scroll_to(&mut self, offset: f32) { self.offset = Some(offset); self.direct_scroll = true; @@ -82,6 +104,7 @@ impl Motion { .collect(), viewport: blend(self.from.viewport, self.target.viewport, eased), plus: blend(self.from.plus, self.target.plus, eased), + ..Visual::default() }; self.next_frame = (t < 1.0).then(|| now + Duration::from_millis(16)); }