slint/internal/compiler/widgets/cupertino-base/checkbox.slint
Florian Blasius 80407d0375
Added cupertino style for std-widgets (#3301)
* Started with cupertino style
2023-08-21 11:04:18 +02:00

113 lines
No EOL
3.5 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
import { Typography, Palette, Icons } from "styling.slint";
import { FocusBorder } from "components.slint";
export component CheckBox {
private property <color> text-color: Palette.foreground;
callback toggled;
in property <string> text;
in property <bool> enabled <=> i-touch-area.enabled;
out property <bool> has-focus: i-focus-scope.has-focus;
in-out property <bool> checked;
min-height: max(16px, i-layout.min-height);
accessible-checkable: true;
accessible-label: root.text;
accessible-checked <=> root.checked;
accessible-role: checkbox;
i-layout := HorizontalLayout {
padding-left: 8px;
spacing: 6px;
Rectangle {
y: (parent.height - self.height) / 2;
width: 14px;
height: self.width;
i-shadow := Rectangle {
visible: !root.enabled || root.checked;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
width: parent.width + 2 * self.border-width;
height: parent.height + 2 * self.border-width;
border-radius: 4px;
border-width: 1px;
border-color: root.checked ? Palette.fake-primary-shadow : Palette.fake-shadow;
}
i-background := Rectangle {
background: root.checked ? Palette.primary : Palette.surface;
border-radius: 3px;
border-width: root.checked ? 0 : 1px;
border-color: root.checked ? transparent : Palette.fake-inner-shadow-strong;
i-icon := Image {
image-fit: contain;
visible: root.checked;
source: Icons.check-mark;
colorize: Palette.on-primary;
width: 10px;
animate colorize { duration: 150ms; }
}
}
animate background, border-color { duration: 150ms; }
}
if (root.text != "") : Text {
text: root.text;
color: root.text-color;
font-size: Typography.body.font-size;
font-weight: Typography.body.font-weight;
vertical-alignment: center;
horizontal-alignment: left;
}
}
i-touch-area := TouchArea {
clicked => {
if (root.enabled) {
root.checked = !root.checked;
root.toggled();
}
}
}
i-focus-scope := FocusScope {
x: 0;
width: 0; // Do not react on clicks
enabled <=> root.enabled;
key-pressed(event) => {
if (event.text == " " || event.text == "\n") {
i-touch-area.clicked();
return accept;
}
return reject;
}
}
states [
disabled when !root.enabled : {
i-background.background: Palette.surface-disabled;
i-shadow.border-color: Palette.fake-disabled-shadow;
i-background.border-color: root.checked ? transparent : Palette.fake-inner-shadow;
i-icon.colorize: Palette.foreground-disabled;
}
pressed when i-touch-area.pressed : {
}
hover when i-touch-area.has-hover : {
}
checked when root.checked && root.enabled : {
}
]
animate text-color { duration: 200ms; }
}