1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
3
4import { ChildIndicator, NameLabel, ResettingLineEdit } from "./basics.slint";
5
6import { PropertyValue, PropertyValueKind } from "../../api.slint";
7import { EditorSizeSettings, EditorSpaceSettings } from "../../components/styling.slint";
8
9import { CheckBox } from "std-widgets.slint";
10
11export component BooleanWidget inherits GridLayout {
12 in property <bool> enabled;
13 in property <string> property-name;
14 in-out property <PropertyValue> property-value;
15
16 callback set-bool-binding(value: bool);
17 callback update-display-string(value: string);
18
19 spacing-vertical: EditorSpaceSettings.default-spacing;
20
21 Row {
22 NameLabel {
23 col: 1;
24
25 property-name: root.property-name;
26 property-value: root.property-value;
27 }
28 }
29
30 Row {
31 childIndicator := ChildIndicator {
32 horizontal-stretch: 0;
33 visible: false;
34 }
35
36 checkbox := CheckBox {
37 enabled: root.enabled;
38 checked: root.property-value.value-bool;
39 text: self.display-string();
40
41 function display-string() -> string {
42 return self.checked ? "true" : "false";
43 }
44
45 toggled() => {
46 root.property-value.value-bool = self.checked;
47 // This needs o happen first, or the PropertyValueWidget will not
48 // trigger anything in upate-display-string-impl().
49 root.update-display-string(self.display-string());
50 root.set-bool-binding(self.checked);
51 }
52 }
53 }
54}
55
56