forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbooker.slint
66 lines (60 loc) · 2.01 KB
/
booker.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
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT
import { LineEdit, Button, ComboBox, GridBox } from "std-widgets.slint";
export component Booker inherits Window {
// returns true if the string parameter is a valid date
pure callback validate-date(string) -> bool;
// returns true if the first date is before the second date and they are both valid
pure callback compare-date(string, string) -> bool;
validate-date(_) => { true }
compare-date(a, b) => { a <= b }
private property <bool> message-visible;
GridBox {
combo := ComboBox {
row: 0;
model: ["one-way flight", "return flight"];
current-value: "one-way flight";
current-index: 0;
}
t1 := LineEdit {
row: 1;
text: "27.03.2014";
}
Rectangle {
row: 1; // over the previous line edit
background: root.validate-date(t1.text) ? transparent : #f008;
}
t2 := LineEdit {
row: 2;
text: "27.03.2014";
enabled: combo.current-index == 1;
}
Rectangle {
row: 2; // over the previous line edit
background: root.validate-date(t2.text) ? transparent : #f008;
}
Button {
row: 3;
text: "Book";
clicked() => { root.message-visible = true; }
enabled: combo.current-index != 1 ? root.validate-date(t1.text) : root.compare-date(t1.text, t2.text);
}
}
if (root.message-visible) : Rectangle {
width: 100%;
height: 100%;
background: #ee8;
Text {
width: 100%;
height: 100%;
text: "You have booked a " + combo.current-value + " on " + t1.text;
vertical-alignment: center;
horizontal-alignment: center;
}
TouchArea {
width: 100%;
height: 100%;
clicked => { root.message-visible = false; }
}
}
}