// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { Typography, Palette } from "styling.slint"; import { FocusBorder } from "components.slint"; export component Button { private property background: primary && root.enabled ? Palette.accent : Palette.surface; private property text-color: primary && root.enabled ? Palette.on-surface : Palette.foreground; callback clicked; in property text; in property icon; in property primary; in property enabled <=> i-touch-area.enabled; in property checkable; out property has-focus: i-focus-scope.has-focus; out property pressed: self.enabled && i-touch-area.pressed; in-out property checked; min-width: max(20px, i-layout.min-width); min-height: max(20px, i-layout.min-height); horizontal-stretch: 0; vertical-stretch: 0; accessible-label: text; accessible-role: button; FocusBorder { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; width: parent.width + 6px; height: parent.height + 6px; border-radius: 8px; has-focus: root.has-focus; } if (root.primary && root.enabled) : Rectangle { drop-shadow-blur: 3px; drop-shadow-color: #00000066; drop-shadow-offset-y: 0.5px; border-radius: 5px; background: root.background; Rectangle { drop-shadow-blur: 2px; drop-shadow-color: #00000026; drop-shadow-offset-y: 1px; border-radius: parent.border-radius; background: root.background; } Rectangle { drop-shadow-blur: 1px; drop-shadow-color: #00000026; drop-shadow-offset-y: 0.5px; border-radius: parent.border-radius; background: root.background; } Rectangle { border-radius: parent.border-radius; background: Palette.dimmer; opacity: 0.17; } } if (!root.primary || !root.enabled) : Rectangle { drop-shadow-blur: 0.25px; drop-shadow-color: #00000066; drop-shadow-offset-y: 0.25px; border-radius: 5px; background: root.background; Rectangle { drop-shadow-blur: 1px; drop-shadow-color: #00000026; drop-shadow-offset-y: 1px; border-radius: parent.border-radius; background: root.background; border-width: 1px; border-color: Palette.decent-border; opacity: root.enabled ? 1 : 0.5; } } i-layout := HorizontalLayout { padding-left: 8px; padding-right: 8px; padding-top: 4px; padding-bottom: 4px; spacing: 4px; alignment: center; if (root.icon.width > 0 && root.icon.height > 0) : Image { y: (parent.height - self.height) / 2; source <=> root.icon; width: 13px; opacity: root.enabled ? 1 : 0.5; } if (root.text != "") : Text { opacity: root.enabled ? 1 : 0.5; font-size: Typography.body.font-size; font-weight: Typography.body.font-weight; horizontal-alignment: center; vertical-alignment: center; text: root.text; color: root.text-color; animate color { duration: 150ms; } } } i-touch-area := TouchArea { clicked => { if (root.checkable) { root.checked = !root.checked; } root.clicked(); } } 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 !i-touch-area.enabled : { root.text-color: Palette.foreground-secondary; root.background: Palette.surface-quaternary; } pressed when root.pressed : { root.background: root.primary ? Palette.accent-secondary : Palette.surface-secondary; } checked when root.checked : { root.text-color: Palette.accent-secondary; } ] animate background { duration: 150ms; } }