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
feat(gui): draw tab icons and settings tiles with one lit-tile painter
RoversX37c99cbac4dc
diff --git a/wezterm-gui/src/tab_icons.rs b/wezterm-gui/src/tab_icons.rsindex 4eb7a9ac..ece1223a 100644--- a/wezterm-gui/src/tab_icons.rs+++ b/wezterm-gui/src/tab_icons.rs@@ -14,6 +14,7 @@use crate::native_settings::{self, NativeTabIconCard, NativeTabIconSettings};use crate::quad::{QuadTrait, TripleLayerQuadAllocator, TripleLayerQuadAllocatorTrait};use crate::ui::draw::DrawContext;+use crate::ui::tile::{draw_tile, TileStyle};use anyhow::{anyhow, bail, Context, Result};use mux::pane::Pane;use std::cell::RefCell;@@ -187,18 +188,6 @@ impl Rgb {LinearRgba::with_srgba(self.0, self.1, self.2, 255)}- /// This colour taken `amount` of the way to `other`, blended in sRGB the- /// way a designer's tool blends.- pub(crate) fn mix(self, other: Self, amount: f32) -> Self {- let channel =- |from: u8, to: u8| (from as f32 + (to as f32 - from as f32) * amount).round() as u8;- Self(- channel(self.0, other.0),- channel(self.1, other.1),- channel(self.2, other.2),- )- }-/// Perceived brightness, 0..=255.fn luma(self) -> f32 {0.2126 * self.0 as f32 + 0.7152 * self.1 as f32 + 0.0722 * self.2 as f32@@ -216,7 +205,6 @@ impl Rgb {}const WHITE: Rgb = Rgb(0xFF, 0xFF, 0xFF);-const BLACK: Rgb = Rgb(0x00, 0x00, 0x00);const INK: Rgb = Rgb(0x11, 0x11, 0x11);/// Brands whose own colour is black sit on a light circle instead: a black/// circle would sink into the dark chrome.@@ -1183,23 +1171,24 @@ fn remove_unreferenced_svgs(settings: &NativeTabIconSettings) {// Drawing, shared by the pane tabs and the settings page so both show the// same icon.-/// How the circle is lit: the fill lightens toward white at the top and-/// darkens toward black at the bottom, and the rim does the same more-/// strongly, so the edge reads as a bevel in the circle's own colour.-const FILL_TOP_LIGHTEN: f32 = 0.18;-const FILL_BOTTOM_DARKEN: f32 = 0.13;-const RIM_TOP_LIGHTEN: f32 = 0.42;-const RIM_BOTTOM_DARKEN: f32 = 0.25;-/// The rim against the diameter: one point on a 25pt tab icon.-const RIM_PER_DIAMETER: f32 = 1.0 / 25.0;-/// The shadow's softness and drop, in design pixels.-const SHADOW_SIGMA: f32 = 3.5;-const SHADOW_DROP: f32 = 2.5;--/// The circle a glyph sits on: a soft shadow in the circle's own hue, a-/// bevelled rim and a fill lit from above. `dark` is the chrome's-/// appearance: the same shadow shows far more on a light bar, so it is-/// fainter there.+/// How a tab icon's circle is lit: the fill lightens toward white at the+/// top and darkens toward black at the bottom, and the rim -- one point on+/// a 25pt icon -- does the same more strongly, so the edge reads as a bevel+/// in the circle's own colour. The shadow is in its hue too.+const PLATE: TileStyle = TileStyle {+ fill_top_lighten: 0.18,+ fill_bottom_darken: 0.13,+ rim_top_lighten: 0.42,+ rim_bottom_darken: 0.25,+ rim_per_side: 1.0 / 25.0,+ shadow_darken: 0.55,+ shadow_alpha_dark: 0.5,+ shadow_alpha_light: 0.32,+ shadow_sigma: 3.5,+ shadow_drop: 2.5,+};++/// The circle a glyph sits on. `dark` is the chrome's appearance.#[allow(clippy::too_many_arguments)]pub(crate) fn draw_plate(ctx: &DrawContext,@@ -1211,37 +1200,17 @@ pub(crate) fn draw_plate(circle: Rgb,dark: bool,) -> Result<()> {- let bounds = euclid::rect(x, y, diameter, diameter);- let shadow = circle- .mix(BLACK, 0.55)- .linear()- .mul_alpha(if dark { 0.5 } else { 0.32 });- ctx.draw_shadow(- layers,- layer,- bounds,- diameter / 2.0,- ctx.px(SHADOW_SIGMA),- ctx.px(SHADOW_DROP),- shadow,- )?;- ctx.draw_rounded_rect_vertical_gradient(+ draw_tile(+ ctx,layers,layer,- bounds,+ x,+ y,+ diameter,diameter / 2.0,- circle.mix(WHITE, RIM_TOP_LIGHTEN).linear(),- circle.mix(BLACK, RIM_BOTTOM_DARKEN).linear(),- )?;- let rim = (diameter * RIM_PER_DIAMETER).round().max(1.0);- let inner = (diameter - rim * 2.0).max(0.0);- ctx.draw_rounded_rect_vertical_gradient(- layers,- layer,- euclid::rect(x + rim, y + rim, inner, inner),- inner / 2.0,- circle.mix(WHITE, FILL_TOP_LIGHTEN).linear(),- circle.mix(BLACK, FILL_BOTTOM_DARKEN).linear(),+ circle.linear(),+ dark,+ &PLATE,)}@@ -1616,13 +1585,6 @@ mod tests {assert_eq!(found("").len(), catalog.cards.len());}- #[test]- fn colours_mix_in_srgb() {- assert_eq!(BLACK.mix(WHITE, 0.5), Rgb(0x80, 0x80, 0x80));- assert_eq!(Rgb(0x37, 0x76, 0xAB).mix(BLACK, 0.0), Rgb(0x37, 0x76, 0xAB));- assert_eq!(Rgb(0x37, 0x76, 0xAB).mix(WHITE, 1.0), WHITE);- }-#[test]fn colours_round_trip_through_the_settings_spelling() {assert_eq!(Rgb::parse("#3776ab"), Some(Rgb(0x37, 0x76, 0xAB)));diff --git a/wezterm-gui/src/ui/mod.rs b/wezterm-gui/src/ui/mod.rsindex 8b4e2e1f..8c1747dd 100644--- a/wezterm-gui/src/ui/mod.rs+++ b/wezterm-gui/src/ui/mod.rs@@ -9,6 +9,7 @@ pub(crate) mod keys;pub(crate) mod primitives;pub(crate) mod shadow;pub(crate) mod state;+pub(crate) mod tile;pub(crate) mod tokens;pub(crate) mod widgets;diff --git a/wezterm-gui/src/ui/tile.rs b/wezterm-gui/src/ui/tile.rsnew file mode 100644index 00000000..a61705f2--- /dev/null+++ b/wezterm-gui/src/ui/tile.rs@@ -0,0 +1,145 @@+//! Lit tiles: a coloured shape with its fill lit from above, a rim that+//! bevels its edge and a soft shadow under it. One painter for every icon+//! that sits on one -- the circles heading pane tabs, the rounded squares+//! heading settings rows -- so they are lit alike; a circle is a tile whose+//! corner radius is half its side.+//!+//! Nothing here is a texture of its own: the fill and rim are gradient quads+//! over the atlas's shared corner sprites, and the shadow is the atlas's+//! blurred silhouette for the tile's radius, so a page of tiles costs a few+//! quads each and no memory per tile.++use crate::quad::TripleLayerQuadAllocator;+use crate::ui::draw::DrawContext;+use window::color::{LinearRgba, SrgbaTuple};++/// How a tile is lit. Every amount is how far the tile's colour is blended+/// toward white (`lighten`) or black (`darken`), in sRGB, as a designer's+/// tool would.+pub(crate) struct TileStyle {+ pub fill_top_lighten: f32,+ pub fill_bottom_darken: f32,+ pub rim_top_lighten: f32,+ pub rim_bottom_darken: f32,+ /// The rim's width against the tile's side.+ pub rim_per_side: f32,+ /// The shadow's colour, as the tile's darkened this far (1 is black).+ pub shadow_darken: f32,+ /// Its peak opacity on dark chrome and on light, where the same shadow+ /// shows far more.+ pub shadow_alpha_dark: f32,+ pub shadow_alpha_light: f32,+ /// Its softness and how far it drops, in design pixels.+ pub shadow_sigma: f32,+ pub shadow_drop: f32,+}++/// Linear light to sRGB, one channel. Not `LinearRgba::to_srgb`: that one+/// switches to the power curve at 0.04045, the cut-off on the sRGB side+/// rather than the linear one (0.0031308), so a channel whose sRGB byte is+/// below about 57 comes back far too light.+fn to_srgb(linear: f32) -> f32 {+ if linear <= 0.0031308 {+ linear * 12.92+ } else {+ linear.powf(1.0 / 2.4) * 1.055 - 0.055+ }+}++/// `color` taken `amount` of the way to `target`, blended in sRGB.+fn blend(color: LinearRgba, target: f32, amount: f32) -> LinearRgba {+ let toward = |linear: f32| {+ let channel = to_srgb(linear);+ channel + (target - channel) * amount+ };+ SrgbaTuple(toward(color.0), toward(color.1), toward(color.2), color.3).to_linear()+}++pub(crate) fn lighten(color: LinearRgba, amount: f32) -> LinearRgba {+ blend(color, 1.0, amount)+}++pub(crate) fn darken(color: LinearRgba, amount: f32) -> LinearRgba {+ blend(color, 0.0, amount)+}++/// A tile `side` pixels square at `(x, y)` with corners of `radius`,+/// coloured `color` and lit by `style`. `dark` is the chrome's appearance.+#[allow(clippy::too_many_arguments)]+pub(crate) fn draw_tile(+ ctx: &DrawContext,+ layers: &mut TripleLayerQuadAllocator,+ layer: usize,+ x: f32,+ y: f32,+ side: f32,+ radius: f32,+ color: LinearRgba,+ dark: bool,+ style: &TileStyle,+) -> anyhow::Result<()> {+ let bounds = euclid::rect(x, y, side, side);+ let shadow_alpha = if dark {+ style.shadow_alpha_dark+ } else {+ style.shadow_alpha_light+ };+ ctx.draw_shadow(+ layers,+ layer,+ bounds,+ radius,+ ctx.px(style.shadow_sigma),+ ctx.px(style.shadow_drop),+ darken(color, style.shadow_darken).mul_alpha(shadow_alpha),+ )?;+ ctx.draw_rounded_rect_vertical_gradient(+ layers,+ layer,+ bounds,+ radius,+ lighten(color, style.rim_top_lighten),+ darken(color, style.rim_bottom_darken),+ )?;+ let rim = (side * style.rim_per_side).round().max(1.0);+ let inner = (side - rim * 2.0).max(0.0);+ ctx.draw_rounded_rect_vertical_gradient(+ layers,+ layer,+ euclid::rect(x + rim, y + rim, inner, inner),+ (radius - rim).max(0.0),+ lighten(color, style.fill_top_lighten),+ darken(color, style.fill_bottom_darken),+ )+}++#[cfg(test)]+mod tests {+ use super::*;++ fn srgb_bytes(color: LinearRgba) -> (u8, u8, u8) {+ let byte = |linear: f32| (to_srgb(linear) * 255.0).round() as u8;+ (byte(color.0), byte(color.1), byte(color.2))+ }++ #[test]+ fn blending_happens_in_srgb() {+ let grey = LinearRgba::with_srgba(0x80, 0x80, 0x80, 0xFF);+ // Halfway to white in sRGB is 0xC0, not what a linear blend gives.+ assert_eq!(srgb_bytes(lighten(grey, 0.5)), (0xC0, 0xC0, 0xC0));+ assert_eq!(srgb_bytes(darken(grey, 0.5)), (0x40, 0x40, 0x40));+ assert_eq!(srgb_bytes(lighten(grey, 0.0)), (0x80, 0x80, 0x80));+ }++ #[test]+ fn dark_channels_keep_their_value() {+ // 0x37 is in the range the shared conversion gets wrong: it came+ // back as 0x7E and turned a blue icon lavender.+ let blue = LinearRgba::with_srgba(0x37, 0x76, 0xAB, 0xFF);+ assert_eq!(srgb_bytes(lighten(blue, 0.0)), (0x37, 0x76, 0xAB));+ let dim = LinearRgba::with_srgba(0x31, 0x31, 0x31, 0xFF);+ assert_eq!(srgb_bytes(lighten(dim, 0.5)), (0x98, 0x98, 0x98));+ let dimmer = LinearRgba::with_srgba(0x32, 0x32, 0x32, 0xFF);+ assert_eq!(srgb_bytes(darken(dimmer, 0.5)), (0x19, 0x19, 0x19));+ }+}