slint/internal/compiler/widgets/cosmic-base/button.slint
Aurindam Jana 0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00

82 lines
2.6 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.2 OR LicenseRef-Slint-commercial
import { CosmicFontSettings, CosmicPalette } from "styling.slint";
import { StateLayer } from "components.slint";
export component Button {
in property <string> text;
in property <image> icon;
in property <bool> primary;
in property <bool> enabled <=> state-layer.enabled;
in property <bool> checkable;
in property <bool> colorize-icon;
out property <bool> has-focus: state-layer.has-focus;
out property <bool> pressed: self.enabled && state-layer.pressed;
in-out property <bool> checked <=> state-layer.checked;
callback clicked;
private property <brush> text-color: primary ? CosmicPalette.accent-foreground : CosmicPalette.control-foreground;
min-width: max(32px, layout.min-width);
min-height: max(32px, layout.min-height);
horizontal-stretch: 0;
vertical-stretch: 0;
accessible-checkable: root.checkable;
accessible-checked <=> root.checked;
accessible-label: text;
accessible-role: button;
forward-focus: state-layer;
states [
disabled when !root.enabled : {
root.opacity: 0.5;
}
]
background := Rectangle {
border-radius: 16px;
background: root.primary ? CosmicPalette.accent-background : CosmicPalette.control-background;
animate background, border-color { duration: 150ms; }
layout := HorizontalLayout {
padding-left: 12px;
padding-right: 12px;
padding-top: 5px;
padding-bottom: 5px;
spacing: 4px;
alignment: center;
if (root.icon.width > 0 && root.icon.height > 0) : Image {
y: (parent.height - self.height) / 2;
source <=> root.icon;
width: 20px;
colorize: root.colorize-icon ? root.text-color : transparent;
}
if (root.text != ""): Text {
font-size: CosmicFontSettings.body.font-size;
font-weight: CosmicFontSettings.body.font-weight;
horizontal-alignment: center;
vertical-alignment: center;
text: root.text;
color: root.text-color;
animate color { duration: 150ms; }
}
}
}
state-layer := StateLayer {
border-radius: background.border-radius;
clicked => {
if (root.checkable) {
root.checked = !root.checked;
}
root.clicked();
}
}
}