Give SecondaryButton, ToggleButton, CircleAction, QbzCheckbox, QbzToggle and QbzSelect a keyboard FocusScope (Enter/Space trigger the same action as a click) plus a non-layout focus-ring overlay: a sibling Rectangle with a transparent-default 2px border that turns Theme.focus-ring only when the scope has keyboard focus, with its radius matched to the control (circle for CircleAction) so focus never reflows the layout. The existing TouchArea stays the pointer source on every control; the FocusScope only adds key activation and focusability. Universal: the ring is a per-theme token and only appears on keyboard focus, so it stays visually neutral at rest across all 33 themes (WCAG 2.4.7 focus-visible). cc
61 lines
1.8 KiB
Plaintext
61 lines
1.8 KiB
Plaintext
// Small square checkbox primitive matching the QBZ dark theme.
|
|
|
|
import { Theme } from "../foundation/semantic-colors.slint";
|
|
import { QbzIcon } from "QbzIcon.slint";
|
|
|
|
export component QbzCheckbox inherits Rectangle {
|
|
in-out property <bool> checked: false;
|
|
callback toggled();
|
|
|
|
width: 18px;
|
|
height: 18px;
|
|
border-radius: 4px;
|
|
background: root.checked ? Theme.accent : transparent;
|
|
border-width: root.checked ? 0px : 1.5px;
|
|
border-color: Theme.text-muted;
|
|
|
|
QbzIcon {
|
|
source: @image-url("../assets/icons/check.svg");
|
|
visible: root.checked;
|
|
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: Theme.accent-text;
|
|
}
|
|
|
|
TouchArea {
|
|
mouse-cursor: pointer;
|
|
clicked => {
|
|
root.checked = !root.checked;
|
|
root.toggled();
|
|
}
|
|
}
|
|
|
|
// Keyboard activation: Enter/Space toggle the box, same as a click. The
|
|
// TouchArea stays the pointer source; this only adds key activation + focus.
|
|
fs := FocusScope {
|
|
key-pressed(event) => {
|
|
if (event.text == Key.Return || event.text == " ") {
|
|
root.checked = !root.checked;
|
|
root.toggled();
|
|
return accept;
|
|
}
|
|
return reject;
|
|
}
|
|
}
|
|
|
|
// Non-layout focus ring — transparent-bordered overlay shown only on
|
|
// keyboard focus, so it never reflows the checkbox.
|
|
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;
|
|
}
|
|
}
|