// Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial import { StateLayer } from "components.slint"; import { MaterialFontSettings, MaterialPalette, Elevation } from "styling.slint"; // Default button widget with Material Design Filled Button look and feel. export component Button { in property text; in property enabled <=> i-state-layer.enabled; in property checkable; in property icon; in property primary; out property has-focus: i-state-layer.has-focus; out property pressed: self.enabled && i-state-layer.pressed; in-out property checked; callback clicked; private property text-color: root.primary ? MaterialPalette.on-accent : MaterialPalette.on-surface; private property text-opacity: 1.0; min-height: max(40px, i-layout.min-height); min-width: max(40px, i-layout.min-width); accessible-label: text; accessible-role: button; forward-focus: i-state-layer; states [ disabled when !root.enabled : { i-background.background: MaterialPalette.on-background-alt; i-background.opacity: 0.12; root.text-opacity: 0.38; root.text-color: MaterialPalette.on-surface; } checked when root.checked: { root.text-color: MaterialPalette.on-accent; } ] i-background := Rectangle { width: 100%; height: 100%; border-radius: 20px; background: root.primary ? MaterialPalette.accent : MaterialPalette.surface; drop-shadow-color: transparent; drop-shadow-blur: Elevation.level0; drop-shadow-offset-y: 1px; } i-state-layer := StateLayer { has-ripple: true; border-radius: i-background.border-radius; background: MaterialPalette.on-background-alt; ripple-color: MaterialPalette.secondary-ripple; selection-background: MaterialPalette.accent; focusable: true; clicked => { if (root.checkable) { root.checked = !root.checked; } root.clicked(); } } i-layout := HorizontalLayout { padding-left: 24px; padding-right: 24px; spacing: 8px; if (root.icon.width > 0 && root.icon.height > 0): Image { source <=> root.icon; width: 24px; opacity: root.text-opacity; } if (root.text != "") : Text { text: root.text; color: root.text-color; opacity: root.text-opacity; vertical-alignment: center; horizontal-alignment: center; font-weight: MaterialFontSettings.label-large.font-weight; animate color { duration: 250ms; easing: ease; } } } }