Files
qbz/crates/qbz-ui/ui/primitives/CommandBlock.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

97 lines
3.4 KiB
Plaintext

// CommandBlock — a copy-paste shell command / config snippet (HiFi wizard).
//
// Surface-elevated card (Radius.sm, no pills) with an optional caption, a
// monospace command body that wraps, and a copy button that flips to a green
// check for 2s. READ-ONLY: the `copy()` callback is wired by the consumer to
// the clipboard (crate::share::copy_to_clipboard); nothing is ever executed.
//
// The height is content-sized (col.preferred-height) so a multi-line command
// grows the block; callers place it in a VerticalLayout and never set a fixed
// height.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { QbzIcon } from "QbzIcon.slint";
export component CommandBlock inherits Rectangle {
in property <string> command;
// Optional caption rendered above the command (e.g. what it does).
in property <string> caption: "";
callback copy();
property <bool> just-copied: false;
border-radius: Radius.sm;
background: Theme.surface-elevated;
border-width: 1px;
border-color: Theme.border-subtle;
height: col.preferred-height;
col := VerticalLayout {
padding: 12px;
spacing: 8px;
if root.caption != "": Text {
text: root.caption;
color: Theme.text-secondary;
font-size: Typography.legal;
font-weight: Typography.medium;
wrap: word-wrap;
}
HorizontalLayout {
spacing: 10px;
// Monospace command body — wraps, takes the remaining width.
Text {
text: root.command;
color: Theme.text-primary;
font-size: Typography.legal;
font-family: "monospace";
wrap: word-wrap;
horizontal-stretch: 1;
}
// Copy button — fixed 30x30, pinned to the top of the row.
VerticalLayout {
alignment: start;
copy-btn := Rectangle {
width: 30px;
height: 30px;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-subtle;
background: copy-ta.has-hover ? Theme.surface-hover : Theme.surface-card;
QbzIcon {
width: 15px;
height: 15px;
source: root.just-copied
? @image-url("../assets/icons/check.svg")
: @image-url("../assets/icons/copy.svg");
tint: root.just-copied
? #3fae6a
: (copy-ta.has-hover ? Theme.text-primary : Theme.text-muted);
}
copy-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.copy();
root.just-copied = true;
reset-timer.running = true;
}
}
}
}
}
}
// Resets the "copied" check after 2s.
reset-timer := Timer {
interval: 2s;
running: false;
triggered => {
root.just-copied = false;
self.running = false;
}
}
}