From 6918db3e4dbcf03c94ae9772d261f949ecc21071 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 01:52:25 +0000 Subject: [PATCH] Tab: the selected tab draws an accent bar along its top edge in high contrast --- crates/ui-widgets/src/tabs/tab.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 69da97979..ea4bd2bd6 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -17,7 +17,7 @@ use crate::primitives::{IconSpec, PaintShape, StrokeWidth, TextRun}; use crate::runtime::env::Label; use crate::style::{ComponentStyle, Corners, Flags, IconLook, RuleKind, StyleColor, StyleCx, SurfaceLook, TextLook, UiTokens}; use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, PointerButton, PressPhase, Proposal, Sense}; -use craft_theme::{Rgba, RowStyle, Stateful, States, TypeRole}; +use craft_theme::{Contrast, Rgba, RowStyle, Stateful, States, TypeRole}; use egui::{Pos2, Rect, Response, Vec2}; #[cfg(feature = "testing")] @@ -77,6 +77,8 @@ struct Sizes { label_line: f32, detail_line: f32, underline_gap: f32, + /// The height of the selected tab's indicator bar. + indicator: f32, text_only: bool, } @@ -100,6 +102,8 @@ pub struct TabStyle { icon: IconLook, /// Under the selected text tab's label. underline: StyleColor, + /// The bar along the selected tab's top edge: the accent in high contrast, none otherwise and on text tabs. + indicator: Option, /// A divider at the tab's trailing edge, in a theme that divides rows. divider: bool, close_side: CloseSide, @@ -256,6 +260,7 @@ impl Component for Tab<'_> { label_line: line(role), detail_line: line(TypeRole::Caption), underline_gap: space.gap.tight, + indicator: stroke.thick, text_only, }; TabStyle { @@ -265,6 +270,7 @@ impl Component for Tab<'_> { detail: TextLook::new(TypeRole::Caption, ink(colors.text.faint, colors.text.faint)), icon: IconLook::new(sizes.icon, ink(colors.text.muted, colors.text.normal)), underline: c(colors.text.normal), + indicator: (!text_only && cx.contrast() == Contrast::High).then(|| c(colors.accent.solid)), divider: key.kind.compact_dividers() && tokens.shape.rows == RowStyle::Divided, close_side: close_side(cx.os, cx.direction.is_rtl()), sizes, @@ -405,6 +411,10 @@ impl Component for Tab<'_> { let x = cx.flow.end_x(); draw.rule(RuleKind::Divider, Pos2::new(x, rect.top()), Pos2::new(x, rect.bottom())); } + if let (Some(color), true) = (style.indicator, selected) { + let bar = Rect::from_min_size(rect.min, Vec2::new(rect.width(), sizes.indicator.min(rect.height()))); + draw.fill(&PaintShape::Rect(bar, egui::CornerRadius::ZERO), color); + } if sizes.text_only && selected { let y = placed.label.bottom() + sizes.underline_gap; let line = PaintShape::Path(vec![Pos2::new(placed.label.left(), y), Pos2::new(placed.label.right(), y)]);