Files
qbz/crates/qbz-ui/ui/primitives/ExpandableSearch.slint
T
vicrodh c8ef2a1b1d refactor(slint): split qbz-slint into qbz-ui lib + qbz bin; reclaim qbz binary
Slint cannot split the .slint compilation across crates, but a Slint LIBRARY
crate exposes its generated Rust types to dependent crates (verified with a
minimal proof). So:

- NEW crate `qbz-ui` (lib): owns the whole .slint tree + build.rs + bundled
  translations; `slint::include_modules!()` + the generated types (AppWindow,
  MiniPlayerWindow, all globals/structs) are re-exported. Translation domain is
  now `qbz-ui` (the .po files renamed accordingly).
- `qbz-slint` (bin) -> renamed to `qbz` (package + `[[bin]] name = "qbz"`),
  reclaiming the binary name from the retired Tauri app. It depends on `qbz-ui`
  and does `pub use qbz_ui::*;` so existing `crate::AppWindow` / `crate::*State`
  references resolve unchanged.

This splits the single ~20 GB rustc into two crates (UI/codegen vs the 75k LOC
of logic) — the foundation for lower build peak, incremental caching, and the
upcoming per-feature crate extraction.

Also fixed for the move: qbz-i18n bundled-.po include paths, the font/WGSL
`include_bytes!`/`include_str!` paths (-> ../../qbz-ui/ui/), workspace members,
dev scripts (`-p qbz`), and the CI workflows. `cargo check -p qbz` is green.

cc
2026-06-25 17:51:09 -06:00

162 lines
6.3 KiB
Plaintext

// Reusable expandable page-search — the exact pattern from the JUMP TO
// bar (ArtistView): a magnifier that, on click, opens a right-anchored
// input that grows to the LEFT (over whatever sits to its left), with
// a leading magnifier glyph + a trailing X that clears and closes.
//
// Self-contained: occupies a small fixed footprint when closed; the
// open overlay overflows to the left, so nothing to its right moves.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { QbzIcon } from "QbzIcon.slint";
import { UiFocusState } from "../focus-state.slint";
export component ExpandableSearch inherits Rectangle {
in property <string> placeholder: @tr("Search…");
// Trimmed 20px so the open field doesn't ride over the controls to its
// left on small screens.
in property <length> max-open-width: 196px;
in-out property <bool> open: false;
in-out property <string> query;
// Bootstrap-style small variant. Default is the standard size.
in property <bool> sm: false;
callback edited(string);
// Defer the focus: focusing the input synchronously inside `changed open`
// races the open animation/layout (and can panic with "Recursion
// detected"). A one-shot timer grabs focus a tick later, reliably.
focus-timer := Timer {
interval: 30ms;
running: false;
triggered => {
input.focus();
self.running = false;
}
}
changed open => {
if (root.open) {
focus-timer.running = true;
focus-timer.restart();
}
}
// Closed footprint — just the magnifier slot.
width: root.sm ? 30px : 34px;
height: root.sm ? 30px : 34px;
// Closed: the magnifier toggle. Fades (not toggled) so open/close is
// smooth in both directions.
Rectangle {
opacity: root.open ? 0.0 : 1.0;
animate opacity { duration: 120ms; easing: ease-in-out; }
width: root.sm ? 30px : 34px;
height: root.sm ? 30px : 34px;
border-radius: 6px;
background: open-ta.has-hover ? Theme.surface-hover : transparent;
QbzIcon {
source: @image-url("../assets/icons/search.svg");
width: root.sm ? 14px : 16px;
height: root.sm ? 14px : 16px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: open-ta.has-hover ? Theme.text-primary : Theme.text-muted;
}
open-ta := TouchArea {
enabled: !root.open;
mouse-cursor: pointer;
clicked => {
root.open = true;
}
}
}
// Open: right-anchored overlay that grows left. Always rendered; its width
// animates to 0 when closed (clip hides it), so the shrink is also smooth.
overlay := Rectangle {
x: parent.width - self.width;
width: root.open ? root.max-open-width : 0px;
height: root.sm ? 30px : 34px;
background: Theme.surface-card;
border-radius: 6px;
border-width: root.open ? 1px : 0px;
// Focused border uses the dedicated focus-ring token (accent-equal in
// most themes, distinct in the a11y palettes) so keyboard focus reads
// consistently with every other primitive's ring.
border-color: input.has-focus ? Theme.focus-ring : Theme.border-subtle;
clip: true;
animate width { duration: 200ms; easing: ease-in-out; }
HorizontalLayout {
padding-left: 11px;
padding-right: 5px;
spacing: 8px;
// Leading magnifier glyph (decorative).
VerticalLayout {
horizontal-stretch: 0;
alignment: center;
QbzIcon {
source: @image-url("../assets/icons/search.svg");
width: 14px;
height: 14px;
tint: Theme.text-muted;
}
}
// Input + placeholder.
Rectangle {
horizontal-stretch: 1;
clip: true;
input := TextInput {
width: 100%;
height: 100%;
color: Theme.text-primary;
font-size: Typography.body;
vertical-alignment: center;
single-line: true;
text <=> root.query;
changed has-focus => { UiFocusState.text-input-focused = self.has-focus; }
edited => {
root.edited(self.text);
}
}
Text {
visible: input.text == "";
width: 100%;
height: 100%;
text: root.placeholder;
color: Theme.text-muted;
font-size: Typography.body;
vertical-alignment: center;
overflow: elide;
}
}
// Trailing X — clears + closes (back to the magnifier).
VerticalLayout {
horizontal-stretch: 0;
alignment: center;
Rectangle {
width: root.sm ? 22px : 24px;
height: root.sm ? 22px : 24px;
border-radius: 4px;
background: clear-ta.has-hover ? Theme.surface-elevated : transparent;
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 12px;
height: 12px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: clear-ta.has-hover ? Theme.text-primary : Theme.text-muted;
}
clear-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.query = "";
root.edited("");
root.open = false;
}
}
}
}
}
}
}