From cdedb86b9c8d0776a255a5c9b2f03c69aaf0c46e Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 6 Oct 2026 00:01:23 +0000 Subject: [PATCH] ui: tooltips on icon buttons, and a count IconButton names itself in a tooltip after a moment of hover, also while it is disabled (mute or deafen when not connected), and can show a neutral count at its top right (for pins and topics later). Tooltips are desktop only: the new Bridge.desktop is false in the Android app. Tooltip showed once (its Timer turned off its own binding) and stayed open after the pointer left. Both now use Slint's Tooltip element with our TooltipBubble: it opens at the pointer, closes when the pointer leaves, and lets clicks and hover through, which a PopupWindow of our own does not while it is open. A press closes it until the pointer leaves. The bubble sets its own preferred width, up to 400px, so long text wraps: the tooltip's popup takes that width, and a max-width would not narrow it. IconButton's look moves onto an inner rectangle: with an opacity and an animation on its root, Slint inlined it at each of its 100-odd uses, and the tooltip and count alone added 3.3 MB of generated code to a crate whose compile already peaks near 14 GB. Now the generated code is 1.1 MB smaller than before (70.7 MB). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AVRENKftQqGoEeswiR9TDQ --- CHANGELOG.md | 5 + crates/voelin-ui/src/app.rs | 1 + crates/voelin-ui/ui/bridge.slint | 3 + crates/voelin-ui/ui/components/badge.slint | 6 +- crates/voelin-ui/ui/components/button.slint | 119 +++++++++++------- crates/voelin-ui/ui/components/index.slint | 1 + crates/voelin-ui/ui/components/overlay.slint | 37 +----- crates/voelin-ui/ui/components/tooltip.slint | 70 +++++++++++ .../voelin-ui/ui/screens/studio-parts.slint | 1 - docs/ui.md | 15 ++- 10 files changed, 175 insertions(+), 83 deletions(-) create mode 100644 crates/voelin-ui/ui/components/tooltip.slint diff --git a/CHANGELOG.md b/CHANGELOG.md index 01b8111..bb0ea18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows decoders work without installing FFmpeg. - AV1 decoding through dav1d in every desktop build. - 122 more signed client versions (`Versions.csv`). +- Icon buttons show their name on hover (desktop), also while they are + disabled. ### Changed @@ -53,6 +55,9 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - The account's avatar is downloaded from its own link; it was asked for as an upload link and refused with HTTP 403. +- Hover help in the Stream Studio (a source's error, the status details) + shows each time and closes when the pointer leaves; it showed only once, + and stayed open until a click. ## [0.0.1-alpha] - 2026-10-04 diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index acd65e6..9eb45f6 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -643,6 +643,7 @@ pub fn run(options: RunOptions) -> Result<()> { let bridge = ui.global::(); bridge.set_app_name(voelin_platform::APP_NAME.into()); bridge.set_app_version(env!("CARGO_PKG_VERSION").into()); + bridge.set_desktop(cfg!(not(target_os = "android"))); let models = Models::new(&bridge); // Wayland and X11 find the desktop file (and icon) by this id. #[cfg(not(target_os = "android"))] diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index 71d2051..a6b144b 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -934,6 +934,9 @@ export global Bridge { // The product name (voelin_platform::APP_NAME, not translated) and version. in property app-name: "Voelin"; in property app-version; + // False in the Android app; the one platform flag (tooltips are desktop + // only). The studio's own window, desktop only, keeps the default. + in property desktop: true; in-out property client-audio; // Opt-in local crash reports, and a notice about reports on disk. in-out property crash-reports; diff --git a/crates/voelin-ui/ui/components/badge.slint b/crates/voelin-ui/ui/components/badge.slint index fa46017..b5e1a02 100644 --- a/crates/voelin-ui/ui/components/badge.slint +++ b/crates/voelin-ui/ui/components/badge.slint @@ -1,10 +1,12 @@ import { Theme } from "../theme.slint"; import { Icon } from "icon.slint"; -// A red count bubble (unread, requests). +// A count bubble (unread, requests), red unless `fill` says otherwise. export component CountBadge inherits Rectangle { in property count; in property fill: Theme.live; + // The number's colour. + in property ink: Theme.on-accent; width: max(18px, label.preferred-width + 10px); height: 18px; border-radius: 9px; @@ -16,7 +18,7 @@ export component CountBadge inherits Rectangle { padding-right: 5px; label := Text { text: root.count > 99 ? "99+" : root.count; - color: #ffffff; + color: root.ink; font-size: Theme.font-xs; font-weight: Theme.weight-bold; horizontal-alignment: center; diff --git a/crates/voelin-ui/ui/components/button.slint b/crates/voelin-ui/ui/components/button.slint index 493e66d..ee12c1f 100644 --- a/crates/voelin-ui/ui/components/button.slint +++ b/crates/voelin-ui/ui/components/button.slint @@ -1,5 +1,7 @@ import { Theme } from "../theme.slint"; import { Icon } from "icon.slint"; +import { CountBadge } from "badge.slint"; +import { HoverTooltip } from "tooltip.slint"; export enum ButtonKind { // Filled accent: the main action. @@ -117,11 +119,19 @@ export component Button inherits Rectangle { } } -// A square (or round) button with only an icon; `label` is for screen -// readers and the tooltip-less toolbar. +// A square (or round) button with only an icon. `label` names it for +// screen readers and, on the desktop, in a tooltip. +// +// The look is on `face`, not on the root: an opacity or an animation on a +// component's root makes Slint inline the component where it is used, and +// there are over a hundred IconButtons. Shared, their code stays small (and +// so does the compiler's memory). export component IconButton inherits Rectangle { in property icon; in property label; + // Shown when the pointer rests on the button (desktop only, also while + // disabled); "" for none. + in property tooltip: label; in property enabled: true; in property checked; in property round; @@ -135,63 +145,80 @@ export component IconButton inherits Rectangle { // A small dot at the top right (unread, live). in property dot; in property dot-color: Theme.live; + // A neutral count at the top right (pins, topics); hidden at 0 or less. + in property count; callback clicked(); width: size; height: size; - border-radius: round ? size / 2 : Theme.radius-md; - background: touch.pressed ? Theme.surface-4 - : checked ? (danger ? Theme.danger-soft : Theme.accent-soft) - : touch.has-hover ? Theme.surface-3 - : filled ? Theme.surface-2 : transparent; - border-width: filled || checked ? 1px : 0px; - border-color: checked ? (danger ? Theme.danger.transparentize(50%) : Theme.accent) : Theme.border; - opacity: enabled ? 1.0 : 0.45; - animate background { duration: Theme.fast; } accessible-role: AccessibleRole.button; accessible-label: label; accessible-enabled: enabled; accessible-action-default => { if enabled { clicked(); } } - FocusRing { - shown: focus.has-focus; - radius: root.border-radius; - w: root.width; - h: root.height; - } - focus := FocusScope { - enabled: root.enabled; - key-pressed(event) => { - if event.text == " " || event.text == "\n" { - root.clicked(); - return accept; - } - reject + face := Rectangle { + border-radius: root.round ? root.size / 2 : Theme.radius-md; + background: touch.pressed ? Theme.surface-4 + : root.checked ? (root.danger ? Theme.danger-soft : Theme.accent-soft) + : touch.has-hover ? Theme.surface-3 + : root.filled ? Theme.surface-2 : transparent; + border-width: root.filled || root.checked ? 1px : 0px; + border-color: root.checked ? (root.danger ? Theme.danger.transparentize(50%) : Theme.accent) : Theme.border; + opacity: root.enabled ? 1.0 : 0.45; + animate background { duration: Theme.fast; } + + FocusRing { + shown: focus.has-focus; + radius: face.border-radius; + w: root.width; + h: root.height; } - touch := TouchArea { + focus := FocusScope { enabled: root.enabled; - mouse-cursor: MouseCursor.pointer; - clicked => { - focus.focus(); - root.clicked(); + key-pressed(event) => { + if event.text == " " || event.text == "\n" { + root.clicked(); + return accept; + } + reject + } + touch := TouchArea { + enabled: root.enabled; + mouse-cursor: MouseCursor.pointer; + clicked => { + focus.focus(); + root.clicked(); + } } } - } - Icon { - source: icon; - size: icon-size; - tint: root.tint; - } - if dot: Rectangle { - x: parent.width - self.width - root.size * 0.18; - y: root.size * 0.16; - width: 9px; - height: 9px; - border-radius: 4.5px; - background: dot-color; - border-width: 2px; - border-color: Theme.surface; + Icon { + source: root.icon; + size: root.icon-size; + tint: root.tint; + } + if root.dot: Rectangle { + x: parent.width - self.width - root.size * 0.18; + y: root.size * 0.16; + width: 9px; + height: 9px; + border-radius: 4.5px; + background: root.dot-color; + border-width: 2px; + border-color: Theme.surface; + } + if root.count > 0: CountBadge { + x: parent.width - self.width + 4px; + y: -4px; + count: root.count; + fill: Theme.icon; + ink: Theme.surface; + } + HoverTooltip { + text: root.tooltip; + pressed: touch.pressed; + hovered: touch.has-hover; + } } } @@ -211,6 +238,8 @@ export component ActionButton inherits VerticalLayout { IconButton { icon: root.icon; label: root.text; + // The caption already names it. + tooltip: ""; checked: root.checked; danger: root.danger; enabled: root.enabled; diff --git a/crates/voelin-ui/ui/components/index.slint b/crates/voelin-ui/ui/components/index.slint index b67248d..f07d22a 100644 --- a/crates/voelin-ui/ui/components/index.slint +++ b/crates/voelin-ui/ui/components/index.slint @@ -15,6 +15,7 @@ export { SectionHeader, Card, Divider, Banner } from "card.slint"; export { Meter, SpeakingBars } from "meter.slint"; export { NavItem, ListItem } from "list-item.slint"; export { MenuEntry, PopupMenu, Tooltip, Modal, Toast, ResizeHandle } from "overlay.slint"; +export { TooltipBubble, HoverTooltip } from "tooltip.slint"; export { RichText, EmojiPicker } from "emoji.slint"; // Virtualised lists and scrolling come from the standard widgets (styled by // the fluent-dark style); ListView builds only the visible rows. diff --git a/crates/voelin-ui/ui/components/overlay.slint b/crates/voelin-ui/ui/components/overlay.slint index 8f62997..7fad49a 100644 --- a/crates/voelin-ui/ui/components/overlay.slint +++ b/crates/voelin-ui/ui/components/overlay.slint @@ -5,6 +5,7 @@ import { Theme } from "../theme.slint"; import { Icons } from "../icons.slint"; import { Icon } from "icon.slint"; import { IconButton } from "button.slint"; +import { HoverTooltip } from "tooltip.slint"; // An entry of a `PopupMenu`. export struct MenuEntry { @@ -102,39 +103,13 @@ export component PopupMenu inherits Rectangle { } } -// Hover help: wraps @children and shows `text` in a bubble after a moment. +// Hover help: wraps @children and shows `text` in a bubble near the +// pointer after a moment, until the pointer leaves (desktop only). export component Tooltip inherits Rectangle { in property text; - // Above (default) or below the element. - in property below; - area := TouchArea { - @children - } - Timer { - interval: 600ms; - running: area.has-hover && root.text != ""; - triggered => { - self.running = false; - bubble.show(); - } - } - bubble := PopupWindow { - x: (root.width - self.width) / 2; - y: root.below ? root.height + 6px : -self.height - 6px; - width: label.preferred-width + 20px; - height: label.preferred-height + 12px; - close-policy: PopupClosePolicy.close-on-click-outside; - Rectangle { - border-radius: Theme.radius-sm; - background: Theme.surface-4; - border-width: 1px; - border-color: Theme.border-strong; - label := Text { - text: root.text; - color: Theme.text; - font-size: Theme.font-sm; - } - } + @children + HoverTooltip { + text: root.text; } } diff --git a/crates/voelin-ui/ui/components/tooltip.slint b/crates/voelin-ui/ui/components/tooltip.slint new file mode 100644 index 0000000..c6e2484 --- /dev/null +++ b/crates/voelin-ui/ui/components/tooltip.slint @@ -0,0 +1,70 @@ +// Tooltips: the bubble, and the hover area that shows it on the desktop. +// Kept apart from overlay.slint, which imports button.slint, so buttons can +// use them. + +import { Theme } from "../theme.slint"; +import { Bridge } from "../bridge.slint"; + +// The bubble of a tooltip: short text on a raised surface. Longer text +// wraps at `widest`. +export component TooltipBubble inherits Rectangle { + in property text; + in property widest: 400px; + // The tooltip's popup takes this preferred width (a max-width would not + // narrow it), and the text wraps inside it. + preferred-width: min(root.widest, label.preferred-width + 2 * Theme.space-3); + // Slint's own tooltip frame (4px corners) lies under the bubble, so the + // corners match it. + border-radius: Theme.radius-xs; + background: Theme.surface-4; + border-width: 1px; + border-color: Theme.border-strong; + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + padding-top: Theme.space-2; + padding-bottom: Theme.space-2; + label := Text { + text: root.text; + color: Theme.text; + font-size: Theme.font-sm; + vertical-alignment: center; + wrap: word-wrap; + } + } +} + +// Put last in an element: it fills the element, and once the pointer rests +// on it for a moment, `text` shows in a bubble at the pointer until the +// pointer leaves. Desktop only (`Bridge.desktop`). +// +// It is Slint's `Tooltip`, whose bubble lets the pointer through: a +// PopupWindow of our own takes every click and move while it is open, so +// the element under it would lose the click and its hover. Being last, the +// hover area sees the pointer before the element's other children, also +// over a disabled button. Near the window's edges Slint moves the bubble +// inside. +export component HoverTooltip inherits Rectangle { + in property text; + // The element's own TouchArea, if it has one: a press closes the bubble + // until the pointer leaves. + in property pressed; + in property hovered; + property clicked; + changed pressed => { + if self.pressed { + self.clicked = true; + } + } + changed hovered => { + if !self.hovered { + self.clicked = false; + } + } + // Removing the area closes an open bubble. + if Bridge.desktop && !root.clicked && root.text != "": Tooltip { + TooltipBubble { + text: root.text; + } + } +} diff --git a/crates/voelin-ui/ui/screens/studio-parts.slint b/crates/voelin-ui/ui/screens/studio-parts.slint index e9fab2a..9798240 100644 --- a/crates/voelin-ui/ui/screens/studio-parts.slint +++ b/crates/voelin-ui/ui/screens/studio-parts.slint @@ -710,7 +710,6 @@ export component StudioHeader inherits HorizontalLayout { } Tooltip { text: StudioBridge.status.details; - below: true; width: 20px; height: 20px; Icon { diff --git a/docs/ui.md b/docs/ui.md index e7f307b..19699e1 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -84,13 +84,18 @@ The standard widgets (scroll bars, context menus) follow through All in `ui/components/`, exported by `components/index.slint`. +A component used in many places keeps `opacity`, `visible`, shadows and +animations off its root element: Slint inlines such a component at every +use, which grows the generated code and the compiler's memory (IconButton +puts them on an inner `face`). + | Component | File | Key properties | |---|---|---| | `Icon` | icon.slint | `source` (an `Icons.*`), `size`, `tint` | | `Spinner` | icon.slint | `size`, `tint`, `running` | | `Button` | button.slint | `text`, `icon`, `kind` (`ButtonKind.primary/secondary/danger/ghost`), `enabled`, `checked`, `small`; `clicked` | -| `IconButton` | button.slint | `icon`, `label` (screen readers), `checked`, `danger`, `round`, `filled`, `size`, `icon-size`, `tint`, `dot`; `clicked` | -| `ActionButton` | button.slint | round button with a caption (Mute, Deafen, Go Live): `icon`, `text`, `checked`, `danger` | +| `IconButton` | button.slint | `icon`, `label` (screen readers), `tooltip` (default `label`, "" for none; on hover, also while disabled, desktop only), `checked`, `danger`, `round`, `filled`, `size`, `icon-size`, `tint`, `dot`, `count` (a neutral number at the top right, hidden at 0 or less); `clicked` | +| `ActionButton` | button.slint | round button with a caption (Mute, Deafen, Go Live), no tooltip: `icon`, `text`, `checked`, `danger` | | `FocusRing` | button.slint | the accent ring of focused controls | | `TextField` | text-field.slint | `text`, `placeholder`, `input-type`, `icon`, `label`, `bare`, `read-only`; `accepted`, `edited`, `key-pressed`; `clear()`, `select-all()` | | `SearchBox` | text-field.slint | a TextField with a magnifier and the Ctrl K hint (`show-shortcut`) | @@ -104,7 +109,7 @@ All in `ui/components/`, exported by `components/index.slint`. | `SegmentedTabs` | tabs.slint | `model`, `current-index`, `label`; `selected(int)` | | `TabItem` | tabs.slint | underlined tab: `text`, `selected`, `badge`, `closable`; `clicked`, `close` | | `Avatar` | avatar.slint | `image` or `initials` + `tint`, `size`, `status` (`Status.online/idle/dnd/offline/info`), `speaking` (green ring), `crown`, `square` (server icons) | -| `CountBadge` | badge.slint | red count bubble: `count`, `fill` | +| `CountBadge` | badge.slint | count bubble: `count`, `fill` (red), `ink` (the number) | | `LiveBadge` | badge.slint | `text` (LIVE), `large` | | `Chip` | badge.slint | tag: `text`, `icon`, `tint`, `fill`, `outlined` | | `Dot` | badge.slint | a status dot | @@ -117,7 +122,9 @@ All in `ui/components/`, exported by `components/index.slint`. | `NavItem` | list-item.slint | navigation entry: `icon`, `text`, `subtitle`, `selected`, `badge`, `chevron`; `clicked` | | `ListItem` | list-item.slint | row with a leading slot (@children), `title`, `subtitle`, `trailing`, `selected` | | `PopupMenu` | overlay.slint | themed menu: `entries` ([MenuEntry]), `show(x, y)`; `activated(int)` | -| `Tooltip` | overlay.slint | wraps @children, shows `text` on hover | +| `Tooltip` | overlay.slint | wraps @children; `text` shows at the pointer after a moment, until it leaves (desktop only: `Bridge.desktop`) | +| `HoverTooltip` | tooltip.slint | the same, put last in an element (as IconButton does): `text`; `pressed` and `hovered` of the element's TouchArea (a press closes it until the pointer leaves) | +| `TooltipBubble` | tooltip.slint | a tooltip's bubble: `text`, wrapping at `widest` (400px) | | `Modal` | overlay.slint | dialog with backdrop: `title`, `subtitle`, `icon`, `card-width`, `card-height`; `dismissed` (backdrop, Escape, ×) | | `Toast` | overlay.slint | `text`, `icon`, `timeout`, `shown` | | `ResizeHandle` | overlay.slint | drag to resize a side panel: `size` (two-way), `minimum`, `maximum`, `left` |