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
88 lines
3.4 KiB
Plaintext
88 lines
3.4 KiB
Plaintext
// Full-width accent button primitive.
|
|
|
|
import { Theme } from "../foundation/semantic-colors.slint";
|
|
import { Radius } from "../foundation/radius.slint";
|
|
import { Typography } from "../foundation/typography.slint";
|
|
|
|
export component QbzPrimaryButton inherits Rectangle {
|
|
in property <string> label;
|
|
in property <bool> enabled: true;
|
|
// Destructive variant (e.g. the Delete confirm) — a red fill instead of the
|
|
// accent. Additive; existing callers default to the accent primary.
|
|
in property <bool> destructive: false;
|
|
callback clicked();
|
|
|
|
height: 48px;
|
|
border-radius: Radius.sm;
|
|
opacity: root.enabled ? 1.0 : 0.5;
|
|
// Destructive hover darkens the SOLID danger (Theme.danger-hover is a
|
|
// 15-25% translucent tint meant for danger-bg surfaces, not a button fill —
|
|
// using it here would make the button ~80% transparent / pale on hover in
|
|
// every theme). `.darker()` keeps an opaque, richer red across all palettes.
|
|
background: root.destructive
|
|
? (ta.has-hover && root.enabled ? Theme.danger.darker(0.15) : Theme.danger)
|
|
: (ta.has-hover && root.enabled ? Theme.accent-hover : Theme.accent);
|
|
|
|
animate background { duration: 150ms; }
|
|
|
|
// A padded layout drives the preferred-width (label + 20px each side) so the
|
|
// button auto-sizes as a footer chip inside an `alignment: end` row, while
|
|
// still stretching full-width when the parent layout stretches it (login).
|
|
HorizontalLayout {
|
|
alignment: center;
|
|
padding-left: 20px;
|
|
padding-right: 20px;
|
|
Text {
|
|
text: root.label;
|
|
color: Theme.accent-text;
|
|
font-size: Typography.button;
|
|
font-weight: Typography.semibold;
|
|
horizontal-alignment: center;
|
|
vertical-alignment: center;
|
|
}
|
|
}
|
|
|
|
ta := TouchArea {
|
|
enabled: root.enabled;
|
|
mouse-cursor: root.enabled ? pointer : default;
|
|
clicked => {
|
|
root.clicked();
|
|
}
|
|
}
|
|
|
|
// Keyboard activation: Enter/Space fire the same click. `focus-on-click:
|
|
// false` is LOAD-BEARING: Slint hit-tests siblings in REVERSE declaration
|
|
// order, so this FocusScope (declared after `ta`) is visited BEFORE the
|
|
// TouchArea. With the default focus-on-click:true an unfocused FocusScope
|
|
// eats the first Pressed just to grab keyboard focus, aborting the event
|
|
// before it reaches `ta` — THE "blue buttons need two clicks" bug. Disabling
|
|
// focus-on-click makes the FocusScope ignore the press (it stays Tab- and
|
|
// key-focusable for Enter/Space); the press then falls through to `ta` and
|
|
// the first click registers.
|
|
fs := FocusScope {
|
|
enabled: root.enabled;
|
|
focus-on-click: false;
|
|
key-pressed(event) => {
|
|
if (event.text == Key.Return || event.text == " ") {
|
|
root.clicked();
|
|
return accept;
|
|
}
|
|
return reject;
|
|
}
|
|
}
|
|
|
|
// Non-layout focus ring — a transparent-bordered overlay shown only on
|
|
// keyboard focus, so it never reflows the button (universal a11y, neutral
|
|
// at rest in all themes).
|
|
Rectangle {
|
|
x: 0;
|
|
y: 0;
|
|
width: parent.width;
|
|
height: parent.height;
|
|
background: transparent;
|
|
border-width: 2px;
|
|
border-color: fs.has-focus ? Theme.focus-ring : transparent;
|
|
border-radius: parent.border-radius;
|
|
}
|
|
}
|