mirror of
https://github.com/slint-ui/slint.git
synced 2025-07-13 16:15:18 +00:00

* Add `AccessibleRole::Image` * Improve accessibility of the `AboutSlint` widget * Filter out some images from the accessibility tree
118 lines
3.8 KiB
Text
118 lines
3.8 KiB
Text
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
import { FluentFontSettings, FluentPalette, Icons } from "styling.slint";
|
|
import { FocusBorder } from "components.slint";
|
|
|
|
export component CheckBox {
|
|
in property <string> text;
|
|
in property <bool> enabled <=> touch-area.enabled;
|
|
out property <bool> has-focus: focus-scope.has-focus;
|
|
in-out property <bool> checked;
|
|
|
|
callback toggled;
|
|
|
|
private property <color> text-color: FluentPalette.foreground;
|
|
|
|
min-height: max(18px, layout.min-height);
|
|
accessible-checkable: true;
|
|
accessible-enabled: root.enabled;
|
|
accessible-label: root.text;
|
|
accessible-checked <=> root.checked;
|
|
accessible-role: checkbox;
|
|
accessible-action-default => {
|
|
root.checked = !root.checked;
|
|
root.toggled();
|
|
}
|
|
forward-focus: focus-scope;
|
|
|
|
states [
|
|
disabled when !root.enabled : {
|
|
border.border-color: FluentPalette.control-strong-stroke-disabled;
|
|
background.background: root.checked ? FluentPalette.accent-disabled : FluentPalette.control-alt-disabled;
|
|
icon.colorize: FluentPalette.text-accent-foreground-disabled;
|
|
root.text-color: FluentPalette.text-disabled;
|
|
}
|
|
pressed when touch-area.pressed : {
|
|
border.border-color: FluentPalette.control-strong-stroke-disabled;
|
|
background.background: root.checked ? FluentPalette.tertiary-accent-background : FluentPalette.control-alt-quartiary;
|
|
icon.colorize: FluentPalette.text-accent-foreground-secondary;
|
|
}
|
|
hover when touch-area.has-hover : {
|
|
background.background: root.checked ? FluentPalette.secondary-accent-background : FluentPalette.control-alt-tertiary;
|
|
}
|
|
checked when root.checked && root.enabled : {
|
|
background.background: FluentPalette.accent-background;
|
|
}
|
|
]
|
|
|
|
animate text-color { duration: 200ms; }
|
|
|
|
layout := HorizontalLayout {
|
|
spacing: 12px;
|
|
|
|
background := Rectangle {
|
|
width: 18px;
|
|
height: self.width;
|
|
y: (parent.height - self.height) / 2;
|
|
background: FluentPalette.control-alt-secondary;
|
|
border-radius: 2px;
|
|
|
|
animate background, border-color { duration: 150ms; }
|
|
|
|
border := Rectangle {
|
|
border-color: FluentPalette.control-strong-stroke;
|
|
border-width: root.checked ? 0 : 1px;
|
|
border-radius: parent.border-radius;
|
|
}
|
|
|
|
icon := Image {
|
|
image-fit: contain;
|
|
visible: root.checked;
|
|
source: Icons.check-mark;
|
|
colorize: FluentPalette.accent-foreground;
|
|
width: 12px;
|
|
accessible-role: none;
|
|
|
|
animate colorize { duration: 150ms; }
|
|
}
|
|
}
|
|
|
|
if root.text != "" : Text {
|
|
text: root.text;
|
|
color: root.text-color;
|
|
font-size: FluentFontSettings.body.font-size;
|
|
font-weight: FluentFontSettings.body.font-weight;
|
|
vertical-alignment: center;
|
|
horizontal-alignment: left;
|
|
}
|
|
}
|
|
|
|
touch-area := TouchArea {
|
|
clicked => {
|
|
if (root.enabled) {
|
|
root.checked = !root.checked;
|
|
root.toggled();
|
|
}
|
|
}
|
|
}
|
|
|
|
focus-scope := FocusScope {
|
|
x: 0;
|
|
width: 0; // Do not react on clicks
|
|
enabled <=> root.enabled;
|
|
|
|
key-pressed(event) => {
|
|
if (event.text == " " || event.text == "\n") {
|
|
touch-area.clicked();
|
|
return accept;
|
|
}
|
|
return reject;
|
|
}
|
|
}
|
|
|
|
// focus border
|
|
if root.has-focus && root.enabled : FocusBorder {
|
|
border-radius: 4px;
|
|
}
|
|
}
|