A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.
Rust agentagent-orchestrationaiai-agentsclaude-codecodexcoding-agentlinuxmacosmultiplayermultiplexerrustterminalterminal-emulatorterminal-multiplexertmuxtuiweztermwindows
gui: refresh the shared UI toolkit
RoversX0817371d3c3b
diff --git a/wezterm-gui/src/glyphcache.rs b/wezterm-gui/src/glyphcache.rsindex bb531fc3..14cef0d1 100644--- a/wezterm-gui/src/glyphcache.rs+++ b/wezterm-gui/src/glyphcache.rs@@ -634,6 +634,9 @@ pub struct GlyphCache {pub block_glyphs: HashMap<SizedBlockKey, Sprite>,pub svg_icons: HashMap<SizedSvgIconKey, Sprite>,pub brand_icons: HashMap<SizedBrandIconKey, Sprite>,+ /// The application icon, keyed by pixel size. One raster decode per+ /// size, reused for the life of the cache.+ pub app_icons: HashMap<u16, Sprite>,pub material_icons: HashMap<SizedMaterialIconKey, Sprite>,pub cursor_glyphs: HashMap<(Option<CursorShape>, u8), Sprite>,pub color: HashMap<(RgbColor, NotNan<f32>), Sprite>,@@ -703,6 +706,7 @@ impl GlyphCache {block_glyphs: HashMap::new(),svg_icons: HashMap::new(),brand_icons: HashMap::new(),+ app_icons: HashMap::new(),material_icons: HashMap::new(),rotated_svg_icons: HashMap::new(),cursor_glyphs: HashMap::new(),@@ -738,6 +742,7 @@ impl GlyphCache {block_glyphs: HashMap::new(),svg_icons: HashMap::new(),brand_icons: HashMap::new(),+ app_icons: HashMap::new(),material_icons: HashMap::new(),rotated_svg_icons: HashMap::new(),cursor_glyphs: HashMap::new(),@@ -1418,6 +1423,19 @@ impl GlyphCache {Ok(sprite)}+ pub fn cached_app_icon(&mut self, size: usize) -> anyhow::Result<Sprite> {+ let size = size.max(1).min(u16::MAX as usize);+ let key = size as u16;+ if let Some(sprite) = self.app_icons.get(&key) {+ return Ok(sprite.clone());+ }++ let image = crate::termwindow::ui::icons::rasterize_app_icon(size)?;+ let sprite = self.atlas.allocate(&image)?;+ self.app_icons.insert(key, sprite.clone());+ Ok(sprite)+ }+pub fn cached_material_icon(&mut self,icon: MaterialIcon,diff --git a/wezterm-gui/src/termwindow/live_overview.rs b/wezterm-gui/src/termwindow/live_overview.rsindex 0d864ed8..bb1e49d7 100644--- a/wezterm-gui/src/termwindow/live_overview.rs+++ b/wezterm-gui/src/termwindow/live_overview.rs@@ -8,7 +8,9 @@ use crate::termwindow::{TermWindow, TermWindowNotif};use crate::ui::anim::{self, Easing, Timeline};use crate::ui::{draw_button_on_layer, draw_icon_button, draw_icon_button_on_layer, draw_scrollbar_on_layer,- precise_wheel_delta_pixels, wheel_delta_pixels, ButtonSpec, ControlState, DrawContext,+ card_is_warm, card_rect, grid_card_width, precise_wheel_delta_pixels, row_fully_visible,+ row_visible, shared_grid_columns, wheel_delta_pixels, ButtonSpec, ButtonVariant, CardGrid,+ ControlState, DrawContext, RowAlign,InteractionState, ScrollState, UiContext, UiPalette, UiTokens, WidgetKind,};use crate::workspace_threads;@@ -214,19 +216,11 @@ struct PendingClose {title: String,}-#[derive(Clone, Copy, Debug)]-struct GroupGrid {- columns: usize,- rows: usize,- card_width: f32,- card_height: f32,-}-#[derive(Clone, Copy, Debug)]struct GroupLayout {header_y: f32,cards_y: f32,- grid: GroupGrid,+ grid: CardGrid,}/// Where a card is travelling from and to, so that a change of layout is@@ -546,6 +540,8 @@ impl LiveOverviewView {content_width,layout.cards_y,gap,+ // Big tiles: a short last row centred under the full ones.+ RowAlign::Center,);// Card rectangles are in content space, so the band on screen right now// is `[offset, offset + viewport_height]`.@@ -753,6 +749,7 @@ impl LiveOverviewView {content_width,layout.cards_y,gap,+ RowAlign::Center,);seen_keys.insert(card.key.clone());let rect =@@ -1371,8 +1368,8 @@ impl LiveOverviewView {let confirm_label = crate::i18n::tr("live-overview-close-confirm");let button_gap = ctx.px(CONFIRM_BUTTON_GAP);let button_available = (dialog.size.width - padding * 2.0 - button_gap).max(2.0);- let desired_cancel = ctx.measure_text_width(font, &cancel_label) + ctx.px(36.0);- let desired_confirm = ctx.measure_text_width(font, &confirm_label) + ctx.px(36.0);+ let desired_cancel = ctx.measure_text_width(font, &cancel_label) + ctx.px(56.0);+ let desired_confirm = ctx.measure_text_width(font, &confirm_label) + ctx.px(56.0);let (cancel_width, confirm_width) = if desired_cancel + desired_confirm <= button_available{(desired_cancel, desired_confirm)@@ -1395,6 +1392,7 @@ impl LiveOverviewView {rect: euclid::rect(cancel_x, buttons_y, cancel_width, tokens.control_height),state: cancel_state,kind: WidgetKind::Button,+ variant: ButtonVariant::Secondary,},2,)?;@@ -1411,6 +1409,7 @@ impl LiveOverviewView {rect: euclid::rect(confirm_x, buttons_y, confirm_width, tokens.control_height),state: confirm_state,kind: WidgetKind::Button,+ variant: ButtonVariant::Primary,},2,)@@ -2137,52 +2136,6 @@ fn max_columns_for_surface_width(surface_width: f32, five_column_width: f32) ->}}-fn grid_columns(width: f32, minimum: f32, gap: f32, maximum: usize) -> usize {- if maximum == 0 {- return 0;- }- if maximum == 1 || width <= minimum {- 1- } else {- (((width + gap) / (minimum + gap)).floor() as usize).clamp(1, maximum)- }-}--fn single_orphan_group_count(counts: &[usize], columns: usize) -> usize {- if columns == 0 {- return 0;- }- counts- .iter()- .filter(|&&count| count > columns && count % columns == 1)- .count()-}--fn shared_grid_columns(- counts: &[usize],- content_width: f32,- maximum_columns: usize,- minimum: f32,- orphan_comfort_width: f32,- gap: f32,-) -> usize {- let mut columns = grid_columns(content_width, minimum, gap, maximum_columns);- if columns == 0 {- return 0;- }- let initial_available =- (content_width - gap * columns.saturating_sub(1) as f32) / columns as f32;- if columns > 2 && initial_available < orphan_comfort_width {- let reduced_columns = columns - 1;- if single_orphan_group_count(counts, reduced_columns)- < single_orphan_group_count(counts, columns)- {- columns = reduced_columns;- }- }- columns-}-#[allow(clippy::too_many_arguments)]fn group_grid(count: usize,@@ -2193,19 +2146,15 @@ fn group_grid(card_header_height: f32,card_inset: f32,preview_aspect: f32,-) -> GroupGrid {+) -> CardGrid {if columns == 0 {- return GroupGrid {- columns: 0,- rows: 0,- card_width: 0.0,- card_height: 0.0,- };+ return CardGrid::EMPTY;}- let available = (content_width - gap * columns.saturating_sub(1) as f32) / columns as f32;- let card_width = available.min(maximum).max(1.0);+ // Unlike a plain card grid, an overview card's height follows from its+ // width: the preview keeps the host terminal's aspect.+ let card_width = grid_card_width(content_width, columns, maximum, gap);let preview_width = (card_width - card_inset * 2.0).max(1.0);- GroupGrid {+ CardGrid {columns,rows: (count + columns - 1) / columns,card_width,@@ -2266,46 +2215,11 @@ fn group_layouts((layouts, (y - group_gap).max(0.0))}-fn card_rect(- index: usize,- count: usize,- grid: GroupGrid,- content_x: f32,- content_width: f32,- cards_y: f32,- gap: f32,-) -> RectF {- let row = index / grid.columns;- let column = index % grid.columns;- let row_start = row * grid.columns;- let row_count = (count - row_start).min(grid.columns);- let row_width = row_count as f32 * grid.card_width + row_count.saturating_sub(1) as f32 * gap;- let row_x = content_x + (content_width - row_width).max(0.0) / 2.0;- euclid::rect(- row_x + column as f32 * (grid.card_width + gap),- cards_y + row as f32 * (grid.card_height + gap),- grid.card_width,- grid.card_height,- )-}--fn row_visible(y: f32, height: f32, viewport: RectF) -> bool {- y + height > viewport.min_y() && y < viewport.max_y()-}--fn card_is_warm(rect: RectF, viewport: RectF, overscan: f32) -> bool {- let warm_top = viewport.min_y() - overscan.max(0.0);- let warm_bottom = viewport.max_y() + overscan.max(0.0);- rect.max_y() > warm_top && rect.min_y() < warm_bottom-}--fn row_fully_visible(y: f32, height: f32, viewport: RectF) -> bool {- y >= viewport.min_y() && y + height <= viewport.max_y()-}-#[cfg(test)]mod tests {use super::*;+ // Lives in `ui::geometry` now, and only the tests reach for it directly.+ use crate::ui::grid_columns;#[allow(clippy::too_many_arguments)]fn test_group_grid(@@ -2319,7 +2233,7 @@ mod tests {card_header_height: f32,card_inset: f32,preview_aspect: f32,- ) -> GroupGrid {+ ) -> CardGrid {let columns = shared_grid_columns(&[count],content_width,@@ -2434,7 +2348,7 @@ mod tests {for count in 1..=10 {let grid = test_group_grid(count, 1332.0, 5, 400.0, 480.0, 640.0, 16.0, 44.0, 8.0, 1.8);let rects = (0..count)- .map(|idx| card_rect(idx, count, grid, 84.0, 1332.0, 100.0, 16.0))+ .map(|idx| card_rect(idx, count, grid, 84.0, 1332.0, 100.0, 16.0, RowAlign::Center)).collect::<Vec<_>>();assert_eq!(grid.rows, (count + grid.columns - 1) / grid.columns);for (idx, rect) in rects.iter().enumerate() {@@ -2508,7 +2422,7 @@ mod tests {#[test]fn card_hit_rect_matches_painted_geometry() {let grid = test_group_grid(5, 1332.0, 5, 400.0, 480.0, 640.0, 16.0, 44.0, 8.0, 1.8);- let rect = card_rect(2, 5, grid, 84.0, 1332.0, 100.0, 16.0);+ let rect = card_rect(2, 5, grid, 84.0, 1332.0, 100.0, 16.0, RowAlign::Center);let mut widgets = UiContext::default();widgets.push(rect, WidgetKind::SidebarRow, OverviewAction::OpenThread(42));let hit = widgets@@ -2577,7 +2491,7 @@ mod tests {vec![GroupLayout {header_y: 0.0,cards_y: 40.0,- grid: GroupGrid {+ grid: CardGrid {columns,rows,card_width: 480.0,diff --git a/wezterm-gui/src/termwindow/project_root_view.rs b/wezterm-gui/src/termwindow/project_root_view.rsindex a9bee07f..f2494778 100644--- a/wezterm-gui/src/termwindow/project_root_view.rs+++ b/wezterm-gui/src/termwindow/project_root_view.rs@@ -11,7 +11,8 @@ use crate::termwindow::ui::icons::SvgIcon;use crate::termwindow::ui::right_sidebar::{wrap_path_for_width, wrap_snippet_text_for_width};use crate::termwindow::{ContentViewId, TermWindow, TermWindowNotif};use crate::ui::{- draw_scrollbar, rect, wheel_delta_pixels, ControlState, DrawContext, InteractionState,+ draw_scrollbar, rect, wheel_delta_pixels, ButtonVariant, ControlState, DrawContext,+ InteractionState,ScrollState, UiContext, UiPalette, UiTokens, WidgetKind,};use std::path::PathBuf;@@ -493,18 +494,16 @@ impl ProjectRootView {primary: bool,) -> anyhow::Result<()> {self.widgets.push(area, WidgetKind::Button, action);- let state = self.button_state(action, primary);- let (mut bg, mut border) = state.colors(palette);- let mut text = palette.text;- if primary {- bg = if state == ControlState::Pressed {- palette.selected_bg.mul_alpha(0.82)- } else {- palette.selected_bg- };- border = palette.selected_bg;- text = palette.selected_text;- }+ let state = self.button_state(action);+ // Shared with every other button in the app, so "primary" means the+ // accent in both appearances rather than a grey that only reads as+ // primary in the light one.+ let variant = if primary {+ ButtonVariant::Primary+ } else {+ ButtonVariant::Secondary+ };+ let (bg, border, text) = variant.colors(state, palette);ctx.draw_rounded_frame(layers,0,@@ -533,13 +532,11 @@ impl ProjectRootView {Ok(())}- fn button_state(&self, action: ProjectRootAction, primary: bool) -> ControlState {+ fn button_state(&self, action: ProjectRootAction) -> ControlState {if self.interaction.pressed == Some(action) {ControlState::Pressed} else if self.interaction.hovered == Some(action) {ControlState::Hovered- } else if primary {- ControlState::Active} else {ControlState::Normal}diff --git a/wezterm-gui/src/termwindow/remote_thread_view.rs b/wezterm-gui/src/termwindow/remote_thread_view.rsindex dd1943fc..2258a1cd 100644--- a/wezterm-gui/src/termwindow/remote_thread_view.rs+++ b/wezterm-gui/src/termwindow/remote_thread_view.rs@@ -4,7 +4,8 @@ use crate::termwindow::content_view::{ContentView, ContentViewResponse, RemoteCouse crate::termwindow::ui::icons::SvgIcon;use crate::termwindow::TermWindow;use crate::ui::{- draw_scrollbar, rect, wheel_delta_pixels, ControlState, DrawContext, InteractionState,+ draw_scrollbar, rect, wheel_delta_pixels, ButtonVariant, ControlState, DrawContext,+ InteractionState,ScrollState, UiContext, UiPalette, UiTokens, WidgetKind,};use crate::workspace_threads::{self, ThreadConnectionState};@@ -20,8 +21,7 @@ const SPINNER_FRAMES: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "const CONTENT_MAX_W: f32 = 860.0;const PAD: f32 = 48.0;-const CARD_RADIUS: f32 = 18.0;-const BUTTON_RADIUS: f32 = 14.0;+const CARD_RADIUS: f32 = 24.0;const BUTTON_MIN_H: f32 = 52.0;const HERO_ICON_SIZE: f32 = 64.0;pub(crate) const REMOTE_THREAD_CONTENT_VIEW_KEY_PREFIX: &str = "remote-thread:";@@ -498,21 +498,16 @@ impl RemoteThreadView {enabled: bool,) -> anyhow::Result<()> {self.widgets.push(area, WidgetKind::Button, action);- let state = self.button_state(action, primary, enabled);- let (mut bg, mut border) = state.colors(palette);- let mut text = palette.text;- if primary && enabled {- bg = if state == ControlState::Pressed {- palette.selected_bg.mul_alpha(0.82)- } else {- palette.selected_bg- };- border = palette.selected_bg;- text = palette.selected_text;- } else if !enabled {- bg = bg.mul_alpha(0.52);- text = palette.muted_text;- }+ let state = self.button_state(action, enabled);+ // Shared with every other button in the app, so "primary" means the+ // accent in both appearances, and disabled dims consistently instead+ // of by a local rule.+ let variant = if primary {+ ButtonVariant::Primary+ } else {+ ButtonVariant::Secondary+ };+ let (bg, _border, text) = variant.colors(state, palette);ctx.draw_rounded_frame(layers,0,@@ -521,8 +516,17 @@ impl RemoteThreadView {area.size.width,area.size.height,bg,- border,- ctx.px(BUTTON_RADIUS),+ // No outline. The fill already separates these from the page, and+ // the stroked ring is drawn as its own curve rather than following+ // the fill: at pill radius its corner arc runs almost horizontally+ // where it meets the top edge, so the antialiasing smears sideways+ // and the end reads as a rounded rectangle. Passing the fill as the+ // border makes draw_rounded_frame skip the ring entirely.+ bg,+ // Fully rounded, like every other button in the app. Derived from+ // the rect instead of a constant so it cannot fall out of step+ // when the button height changes.+ area.size.height / 2.0,)?;let icon_size = ctx.px(22.0);let icon_x = area.origin.x + ctx.px(18.0);@@ -597,20 +601,13 @@ impl RemoteThreadView {}}- fn button_state(- &self,- action: RemoteThreadAction,- primary: bool,- enabled: bool,- ) -> ControlState {+ fn button_state(&self, action: RemoteThreadAction, enabled: bool) -> ControlState {if !enabled {ControlState::Disabled} else if self.interaction.pressed == Some(action) {ControlState::Pressed} else if self.interaction.hovered == Some(action) {ControlState::Hovered- } else if primary {- ControlState::Active} else {ControlState::Normal}diff --git a/wezterm-gui/src/termwindow/ui/icons.rs b/wezterm-gui/src/termwindow/ui/icons.rsindex afc8b008..1b530424 100644--- a/wezterm-gui/src/termwindow/ui/icons.rs+++ b/wezterm-gui/src/termwindow/ui/icons.rs@@ -20,8 +20,11 @@ pub enum SvgIcon {CodeXml,ClipboardPaste,Copy,+ Download,Ellipsis,Expand,+ Eye,+ EyeOff,ExternalLink,File,FileCode,@@ -53,17 +56,21 @@ pub enum SvgIcon {PanelLeftOpen,PanelRightClose,PanelRightOpen,+ Package,Pencil,Pin,PinOff,Plus,RotateCcw,+ RefreshCw,Redo,Save,+ Scale,Scissors,Search,Server,Settings,+ Shield,SlidersHorizontal,SlidersVertical,Shrink,@@ -129,8 +136,13 @@ impl SvgIcon {include_bytes!("../../../../third_party/lucide/icons/clipboard-paste.svg")}Self::Copy => include_bytes!("../../../../third_party/lucide/icons/copy.svg"),+ Self::Download => {+ include_bytes!("../../../../third_party/lucide/icons/download.svg")+ }Self::Ellipsis => include_bytes!("../../../../third_party/lucide/icons/ellipsis.svg"),Self::Expand => include_bytes!("../../../../third_party/lucide/icons/expand.svg"),+ Self::Eye => include_bytes!("../../../../third_party/lucide/icons/eye.svg"),+ Self::EyeOff => include_bytes!("../../../../third_party/lucide/icons/eye-off.svg"),Self::ExternalLink => {include_bytes!("../../../../third_party/lucide/icons/external-link.svg")}@@ -201,6 +213,7 @@ impl SvgIcon {include_bytes!("../../../../third_party/lucide/icons/panel-right-open.svg")}Self::Pencil => include_bytes!("../../../../third_party/lucide/icons/pencil.svg"),+ Self::Package => include_bytes!("../../../../third_party/lucide/icons/package.svg"),Self::Pin => include_bytes!("../../../../third_party/lucide/icons/pin.svg"),Self::PinOff => include_bytes!("../../../../third_party/lucide/icons/pin-off.svg"),Self::Unlink2 => include_bytes!("../../../../third_party/lucide/icons/unlink-2.svg"),@@ -208,12 +221,17 @@ impl SvgIcon {Self::RotateCcw => {include_bytes!("../../../../third_party/lucide/icons/rotate-ccw.svg")}+ Self::RefreshCw => {+ include_bytes!("../../../../third_party/lucide/icons/refresh-cw.svg")+ }Self::Redo => include_bytes!("../../../../third_party/lucide/icons/redo.svg"),Self::Save => include_bytes!("../../../../third_party/lucide/icons/save.svg"),+ Self::Scale => include_bytes!("../../../../third_party/lucide/icons/scale.svg"),Self::Scissors => include_bytes!("../../../../third_party/lucide/icons/scissors.svg"),Self::Search => include_bytes!("../../../../third_party/lucide/icons/search.svg"),Self::Server => include_bytes!("../../../../third_party/lucide/icons/server.svg"),Self::Settings => include_bytes!("../../../../third_party/lucide/icons/settings.svg"),+ Self::Shield => include_bytes!("../../../../third_party/lucide/icons/shield.svg"),Self::SlidersHorizontal => {include_bytes!("../../../../third_party/lucide/icons/sliders-horizontal.svg")}@@ -549,6 +567,31 @@ pub fn distro_to_icon(id: &str) -> Option<BrandIcon> {/// Shared SVG -> RGBA raster path used by both [`SvgIcon`] and [`BrandIcon`]./// The icon is scaled to fit and centered within a `size`×`size` pixmap.+/// The application icon, for the About page's hero.+///+/// The only raster asset in here. `image` hands back straight alpha while the+/// atlas stores premultiplied -- the multiply below is what stops the icon's+/// soft edges from ringing bright against a dark card.+pub fn rasterize_app_icon(size: usize) -> Result<Image> {+ let size = size.max(1);+ let decoded = image::load_from_memory(crate::termwindow::ICON_DATA)+ .context("decoding the application icon")?+ .resize_exact(+ size as u32,+ size as u32,+ image::imageops::FilterType::Lanczos3,+ )+ .into_rgba8();+ let mut data = decoded.into_raw();+ for pixel in data.chunks_exact_mut(4) {+ let alpha = pixel[3] as u32;+ for channel in &mut pixel[..3] {+ *channel = ((*channel as u32 * alpha + 127) / 255) as u8;+ }+ }+ Ok(Image::from_raw(size, size, data))+}+fn rasterize_svg_str(svg: &str, size: usize, degrees: f32) -> Result<Image> {let size = size.max(1);let tree = resvg::usvg::Tree::from_data(svg.as_bytes(), &resvg::usvg::Options::default())diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rsindex 0ca68ea2..dfc11985 100644--- a/wezterm-gui/src/termwindow/ui/sidebar.rs+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs@@ -50,6 +50,15 @@ const WORKSPACE_SECTION_LABEL_GAP: usize = 12;/// `workspace_sidebar_hidden_statuses` cannot be cleared from the UI.const SHOW_SIDEBAR_VIEW_OPTIONS: bool = false;+/// Diameter for every round sidebar action button, and the height of the+/// New Thread pill beside them. Also their corner radius, since they are all+/// fully rounded.+///+/// 58 is the ceiling: the per-section buttons are additionally clamped to+/// `session_row_height - 8`, so anything larger makes them stop matching the+/// notification button. Raising it past 58 means raising+/// `SESSION_ROW_MIN_HEIGHT` too.+const TOP_ACTION_MAX_HEIGHT: usize = 58;const SESSION_ROW_MIN_HEIGHT: usize = 66;const SESSION_ROW_SIDE_PADDING: usize = 10;const SESSION_ACTION_MIN_SIZE: usize = 48;@@ -65,7 +74,6 @@ const NOTIFICATION_BADGE_COLOR: LinearRgba = LinearRgba::with_components(0.96, 0const NOTIFICATION_BADGE_PULSE_DURATION: Duration = Duration::from_millis(1800);const NOTIFICATION_BADGE_PULSE_COUNT: f32 = 3.0;const NOTIFICATION_BADGE_FRAME_MS: u64 = 33;-const SIDEBAR_SECTION_ACTION_SIZE: usize = 48;const SIDEBAR_SECTION_ACTION_ICON_INSET: usize = 6;/// Connection health of the active Space's mux client domain, as shown by@@ -783,7 +791,7 @@ impl crate::TermWindow {y += self.workspace_sidebar_toggle_visual_size() + self.ui_px(SIDEBAR_INSET);}let top_action_height = row_height- .min(self.ui_px(48))+ .min(self.ui_px(TOP_ACTION_MAX_HEIGHT)).max(ui_cell_height + self.ui_px(SIDEBAR_INSET))+ if sidebar_toolbar_uses_fullscreen_style {self.ui_px(WINDOW_TAB_FULLSCREEN_NEW_SESSION_EXTRA_HEIGHT)@@ -1270,8 +1278,14 @@ impl crate::TermWindow {if toggle_hovered { foreground } else { muted_fg },)?;}- let section_button_size = self- .ui_px(SIDEBAR_SECTION_ACTION_SIZE)+ // One diameter for every round sidebar action button. It follows the+ // notification button, which is pinned to the New Thread row's height+ // because the two sit side by side -- so tying the section buttons to+ // the same number is what keeps the whole right-hand column one size.+ // Still clamped to its own row: a section button must not outgrow the+ // row it sits in.+ let section_button_size = layout+ .top_action_height.max(button_size).min(session_row_height.saturating_sub(8));let active_project_id = view@@ -1490,7 +1504,7 @@ impl crate::TermWindow {notification_action_size,notification_action_size,);- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,1,euclid::rect(@@ -1499,15 +1513,12 @@ impl crate::TermWindow {top_action_width as f32,top_action_height as f32,),- if top_action_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS + 4.0),+ chrome,+ top_action_hovered,+ false,).context("sidebar add thread button")?;- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,1,euclid::rect(@@ -1516,12 +1527,9 @@ impl crate::TermWindow {notification_action_size as f32,notification_action_size as f32,),- if notification_action_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS + 4.0),+ chrome,+ notification_action_hovered,+ false,).context("sidebar notifications button")?;if let Some(project_id) = active_project_id.clone() {@@ -1878,7 +1886,7 @@ impl crate::TermWindow {button_x.saturating_sub(item_x + self.ui_px(SIDEBAR_INSET) * 2),muted_fg,)?;- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,1,euclid::rect(@@ -1887,12 +1895,9 @@ impl crate::TermWindow {section_button_size as f32,section_button_size as f32,),- if button_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS),+ chrome,+ button_hovered,+ false,).context("sidebar new project button")?;self.ui_items.push(UIItem {@@ -2078,7 +2083,7 @@ impl crate::TermWindow {project_action_size,project_action_size,);- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,1,euclid::rect(@@ -2087,12 +2092,9 @@ impl crate::TermWindow {project_action_size as f32,project_action_size as f32,),- if project_action_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS),+ chrome,+ project_action_hovered,+ false,).context("sidebar new thread button")?;self.ui_items.push(UIItem {@@ -2433,7 +2435,7 @@ impl crate::TermWindow {group_action_size,group_action_size,);- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,1,euclid::rect(@@ -2442,14 +2444,9 @@ impl crate::TermWindow {group_action_size as f32,group_action_size as f32,),- if group_action_hovered {- chrome.sidebar_button_hover_bg- } else if group.attached {- chrome.sidebar_button_bg- } else {- chrome.sidebar_button_bg.mul_alpha(0.4)- },- self.ui_f32(SIDEBAR_ROW_RADIUS),+ chrome,+ group_action_hovered,+ !group.attached,).context("sidebar ref group new thread button")?;if group.attached {@@ -2786,7 +2783,9 @@ impl crate::TermWindow {top_action_width,top_action_height,);- self.fill_rounded_rectangle(+ // The repaint over the scrolled list; it is what ends up visible,+ // so it has to use the same treatment as the layer-1 fill.+ self.paint_sidebar_action_button(layers,2,euclid::rect(@@ -2795,12 +2794,9 @@ impl crate::TermWindow {top_action_width as f32,top_action_height as f32,),- if top_action_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS + 4.0),+ chrome,+ top_action_hovered,+ false,).context("sidebar add thread button repaint")?;let notification_action_hovered = self.is_pointer_over_ui_rect(@@ -2809,7 +2805,7 @@ impl crate::TermWindow {notification_action_size,notification_action_size,);- self.fill_rounded_rectangle(+ self.paint_sidebar_action_button(layers,2,euclid::rect(@@ -2818,12 +2814,9 @@ impl crate::TermWindow {notification_action_size as f32,notification_action_size as f32,),- if notification_action_hovered {- chrome.sidebar_button_hover_bg- } else {- chrome.sidebar_button_bg- },- self.ui_f32(SIDEBAR_ROW_RADIUS + 4.0),+ chrome,+ notification_action_hovered,+ false,).context("sidebar notifications button repaint")?;let top_action_fg = if active_project_id.is_some() {@@ -3151,7 +3144,9 @@ impl crate::TermWindow {let ssh_icon_size = icon_size.min(settings_row_height.saturating_sub(8));self.paint_sidebar_icon(layers,- SvgIcon::Link2,+ // Same globe the Space menu's "Add Remote Host" uses; a+ // chain link never said "a machine somewhere else".+ SvgIcon::Globe,ssh_action_x + ((settings_action_size.saturating_sub(ssh_icon_size)) / 2),ssh_action_y + ((settings_action_size.saturating_sub(ssh_icon_size)) / 2),ssh_icon_size,@@ -3344,6 +3339,44 @@ impl crate::TermWindow {.is_some_and(|until| until > std::time::Instant::now())}+ /// A sidebar action button: circle or pill, with the same shadow and+ /// hairline border a selected sidebar row gets.+ ///+ /// Four call sites paint these (New Thread and the bell, each of which is+ /// also repainted on a higher layer over the scrolled list, plus the+ /// per-section add buttons), and they used to carry the radius and the+ /// fill separately. Keeping the treatment in one place is what stops one+ /// of them from staying a rounded square when the others become pills.+ pub(crate) fn paint_sidebar_action_button(+ &self,+ layers: &mut TripleLayerQuadAllocator,+ layer_num: usize,+ rect: RectF,+ chrome: UiPalette,+ hovered: bool,+ // `dimmed` is a button whose action is unavailable right now -- a+ // detached ref group's add button. It keeps its shape and place so+ // the column stays even, and fades instead of disappearing.+ dimmed: bool,+ ) -> anyhow::Result<()> {+ let radius = rect.height().min(rect.width()) / 2.0;+ let fade = if dimmed { 0.4 } else { 1.0 };+ self.paint_active_surface_shadow(layers, layer_num, rect, radius)?;+ self.fill_rounded_rectangle_with_border(+ layers,+ layer_num,+ rect,+ if hovered {+ chrome.sidebar_button_hover_bg+ } else {+ chrome.sidebar_button_bg.mul_alpha(fade)+ },+ chrome.sidebar_row_active_border.mul_alpha(fade),+ radius,+ CAPSULE_BORDER_WIDTH,+ )+ }+pub(crate) fn fill_rounded_rectangle(&self,layers: &mut TripleLayerQuadAllocator,diff --git a/wezterm-gui/src/ui/draw.rs b/wezterm-gui/src/ui/draw.rsindex 98f1076f..aac1dce1 100644--- a/wezterm-gui/src/ui/draw.rs+++ b/wezterm-gui/src/ui/draw.rs@@ -22,6 +22,7 @@ use crate::termwindow::render::corners::{TOP_RIGHT_ROUNDED_CORNER_MASK, TOP_RIGHT_ROUNDED_CORNER_OUTLINE,};use crate::termwindow::ui::icons::{BrandIcon, SvgIcon};+use crate::ui::{UiPalette, UiTokens};use crate::utilsprites::RenderMetrics;use std::rc::Rc;use wezterm_bidi::Direction;@@ -49,6 +50,23 @@ impl<'a> DrawContext<'a> {}}+ /// The same surface measured with another font's metrics.+ ///+ /// Text lands on the baseline of whichever metrics the *context* carries,+ /// not the font passed to `draw_text` -- so a heading drawn in a larger+ /// font through the body context sits on the body baseline and looks+ /// misaligned. Re-borrow with the heading's metrics instead.+ pub(crate) fn with_metrics<'m>(&self, metrics: &'m RenderMetrics) -> DrawContext<'m>+ where+ 'a: 'm,+ {+ DrawContext {+ render_state: self.render_state,+ dimensions: self.dimensions,+ metrics,+ }+ }+/// Design pixels (2x macOS backing) → this window's backing pixels.pub(crate) fn px(&self, value: f32) -> f32 {crate::ui::scale_ui_f32(value, self.dimensions.dpi)@@ -402,6 +420,29 @@ impl<'a> DrawContext<'a> {Ok(())}+ /// A grouped card: the translucent surface a panel's contents sit on.+ /// One call, so every page groups things the same way.+ pub(crate) fn draw_card(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ rect: RectF,+ palette: UiPalette,+ tokens: UiTokens,+ ) -> anyhow::Result<()> {+ self.draw_rounded_frame(+ layers,+ layer_num,+ rect.origin.x,+ rect.origin.y,+ rect.size.width,+ rect.size.height,+ palette.card_bg,+ palette.separator,+ tokens.card_radius,+ )+ }+pub(crate) fn draw_rounded_frame(&self,layers: &mut TripleLayerQuadAllocator<'_>,@@ -414,18 +455,9 @@ impl<'a> DrawContext<'a> {border: LinearRgba,radius: f32,) -> anyhow::Result<()> {- self.draw_rounded_rect(layers, layer_num, x, y, width, height, border, radius)?;- self.draw_rounded_rect(- layers,- layer_num,- x + 1.0,- y + 1.0,- width - 2.0,- height - 2.0,- fill,- (radius - 1.0).max(0.0),- )?;- Ok(())+ draw_rounded_frame(+ self, layers, layer_num, x, y, width, height, fill, border, radius,+ )}pub(crate) fn draw_corner(@@ -692,3 +724,163 @@ impl<'a> DrawContext<'a> {fn color_with_alpha(color: LinearRgba, alpha: f32) -> LinearRgba {LinearRgba(color.0, color.1, color.2, alpha.clamp(0.0, 1.0))}++/// The primitives [`draw_rounded_frame`] is built from. Two painters supply+/// them and cannot share a draw path -- [`DrawContext`] for the in-window+/// pages, the settings window for its own -- so they share the frame's+/// geometry through this instead of keeping a copy of it each. The names are+/// deliberately not the painters' own, so that implementing this cannot+/// shadow the inherent methods it forwards to.+pub(crate) trait RoundedFramePainter {+ fn frame_rounded_rect(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ width: f32,+ height: f32,+ color: LinearRgba,+ radius: f32,+ ) -> anyhow::Result<()>;++ fn frame_rect(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ width: f32,+ height: f32,+ color: LinearRgba,+ ) -> anyhow::Result<()>;++ fn frame_corner(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ polys: &'static [Poly],+ size: euclid::Size2D<f32, window::PixelUnit>,+ color: LinearRgba,+ ) -> anyhow::Result<()>;+}++/// A filled rounded rect with a one-pixel ring on its edge.+///+/// Fill first, then the ring. This used to paint the border across the whole+/// rect and cover it with the fill inset by a pixel, which only works when+/// the fill is opaque. Every translucent one -- a card at 0.78 alpha, a+/// control at 0.98 -- let the border colour through across the entire+/// interior, so selecting a card tinted the whole card with the accent+/// instead of just outlining it.+///+/// A border the same colour as the fill is not a border: stroking it anyway+/// draws the antialiased edge twice, which hardens the outline into a visible+/// ring around a filled button and chews the corners of a pill. Passing the+/// fill as the border is how a caller asks for no ring at all.+pub(crate) fn draw_rounded_frame(+ painter: &impl RoundedFramePainter,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ width: f32,+ height: f32,+ fill: LinearRgba,+ border: LinearRgba,+ radius: f32,+) -> anyhow::Result<()> {+ if width <= 0.0 || height <= 0.0 {+ return Ok(());+ }+ if fill.3 > 0.0 {+ painter.frame_rounded_rect(layers, layer_num, x, y, width, height, fill, radius)?;+ }+ if border.3 <= 0.0 || border == fill {+ return Ok(());+ }+ let radius = radius.min(width / 2.0).min(height / 2.0).round().max(0.0);+ const STROKE: f32 = 1.0;+ if radius > 0.0 {+ let size = euclid::size2(radius, radius);+ for (cx, cy, poly) in [+ (x, y, TOP_LEFT_ROUNDED_CORNER_OUTLINE),+ (x + width - radius, y, TOP_RIGHT_ROUNDED_CORNER_OUTLINE),+ (x, y + height - radius, BOTTOM_LEFT_ROUNDED_CORNER_OUTLINE),+ (+ x + width - radius,+ y + height - radius,+ BOTTOM_RIGHT_ROUNDED_CORNER_OUTLINE,+ ),+ ] {+ painter.frame_corner(layers, layer_num, cx, cy, poly, size, border)?;+ }+ }+ let straight_w = (width - radius * 2.0).max(0.0);+ let straight_h = (height - radius * 2.0).max(0.0);+ painter.frame_rect(layers, layer_num, x + radius, y, straight_w, STROKE, border)?;+ painter.frame_rect(+ layers,+ layer_num,+ x + radius,+ y + height - STROKE,+ straight_w,+ STROKE,+ border,+ )?;+ painter.frame_rect(layers, layer_num, x, y + radius, STROKE, straight_h, border)?;+ painter.frame_rect(+ layers,+ layer_num,+ x + width - STROKE,+ y + radius,+ STROKE,+ straight_h,+ border,+ )?;+ Ok(())+}++impl RoundedFramePainter for DrawContext<'_> {+ fn frame_rounded_rect(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ width: f32,+ height: f32,+ color: LinearRgba,+ radius: f32,+ ) -> anyhow::Result<()> {+ self.draw_rounded_rect(layers, layer_num, x, y, width, height, color, radius)+ }++ fn frame_rect(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ width: f32,+ height: f32,+ color: LinearRgba,+ ) -> anyhow::Result<()> {+ self.draw_rect(layers, layer_num, x, y, width, height, color)+ }++ fn frame_corner(+ &self,+ layers: &mut TripleLayerQuadAllocator<'_>,+ layer_num: usize,+ x: f32,+ y: f32,+ polys: &'static [Poly],+ size: euclid::Size2D<f32, window::PixelUnit>,+ color: LinearRgba,+ ) -> anyhow::Result<()> {+ self.draw_corner(layers, layer_num, x, y, polys, size, color)+ }+}diff --git a/wezterm-gui/src/ui/geometry.rs b/wezterm-gui/src/ui/geometry.rsindex becaa37b..6fc95d6e 100644--- a/wezterm-gui/src/ui/geometry.rs+++ b/wezterm-gui/src/ui/geometry.rs@@ -18,3 +18,347 @@ pub(crate) fn contains(rect: window::RectF, x: f32, y: f32) -> bool {pub(crate) fn clamp(value: f32, min: f32, max: f32) -> f32 {value.max(min).min(max)}++/// Layout of a grid of equal-sized cards: how many columns fit, how many rows+/// that makes, and the size of one card.+///+/// The whole grid is width-driven -- pick the columns from the available+/// width, and every other number falls out. That is what lets one page reflow+/// from one column to five without a breakpoint table.+#[derive(Clone, Copy, Debug, PartialEq)]+pub(crate) struct CardGrid {+ pub columns: usize,+ pub rows: usize,+ pub card_width: f32,+ pub card_height: f32,+}++impl CardGrid {+ pub(crate) const EMPTY: Self = Self {+ columns: 0,+ rows: 0,+ card_width: 0.0,+ card_height: 0.0,+ };++ /// Total height of the laid-out rows, gaps included.+ pub(crate) fn height(self, gap: f32) -> f32 {+ if self.rows == 0 {+ 0.0+ } else {+ self.rows as f32 * self.card_height + self.rows.saturating_sub(1) as f32 * gap+ }+ }+}++/// How many cards of at least `minimum` width fit across `width`.+pub(crate) fn grid_columns(width: f32, minimum: f32, gap: f32, maximum: usize) -> usize {+ if maximum == 0 {+ return 0;+ }+ if maximum == 1 || width <= minimum {+ 1+ } else {+ (((width + gap) / (minimum + gap)).floor() as usize).clamp(1, maximum)+ }+}++/// Groups whose last row would hold exactly one card. A lone card under a full+/// row reads as a mistake, so callers trade a column away to avoid several of+/// them at once.+pub(crate) fn single_orphan_group_count(counts: &[usize], columns: usize) -> usize {+ if columns == 0 {+ return 0;+ }+ counts+ .iter()+ .filter(|&&count| count > columns && count % columns == 1)+ .count()+}++/// One column count for every group on the page, so groups line up with each+/// other. Drops a column when doing so leaves fewer orphaned last rows and the+/// cards are narrow enough that the extra width is welcome anyway.+pub(crate) fn shared_grid_columns(+ counts: &[usize],+ content_width: f32,+ maximum_columns: usize,+ minimum: f32,+ orphan_comfort_width: f32,+ gap: f32,+) -> usize {+ // Never lay out more columns than the fullest group can fill. A column+ // nothing is ever placed in is not a layout, it is width taken away from+ // the cards that do exist -- which is how three hosts on a wide page end+ // up squeezed to the minimum width with their names truncated and half+ // the page empty beside them.+ let fullest = counts.iter().copied().max().unwrap_or(0).max(1);+ let mut columns = grid_columns(content_width, minimum, gap, maximum_columns).min(fullest);+ if columns == 0 {+ return 0;+ }+ let initial_available =+ (content_width - gap * columns.saturating_sub(1) as f32) / columns as f32;+ if columns > 2 && initial_available < orphan_comfort_width {+ let reduced_columns = columns - 1;+ if single_orphan_group_count(counts, reduced_columns)+ < single_orphan_group_count(counts, columns)+ {+ columns = reduced_columns;+ }+ }+ columns+}++/// Width of one card once `columns` of them share `content_width`, capped so a+/// nearly-empty page does not stretch two cards across a 5K display.+pub(crate) fn grid_card_width(+ content_width: f32,+ columns: usize,+ maximum: f32,+ gap: f32,+) -> f32 {+ if columns == 0 {+ return 0.0;+ }+ let available = (content_width - gap * columns.saturating_sub(1) as f32) / columns as f32;+ available.min(maximum).max(1.0)+}++/// A grid of cards whose height the caller already knows. (Cards whose height+/// follows from their width -- a terminal preview, say -- compute it from+/// [`grid_card_width`] instead.)+pub(crate) fn card_grid(+ count: usize,+ content_width: f32,+ columns: usize,+ maximum_card_width: f32,+ gap: f32,+ card_height: f32,+) -> CardGrid {+ if columns == 0 {+ return CardGrid::EMPTY;+ }+ CardGrid {+ columns,+ rows: (count + columns - 1) / columns,+ card_width: grid_card_width(content_width, columns, maximum_card_width, gap),+ card_height,+ }+}++/// Where a row of cards begins when it does not fill the content width.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) enum RowAlign {+ /// Pin to the left margin. What a list wants: the reader's eye returns to+ /// the same column on every row, and a page with three hosts on it still+ /// starts where a page with thirty does.+ Start,+ /// Centre the row. What a gallery of big tiles wants, where a short last+ /// row hanging off one side reads as a mistake.+ Center,+ /// Pin to both margins: cards keep their width and the width left over+ /// once they hit their cap is shared out between them, so a full row+ /// always reaches the right edge.+ ///+ /// Only full rows are stretched. Spreading a two-card last row across the+ /// whole page -- which is what `space-between` does elsewhere -- puts a+ /// hole in the middle of the grid; the short row keeps the base gap and+ /// starts at the left margin, under the row above it.+ Justify,+}++/// Where card `index` of `count` sits, in the same space `cards_y` is in.+pub(crate) fn card_rect(+ index: usize,+ count: usize,+ grid: CardGrid,+ content_x: f32,+ content_width: f32,+ cards_y: f32,+ gap: f32,+ align: RowAlign,+) -> window::RectF {+ if grid.columns == 0 {+ return rect(content_x, cards_y, 0.0, 0.0);+ }+ let row = index / grid.columns;+ let column = index % grid.columns;+ let row_start = row * grid.columns;+ let row_count = (count - row_start).min(grid.columns);+ let (row_x, column_gap) = match align {+ RowAlign::Start => (content_x, gap),+ RowAlign::Center => {+ let row_width =+ row_count as f32 * grid.card_width + row_count.saturating_sub(1) as f32 * gap;+ (content_x + (content_width - row_width).max(0.0) / 2.0, gap)+ }+ RowAlign::Justify if row_count == grid.columns && grid.columns > 1 => {+ let used = grid.columns as f32 * grid.card_width;+ let spread = (content_width - used) / (grid.columns - 1) as f32;+ // Absorb a modest remainder only. When the cards are capped well+ // below the page -- three of them on a wide window -- sharing out+ // what is left would put half a card's width between neighbours,+ // which reads as a broken layout rather than a filled row. Past+ // double the base gap, leave the slack on the right instead.+ let spread = if spread <= gap * 2.0 {+ spread.max(gap)+ } else {+ gap+ };+ (content_x, spread)+ }+ RowAlign::Justify => (content_x, gap),+ };+ euclid::rect(+ row_x + column as f32 * (grid.card_width + column_gap),+ // Rows always step by the base gap: only the horizontal run has+ // leftover width to absorb.+ cards_y + row as f32 * (grid.card_height + gap),+ grid.card_width,+ grid.card_height,+ )+}++/// Any part of the band `[y, y + height)` inside the viewport.+pub(crate) fn row_visible(y: f32, height: f32, viewport: window::RectF) -> bool {+ y + height > viewport.min_y() && y < viewport.max_y()+}++/// The whole band inside the viewport.+pub(crate) fn row_fully_visible(y: f32, height: f32, viewport: window::RectF) -> bool {+ y >= viewport.min_y() && y + height <= viewport.max_y()+}++/// Visible, or close enough that it is worth keeping ready: one row of+/// overscan stops a scroll from revealing empty cards.+pub(crate) fn card_is_warm(rect: window::RectF, viewport: window::RectF, overscan: f32) -> bool {+ let warm_top = viewport.min_y() - overscan.max(0.0);+ let warm_bottom = viewport.max_y() + overscan.max(0.0);+ rect.max_y() > warm_top && rect.min_y() < warm_bottom+}++#[cfg(test)]+mod tests {+ use super::*;++ /// The whole point of the grid: more width means more columns, not wider+ /// cards past their cap and not a hole in the middle of the page.+ #[test]+ fn columns_follow_the_available_width() {+ let (min, gap) = (260.0, 14.0);+ assert_eq!(grid_columns(300.0, min, gap, 5), 1);+ assert_eq!(grid_columns(560.0, min, gap, 5), 2);+ assert_eq!(grid_columns(840.0, min, gap, 5), 3);+ // Never past the cap, however wide the window gets.+ assert_eq!(grid_columns(4000.0, min, gap, 5), 5);+ // A window narrower than one card still shows one.+ assert_eq!(grid_columns(10.0, min, gap, 5), 1);+ }++ /// Three cards in a page wide enough for five get three wide columns,+ /// not five narrow ones with two of them empty.+ #[test]+ fn columns_never_exceed_the_fullest_group() {+ let wide = 2000.0;+ assert_eq!(grid_columns(wide, 340.0, 18.0, 5), 5);+ assert_eq!(shared_grid_columns(&[3], wide, 5, 340.0, 400.0, 18.0), 3);+ // Groups still share one count, taken from the fullest of them, so+ // the two grids stay aligned with each other.+ assert_eq!(shared_grid_columns(&[3, 4], wide, 5, 340.0, 400.0, 18.0), 4);+ // Nothing to place: one column, and no panic on an empty page.+ assert_eq!(shared_grid_columns(&[], wide, 5, 340.0, 400.0, 18.0), 1);+ assert_eq!(shared_grid_columns(&[0, 0], wide, 5, 340.0, 400.0, 18.0), 1);+ }++ #[test]+ fn card_width_is_capped_but_never_negative() {+ assert_eq!(grid_card_width(800.0, 2, 380.0, 20.0), 380.0);+ assert_eq!(grid_card_width(500.0, 2, 380.0, 20.0), 240.0);+ assert_eq!(grid_card_width(0.0, 3, 380.0, 20.0), 1.0);+ assert_eq!(grid_card_width(800.0, 0, 380.0, 20.0), 0.0);+ }++ #[test]+ fn rows_round_up_and_measure_with_their_gaps() {+ let grid = card_grid(5, 800.0, 2, 380.0, 20.0, 80.0);+ assert_eq!(grid.columns, 2);+ assert_eq!(grid.rows, 3);+ assert_eq!(grid.height(20.0), 3.0 * 80.0 + 2.0 * 20.0);+ assert_eq!(card_grid(0, 800.0, 2, 380.0, 20.0, 80.0).rows, 0);+ assert_eq!(CardGrid::EMPTY.height(20.0), 0.0);+ }++ /// Every row is centred on the content width, so a last row that cannot+ /// fill it does not hang off to one side. (The full rows are centred too,+ /// which only shows once the cards hit their width cap.)+ #[test]+ fn a_short_last_row_is_centred() {+ let grid = card_grid(3, 800.0, 2, 380.0, 20.0, 80.0);+ assert_eq!(grid.card_width, 380.0, "capped below the available width");+ let full_row = card_rect(0, 3, grid, 0.0, 800.0, 0.0, 20.0, RowAlign::Center);+ let orphan = card_rect(2, 3, grid, 0.0, 800.0, 0.0, 20.0, RowAlign::Center);+ assert_eq!(full_row.origin.x, (800.0 - (380.0 * 2.0 + 20.0)) / 2.0);+ assert_eq!(orphan.origin.x, (800.0 - grid.card_width) / 2.0);+ assert_eq!(orphan.origin.y, grid.card_height + 20.0);+ // Left-aligned, every row starts at the margin regardless of length.+ for index in 0..3 {+ let card = card_rect(index, 3, grid, 40.0, 800.0, 0.0, 20.0, RowAlign::Start);+ assert_eq!(card.origin.x, 40.0 + (index % 2) as f32 * (380.0 + 20.0));+ }+ }++ /// Justified: a full row reaches both margins, and the short row under it+ /// keeps the base gap instead of being spread across the page.+ #[test]+ fn justify_stretches_full_rows_only() {+ let grid = card_grid(3, 800.0, 2, 380.0, 20.0, 80.0);+ let at = |index| card_rect(index, 3, grid, 0.0, 800.0, 0.0, 20.0, RowAlign::Justify).origin.x;+ assert_eq!(at(0), 0.0);+ // 800 - 2 * 380 = 40 of slack, all of it in the single gap.+ assert_eq!(at(1), 380.0 + 40.0);+ assert_eq!(at(1) + 380.0, 800.0, "full row reaches the right margin");+ // Last row: one card, base gap, left margin.+ assert_eq!(at(2), 0.0);+ }++ /// A remainder too large to share out is left on the right rather than+ /// blown into the gaps.+ #[test]+ fn justify_gives_up_when_the_slack_is_absurd() {+ // Three 560-wide cards on a 2900-wide page: 1220 left over, which+ // would be 610 between neighbours.+ let grid = card_grid(3, 2900.0, 3, 560.0, 18.0, 104.0);+ assert_eq!(grid.card_width, 560.0);+ let at = |index| {+ card_rect(index, 3, grid, 0.0, 2900.0, 0.0, 18.0, RowAlign::Justify)+ .origin+ .x+ };+ assert_eq!(at(1), 560.0 + 18.0, "base gap, not a stretched one");+ assert_eq!(at(2), (560.0 + 18.0) * 2.0);+ }++ /// When the cards are not capped there is nothing to share out, so a+ /// justified grid is indistinguishable from a left-aligned one.+ #[test]+ fn justify_is_inert_when_cards_already_fill_the_row() {+ let grid = card_grid(4, 800.0, 2, 10_000.0, 20.0, 80.0);+ for index in 0..4 {+ let justified = card_rect(index, 4, grid, 0.0, 800.0, 0.0, 20.0, RowAlign::Justify);+ let start = card_rect(index, 4, grid, 0.0, 800.0, 0.0, 20.0, RowAlign::Start);+ assert_eq!(justified, start);+ }+ }++ #[test]+ fn warmth_extends_one_overscan_past_the_viewport() {+ let viewport = rect(0.0, 100.0, 500.0, 200.0);+ let above = rect(0.0, 40.0, 100.0, 40.0);+ assert!(!card_is_warm(above, viewport, 0.0));+ assert!(card_is_warm(above, viewport, 80.0));+ assert!(row_visible(90.0, 20.0, viewport));+ assert!(!row_fully_visible(90.0, 20.0, viewport));+ assert!(row_fully_visible(120.0, 20.0, viewport));+ }+}diff --git a/wezterm-gui/src/ui/icons.rs b/wezterm-gui/src/ui/icons.rsindex d09c6d98..35ae056b 100644--- a/wezterm-gui/src/ui/icons.rs+++ b/wezterm-gui/src/ui/icons.rs@@ -4,6 +4,7 @@ pub(crate) use crate::termwindow::ui::icons::{BrandIcon, SvgIcon};pub(crate) enum SettingsIcon {General,Appearance,+ Sidebar,Terminal,Workspaces,Agents,@@ -12,6 +13,7 @@ pub(crate) enum SettingsIcon {Developer,UiKit,Memory,+ Update,About,Archived,CommandPalette,@@ -25,6 +27,7 @@ impl SettingsIcon {match self {Self::General => SvgIcon::SlidersHorizontal,Self::Appearance => SvgIcon::Palette,+ Self::Sidebar => SvgIcon::PanelRightOpen,Self::Terminal => SvgIcon::Terminal,Self::Workspaces => SvgIcon::FolderOpen,Self::Agents => SvgIcon::Bot,@@ -33,6 +36,7 @@ impl SettingsIcon {Self::Developer => SvgIcon::Settings,Self::UiKit => SvgIcon::SlidersVertical,Self::Memory => SvgIcon::MemoryStick,+ Self::Update => SvgIcon::RefreshCw,Self::About => SvgIcon::Info,Self::Archived => SvgIcon::Archive,Self::CommandPalette => SvgIcon::SquareTerminal,diff --git a/wezterm-gui/src/ui/primitives.rs b/wezterm-gui/src/ui/primitives.rsindex 9b7dff64..4cf8e9d3 100644--- a/wezterm-gui/src/ui/primitives.rs+++ b/wezterm-gui/src/ui/primitives.rs@@ -5,7 +5,6 @@ pub(crate) enum ControlState {Normal,Hovered,Pressed,- Active,Disabled,}@@ -17,13 +16,66 @@ impl ControlState {match self {Self::Normal => (palette.control_bg, palette.control_border),Self::Hovered => (palette.control_hover_bg, palette.separator),- Self::Pressed => (palette.control_pressed_bg, palette.selected_bg),- Self::Active => (palette.selected_bg, palette.selected_bg),+ Self::Pressed => (palette.control_pressed_bg, palette.accent),Self::Disabled => (palette.control_bg, palette.control_border),}}}+/// What a button *means*, which is what decides its colours. Kept apart from+/// [`ControlState`] because the two are orthogonal: a primary button still has+/// a hover and a pressed look.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub(crate) enum ButtonVariant {+ /// Neutral chrome. Anything that is not the one action a panel exists for.+ #[default]+ Secondary,+ /// The one action a panel exists for: filled with the accent.+ Primary,+}++impl ButtonVariant {+ /// `(background, border, label)`. The label colour is the part the shared+ /// widget used to get wrong: it painted every label in `palette.text`, so+ /// a filled button got near-black text on saturated blue.+ pub(crate) fn colors(+ self,+ state: ControlState,+ palette: UiPalette,+ ) -> (+ window::color::LinearRgba,+ window::color::LinearRgba,+ window::color::LinearRgba,+ ) {+ let label_for_neutral = match state {+ ControlState::Disabled => palette.muted_text,+ _ => palette.text,+ };+ match self {+ Self::Secondary => {+ let (bg, border) = state.colors(palette);+ (bg, border, label_for_neutral)+ }+ Self::Primary => {+ let fill = match state {+ // Both tints move the accent the same direction the+ // appearance expects: darker in light mode, lighter in+ // dark. Pressed and hovered share it -- on a filled+ // button the extra step is not legible anyway.+ ControlState::Hovered | ControlState::Pressed => palette.accent_hover,+ ControlState::Disabled => palette.accent.mul_alpha(0.45),+ _ => palette.accent,+ };+ let label = match state {+ ControlState::Disabled => palette.on_accent.mul_alpha(0.65),+ _ => palette.on_accent,+ };+ (fill, fill, label)+ }+ }+ }+}+#[derive(Debug, Clone, Copy)]pub(crate) struct ButtonSpec<'a, A: Copy> {pub label: &'a str,@@ -31,6 +83,7 @@ pub(crate) struct ButtonSpec<'a, A: Copy> {pub rect: window::RectF,pub state: ControlState,pub kind: WidgetKind,+ pub variant: ButtonVariant,}#[derive(Debug, Clone, Copy)]diff --git a/wezterm-gui/src/ui/state.rs b/wezterm-gui/src/ui/state.rsindex 2cc6385b..cf716a96 100644--- a/wezterm-gui/src/ui/state.rs+++ b/wezterm-gui/src/ui/state.rs@@ -45,6 +45,34 @@ impl<A: Copy> UiContext<A> {self.hits.push(HitTarget { rect, kind, action });}+ /// How many targets have been recorded so far. Paired with+ /// [`Self::clip_since`] to bracket a scrolling region.+ pub(crate) fn len(&self) -> usize {+ self.hits.len()+ }++ /// Bound every target pushed since `start` to `viewport`, dropping the+ /// ones that fall entirely outside it. A scrolling body drawn into its+ /// own allocator and replayed clipped has its *pixels* bounded; without+ /// this its widgets keep taking clicks where they are no longer drawn.+ pub(crate) fn clip_since(&mut self, start: usize, viewport: window::RectF) {+ let mut index = 0;+ self.hits.retain_mut(|target| {+ let position = index;+ index += 1;+ if position < start {+ return true;+ }+ match target.rect.intersection(&viewport) {+ Some(visible) => {+ target.rect = visible;+ true+ }+ None => false,+ }+ });+ }+pub(crate) fn hit_test(&self, x: f32, y: f32) -> Option<HitTarget<A>> {self.hits.iter()diff --git a/wezterm-gui/src/ui/tokens.rs b/wezterm-gui/src/ui/tokens.rsindex 650c495a..0db144d4 100644--- a/wezterm-gui/src/ui/tokens.rs+++ b/wezterm-gui/src/ui/tokens.rs@@ -14,10 +14,35 @@ pub(crate) struct UiPalette {pub control_border: LinearRgba,pub sidebar_button_bg: LinearRgba,pub sidebar_button_hover_bg: LinearRgba,+ /// The sidebar row ramp. These three are ordered on purpose --+ /// hover < pressed < active -- because a selected row is a state and the+ /// other two are momentary feedback; feedback that outweighs the state+ /// makes the row under the pointer look more current than the one that is.+ /// Write them as concrete colors, never as a white wash: a wash composites+ /// in linear space, so 7.5% white over the dark bar landed at rgb(80) and+ /// silently jumped the whole ramp.pub sidebar_row_hover_bg: LinearRgba,+ pub sidebar_row_pressed_bg: LinearRgba,pub sidebar_row_active_bg: LinearRgba,pub sidebar_row_active_border: LinearRgba,pub selected_bg: LinearRgba,+ /// The one saturated color in the chrome. Everything else is a neutral,+ /// so this is what a selected row, an active switch or a primary button+ /// uses to say "this one". Kept identical in shape across platforms --+ /// the whole UI is drawn from these tokens, so one edit moves every OS.+ pub accent: LinearRgba,+ pub accent_hover: LinearRgba,+ /// Text and glyphs sitting on top of `accent`.+ pub on_accent: LinearRgba,+ /// Irreversible actions. Used as a label/border tint rather than a fill,+ /// so a destructive button still reads as a button and not as an alert.+ pub danger: LinearRgba,+ /// The off half of a switch track. Distinct from `control_border`, which+ /// is a hairline colour and disappears when used as a filled track.+ pub track_off: LinearRgba,+ /// Fill for a grouped card floating on `window_bg`. Translucent on+ /// purpose: it picks up whatever the page paints behind it.+ pub card_bg: LinearRgba,pub text: LinearRgba,pub secondary_text: LinearRgba,pub muted_text: LinearRgba,@@ -42,9 +67,16 @@ impl UiPalette {sidebar_button_bg: rgba(255, 255, 255, 0.72),sidebar_button_hover_bg: rgba(255, 255, 255, 0.94),sidebar_row_hover_bg: rgba(60, 60, 67, 0.08),+ sidebar_row_pressed_bg: rgba(60, 60, 67, 0.16),sidebar_row_active_bg: rgba(255, 255, 255, 0.78),sidebar_row_active_border: rgba(60, 60, 67, 0.18),selected_bg: rgb(0, 122, 255),+ accent: rgb(0, 122, 255),+ accent_hover: rgb(0, 106, 224),+ on_accent: rgb(255, 255, 255),+ danger: rgb(215, 38, 61),+ track_off: rgba(220, 220, 226, 1.0),+ card_bg: rgba(255, 255, 255, 0.72),text: rgb(28, 28, 30),secondary_text: rgb(72, 72, 74),muted_text: rgb(142, 142, 147),@@ -64,10 +96,17 @@ impl UiPalette {control_border: rgba(118, 118, 128, 0.28),sidebar_button_bg: rgba(36, 36, 38, 0.94),sidebar_button_hover_bg: rgba(48, 48, 50, 0.98),- sidebar_row_hover_bg: rgba(255, 255, 255, 0.075),- sidebar_row_active_bg: rgba(48, 48, 50, 0.98),+ sidebar_row_hover_bg: rgba(42, 42, 44, 0.98),+ sidebar_row_pressed_bg: rgba(52, 52, 55, 0.98),+ sidebar_row_active_bg: rgba(62, 62, 65, 0.98),sidebar_row_active_border: rgba(118, 118, 128, 0.22),selected_bg: rgb(58, 58, 60),+ accent: rgb(10, 132, 255),+ accent_hover: rgb(50, 152, 255),+ on_accent: rgb(255, 255, 255),+ danger: rgb(255, 69, 58),+ track_off: rgba(78, 78, 82, 1.0),+ card_bg: rgba(30, 30, 32, 0.78),text: rgb(242, 242, 247),secondary_text: rgb(199, 199, 204),muted_text: rgb(142, 142, 147),@@ -89,6 +128,8 @@ pub(crate) struct UiTokens {pub row_gap: f32,pub control_height: f32,pub control_radius: f32,+ /// Grouped-card corner radius.+ pub card_radius: f32,pub row_radius: f32,pub icon_size: f32,pub resize_handle_width: f32,@@ -112,6 +153,7 @@ impl Default for UiTokens {row_gap: 8.0,control_height: 56.0,control_radius: 12.0,+ card_radius: 36.0,row_radius: 9.0,icon_size: 26.0,resize_handle_width: 24.0,@@ -140,6 +182,7 @@ impl UiTokens {row_gap: base.row_gap * scale,control_height: base.control_height * scale,control_radius: base.control_radius * scale,+ card_radius: base.card_radius * scale,row_radius: base.row_radius * scale,icon_size: base.icon_size * scale,resize_handle_width: base.resize_handle_width * scale,diff --git a/wezterm-gui/src/ui/widgets.rs b/wezterm-gui/src/ui/widgets.rsindex 1e64b0aa..1de2ef58 100644--- a/wezterm-gui/src/ui/widgets.rs+++ b/wezterm-gui/src/ui/widgets.rs@@ -22,10 +22,11 @@ use window::RectF;/// `ui::tokens::ui_scale_for_dpi`.////// Horizontal inset for a button label; the available text width is the button-/// width minus this on *both* sides. Callers size buttons as-/// `measure_text_width(label) + px(36)`, which leaves 8 design px of slack.-const BUTTON_TEXT_PAD: f32 = 14.0;-const BUTTON_RADIUS: f32 = 8.0;+/// width minus this on *both* sides. Callers must therefore size buttons as+/// `measure_text_width(label) + px(N)` with `N` at least twice this, or the+/// widget will ellipsize the label it was asked to show. `px(56)` is the+/// house size and leaves 16 design px of slack.+const BUTTON_TEXT_PAD: f32 = 20.0;const ICON_BUTTON_RADIUS: f32 = 8.0;/// Icon side length is derived from the (already DPI-aware) cell height, so/// only the padding and the clamp bounds are design pixels.@@ -54,8 +55,8 @@ pub(crate) fn button_label_width(button_width: f32, scale: f32) -> f32 {button_width - BUTTON_TEXT_PAD * 2.0 * scale}-/// A filled, rounded button with a centered-left label. The caller fills-/// `spec.state` (e.g. from its [`InteractionState`]).+/// A filled pill button with a centred label. The caller fills `spec.state`+/// (e.g. from its [`InteractionState`]) and `spec.variant`.pub(crate) fn draw_button<A: Copy + PartialEq>(ctx: &DrawContext,layers: &mut TripleLayerQuadAllocator<'_>,@@ -96,7 +97,7 @@ fn draw_button_with_layers<A: Copy + PartialEq>(text_layer: usize,) -> anyhow::Result<()> {widgets.push(spec.rect, spec.kind, spec.action);- let (background, border) = spec.state.colors(palette);+ let (background, border, label_color) = spec.variant.colors(spec.state, palette);ctx.draw_rounded_frame(layers,background_layer,@@ -106,17 +107,26 @@ fn draw_button_with_layers<A: Copy + PartialEq>(spec.rect.size.height,background,border,- ctx.px(BUTTON_RADIUS),+ // A pill rather than a rounded rectangle: at a glance that is what+ // separates a button from the text field sitting next to it.+ spec.rect.size.height / 2.0,)?;+ // Centre the label. It used to be pinned to the left inset, which reads as+ // a layout bug on any button wider than its text -- most obviously on the+ // equal-width buttons of a confirmation dialog.+ let available = button_label_width(spec.rect.size.width, ctx.scale());+ let measured = ctx.measure_text_width(font, spec.label).min(available);+ let text_x =+ spec.rect.origin.x + ((spec.rect.size.width - measured) / 2.0).max(ctx.px(BUTTON_TEXT_PAD));ctx.draw_text_on_layer(layers,text_layer,font,- spec.rect.origin.x + ctx.px(BUTTON_TEXT_PAD),+ text_x,control_text_y(ctx, spec.rect.origin.y, spec.rect.size.height),spec.label,- palette.text,- button_label_width(spec.rect.size.width, ctx.scale()),+ label_color,+ available,)?;Ok(())}@@ -289,10 +299,79 @@ pub(crate) fn draw_text_input<A: Copy + PartialEq>(cursor_on: bool,spec: TextInputSpec<'_, A>,caret: Option<InputCaret>,+) -> anyhow::Result<()> {+ draw_text_input_with_layers(+ ctx,+ layers,+ font,+ widgets,+ interaction,+ palette,+ tokens,+ text_pad,+ cursor_on,+ spec,+ caret,+ 0,+ 1,+ )+}++/// The same field drawn entirely on one layer. A field that sits in a fixed+/// header has scrolled content passing beneath it, and the mask that hides+/// that content covers every layer -- so the field has to be painted above+/// the mask, not merely after it.+#[allow(clippy::too_many_arguments)]+pub(crate) fn draw_text_input_on_layer<A: Copy + PartialEq>(+ ctx: &DrawContext,+ layers: &mut TripleLayerQuadAllocator<'_>,+ font: &Rc<LoadedFont>,+ widgets: &mut UiContext<A>,+ interaction: &InteractionState<A>,+ palette: UiPalette,+ tokens: UiTokens,+ text_pad: f32,+ cursor_on: bool,+ spec: TextInputSpec<'_, A>,+ caret: Option<InputCaret>,+ layer_num: usize,+) -> anyhow::Result<()> {+ draw_text_input_with_layers(+ ctx,+ layers,+ font,+ widgets,+ interaction,+ palette,+ tokens,+ text_pad,+ cursor_on,+ spec,+ caret,+ layer_num,+ layer_num,+ )+}++#[allow(clippy::too_many_arguments)]+fn draw_text_input_with_layers<A: Copy + PartialEq>(+ ctx: &DrawContext,+ layers: &mut TripleLayerQuadAllocator<'_>,+ font: &Rc<LoadedFont>,+ widgets: &mut UiContext<A>,+ interaction: &InteractionState<A>,+ palette: UiPalette,+ tokens: UiTokens,+ text_pad: f32,+ cursor_on: bool,+ spec: TextInputSpec<'_, A>,+ caret: Option<InputCaret>,+ frame_layer: usize,+ text_layer: usize,) -> anyhow::Result<()> {widgets.push(spec.rect, WidgetKind::TextInput, spec.action);let border = if spec.focused {- palette.selected_bg+ palette.accent} else if interaction.hovered == Some(spec.action) {palette.separator} else {@@ -300,7 +379,7 @@ pub(crate) fn draw_text_input<A: Copy + PartialEq>(};ctx.draw_rounded_frame(layers,- 0,+ frame_layer,spec.rect.origin.x,spec.rect.origin.y,spec.rect.size.width,@@ -310,12 +389,15 @@ pub(crate) fn draw_text_input<A: Copy + PartialEq>(tokens.control_radius,)?;- let text = if spec.text.is_empty() && !spec.focused {+ // An empty field keeps its placeholder while focused. Hiding it left a+ // blank slab with a caret in it, which says nothing about what belongs+ // there -- and the field this page focuses on open is the search box.+ let text = if spec.text.is_empty() {spec.placeholder} else {spec.text};- let color = if spec.text.is_empty() && !spec.focused {+ let color = if spec.text.is_empty() {palette.muted_text} else {palette.text@@ -343,18 +425,19 @@ pub(crate) fn draw_text_input<A: Copy + PartialEq>(let end_x = text_width_to_char(ctx, font, spec.text, end).min(text_area);ctx.draw_rounded_rect(layers,- 1,+ text_layer,text_left + start_x - bleed_x,highlight_y,(end_x - start_x) + bleed_x * 2.0,highlight_h,- palette.selected_bg.mul_alpha(0.56),+ palette.accent.mul_alpha(0.56),highlight_radius,)?;}}- ctx.draw_text(+ ctx.draw_text_on_layer(layers,+ text_layer,font,text_left,control_text_y(ctx, spec.rect.origin.y, spec.rect.size.height),@@ -372,22 +455,25 @@ pub(crate) fn draw_text_input<A: Copy + PartialEq>(let caret_width = ctx.px(CARET_WIDTH);ctx.draw_rect(layers,- 1,+ text_layer,text_left + caret_dx.min(text_area) - caret_width / 3.0,highlight_y,caret_width,highlight_h,- palette.selected_bg,+ palette.accent,)?;}Ok(())}-/// A pill toggle (iOS-style). `on` selects accent vs muted track + knob side.+/// A pill switch. The on track is the accent; the off track is a filled+/// neutral, not `control_border` -- a hairline colour used as a fill left the+/// two states nearly identical in the dark palette.pub(crate) fn draw_toggle<A: Copy + PartialEq>(ctx: &DrawContext,layers: &mut TripleLayerQuadAllocator<'_>,widgets: &mut UiContext<A>,+ interaction: &InteractionState<A>,palette: UiPalette,rect: RectF,on: bool,@@ -395,11 +481,9 @@ pub(crate) fn draw_toggle<A: Copy + PartialEq>() -> anyhow::Result<()> {widgets.push(rect, WidgetKind::Button, action);let h = rect.size.height;- let track = if on {- palette.selected_bg- } else {- palette.control_border- };+ let pressed = interaction.pressed == Some(action);+ let hovered = interaction.hovered == Some(action);+ let track = toggle_track_color(palette, on, hovered, pressed);ctx.draw_rounded_rect(layers,0,@@ -424,12 +508,37 @@ pub(crate) fn draw_toggle<A: Copy + PartialEq>(rect.origin.y + inset,knob,knob,- LinearRgba::with_components(1.0, 1.0, 1.0, 1.0),+ palette.on_accent,knob / 2.0,)?;Ok(())}+/// The track colour of a switch in every state. The settings window paints+/// its own switch -- it has no `DrawContext`, so it cannot call+/// [`draw_toggle`] -- and this is the part the two must agree on, so it lives+/// here rather than being written twice.+pub(crate) fn toggle_track_color(+ palette: UiPalette,+ on: bool,+ hovered: bool,+ pressed: bool,+) -> LinearRgba {+ if on {+ if pressed || hovered {+ palette.accent_hover+ } else {+ palette.accent+ }+ } else if pressed {+ palette.track_off.mul_alpha(0.8)+ } else if hovered {+ palette.track_off.mul_alpha(0.9)+ } else {+ palette.track_off+ }+}+/// A vertical scrollbar thumb within `area` (no track), matching the settings/// window's look.pub(crate) fn draw_scrollbar(@@ -477,13 +586,13 @@ pub(crate) fn draw_scrollbar_on_layer(mod tests {use super::{button_label_width, BUTTON_TEXT_PAD};- /// Callers size buttons as `measure_text_width(label) + px(36)`. The label+ /// Callers size buttons as `measure_text_width(label) + px(56)`. The label/// must still fit after the widget subtracts its own insets, at *every*/// scale — mixing a scaled width with unscaled insets is what truncated/// "Save & Open" into "Save & O..." on 96dpi displays.#[test]fn label_always_fits_the_button_the_caller_sized() {- const CALLER_PAD: f32 = 36.0;+ const CALLER_PAD: f32 = 56.0;for scale in [0.25, 0.5, 0.75, 1.0, 2.0] {for measured in [0.0, 12.5, 61.0, 168.0] {let button_width = measured + CALLER_PAD * scale;@@ -501,8 +610,8 @@ mod tests {#[test]fn insets_are_symmetric() {- // 8 design px of slack at scale 1.0, matching the settings window's- // own 44/36 pairing.+ // The inset comes off both sides and scales with the button, which+ // is what leaves the house size its 16 design px of slack.assert_eq!(button_label_width(100.0, 1.0),100.0 - BUTTON_TEXT_PAD * 2.0