forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtodo.slint
134 lines (108 loc) · 3.68 KB
/
todo.slint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT
import { SpinBox, Button, CheckBox, Slider, LineEdit, ScrollView, ListView,
HorizontalBox, VerticalBox, GridBox, StandardButton, Palette } from "std-widgets.slint";
@rust-attr(derive(serde::Serialize, serde::Deserialize))
export struct TodoItem {
title: string,
checked: bool,
}
component MainWindow inherits Window {
in property <[TodoItem]> todo-model: [
{ title: "Implement the .slint file", checked: true },
{ title: "Do the Rust part", checked: false },
{ title: "Make the C++ code", checked: false },
{ title: "Write some JavaScript code", checked: false },
{ title: "Test the application", checked: false },
{ title: "Ship to customer", checked: false },
{ title: "???", checked: false },
{ title: "Profit", checked: false },
];
in property <bool> show-header: false;
in-out property <bool> is-sort-by-name: false;
in-out property <bool> hide-done-items: false;
callback todo-added(string);
callback remove-done();
callback popup_confirmed;
callback show_confirm_popup;
callback apply_sorting_and_filtering();
show_confirm_popup => { confirm_popup.show(); }
preferred-width: 400px;
preferred-height: 600px;
confirm_popup := PopupWindow {
x: 40px;
y: 100px;
width: min(confirm_popup_layout.preferred-width, root.width - 80px);
Rectangle {
background: Palette.background;
border-color: Palette.border;
border-width: 1px;
}
confirm_popup_layout := Dialog {
height:100%; width: 100%;
confirm_popup_text := Text {
text: "Some items are not done, are you sure you wish to quit?";
wrap: word-wrap;
}
StandardButton { kind: yes; clicked => { root.popup_confirmed(); } }
StandardButton { kind: no; }
}
}
VerticalBox {
HorizontalBox {
padding: 0px;
text-edit := LineEdit {
accepted(text) => {
root.todo-added(self.text);
self.text = "";
}
placeholder-text: "What needs to be done?";
}
btn := Button {
clicked => {
root.todo-added(text-edit.text);
text-edit.text = "";
}
text: "Add New Entry";
enabled: text-edit.text != "";
}
}
if (root.show-header) : HorizontalBox {
padding: 0px;
alignment: start;
CheckBox {
toggled => {
root.apply_sorting_and_filtering();
}
text: "Sort by name";
checked <=> root.is-sort-by-name;
}
CheckBox {
toggled => {
root.apply_sorting_and_filtering();
}
text: "Hide done items";
checked <=> root.hide-done-items;
}
}
list-view := ListView {
for todo in root.todo-model: HorizontalLayout {
CheckBox {
toggled => {
todo.checked = self.checked;
}
text: todo.title;
checked: todo.checked;
}
}
}
HorizontalBox {
padding: 0px;
alignment: end;
Button {
clicked => { root.remove-done(); }
text: "Remove Done Items";
}
}
}
}