1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4import { LineEdit, Button, ComboBox, GridBox } from "std-widgets.slint";
5
6export component Booker inherits Window {
7 // returns true if the string parameter is a valid date
8 pure callback validate-date(string) -> bool;
9 // returns true if the first date is before the second date and they are both valid
10 pure callback compare-date(string, string) -> bool;
11
12 validate-date(_) => { true }
13 compare-date(a, b) => { a <= b }
14
15 private property <bool> message-visible;
16
17 GridBox {
18 combo := ComboBox {
19 row: 0;
20 model: ["one-way flight", "return flight"];
21 current-value: "one-way flight";
22 current-index: 0;
23 }
24 t1 := LineEdit {
25 row: 1;
26 text: "27.03.2014";
27 }
28 Rectangle {
29 row: 1; // over the previous line edit
30 background: root.validate-date(t1.text) ? transparent : #f008;
31 }
32 t2 := LineEdit {
33 row: 2;
34 text: "27.03.2014";
35 enabled: combo.current-index == 1;
36 }
37 Rectangle {
38 row: 2; // over the previous line edit
39 background: root.validate-date(t2.text) ? transparent : #f008;
40 }
41 Button {
42 row: 3;
43 text: "Book";
44 clicked() => { root.message-visible = true; }
45 enabled: combo.current-index != 1 ? root.validate-date(t1.text) : root.compare-date(t1.text, t2.text);
46 }
47 }
48
49 if (root.message-visible) : Rectangle {
50 width: 100%;
51 height: 100%;
52 background: #ee8;
53 Text {
54 width: 100%;
55 height: 100%;
56 text: "You have booked a " + combo.current-value + " on " + t1.text;
57 vertical-alignment: center;
58 horizontal-alignment: center;
59 }
60 TouchArea {
61 width: 100%;
62 height: 100%;
63 clicked => { root.message-visible = false; }
64 }
65 }
66}
67