-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_window.slint
More file actions
138 lines (119 loc) · 4.9 KB
/
Copy pathmain_window.slint
File metadata and controls
138 lines (119 loc) · 4.9 KB
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
135
136
137
138
import { VirtualKeyboardHandler, VirtualKeyboard, KeyModel } from "virtual_keyboard.slint";
import { AutocompleteHandler } from "autocomplete_line_edit.slint";
import { ConfettiOverlay } from "confetti.slint";
import { Main } from "pages/main.slint";
import { Donate } from "pages/donate.slint";
import { InsertMoney } from "pages/insert_money.slint";
import { HomeAssistant } from "pages/home_assistant.slint";
export { VirtualKeyboardHandler, KeyModel, AutocompleteHandler }
enum Page {
Main,
Donate,
InsertMoney,
HomeAssistant,
Top,
Games
}
export component MainWindow inherits Window {
property <Page> current-page: Page.Main;
in-out property <int> session-amount: 0;
in-out property <string> session-username: "";
in-out property <int> session-fund-id: 0;
in-out property <string> session-fund-name: "";
// data storage
in-out property <[string]> available-funds: [];
in-out property <[int]> available-fund-ids: [];
in-out property <[string]> usernames: [];
// confetti state
in-out property <bool> show-confetti: false;
in-out property <bool> confetti-falling: false;
// toast state — set by Rust when a bill or coin is accepted
in-out property <int> last-added-amount: 0;
// callbacks for rust to hook into
callback done-clicked(string, int, int); // username, fund_id, amount
callback start-accepting-money();
callback stop-accepting-money();
callback show-home-assistant();
callback hide-home-assistant();
callback fetch-funds(); // fetches available-funds and available-fund-ids
callback fetch-usernames(); // fetches available-usernames for autocomplete
callback confetti-started(); // tells rust to start confetti dismiss timer
/// Called from Rust when HASS sends a POST /close-hass request.
public function close-hass-remote() {
root.hide-home-assistant();
root.current-page = Page.Main;
}
title: "Donation Machine";
width: 1280px;
height: 1024px;
Rectangle {
if current-page == Page.Main: Main {
donate-clicked => {
root.current-page = Page.Donate;
}
home-assistant-clicked => {
root.show-home-assistant();
root.current-page = Page.HomeAssistant;
}
}
if current-page == Page.Donate: Donate {
fund-items: root.available-funds;
fund-ids: root.available-fund-ids;
username-suggestions: root.usernames;
fetch-funds => {
root.fetch-funds();
}
fetch-usernames => {
root.fetch-usernames();
}
back-clicked => {
VirtualKeyboardHandler.open = false;
root.current-page = Page.Main;
}
next-clicked(username, fund-id) => {
debug("proceed with username:", username, "fund:", fund-id);
VirtualKeyboardHandler.open = false;
root.session-username = username;
root.session-fund-id = fund-id;
root.session-fund-name = self.selected-fund-index >= 0 ? self.fund-items[self.selected-fund-index] : "";
root.session-amount = 0; // reset session amount
root.start-accepting-money(); // enable bill acceptor
root.current-page = Page.InsertMoney;
}
}
if current-page == Page.InsertMoney: InsertMoney {
current-amount: root.session-amount;
username: root.session-username;
fundname: root.session-fund-name;
last-added-amount <=> root.last-added-amount;
cancel-clicked => {
root.stop-accepting-money(); // disable bill acceptor
root.session-amount = 0;
root.session-username = "";
root.current-page = Page.Donate;
}
done-clicked(username, amount) => {
debug("done with username:", username, "amount:", amount, "fund:", root.session-fund-id);
root.stop-accepting-money(); // disable bill acceptor
// call the root callback so rust can handle the donation
root.done-clicked(username, root.session-fund-id, amount);
root.session-amount = 0;
root.session-username = "";
root.session-fund-id = 0;
root.current-page = Page.Main;
root.show-confetti = true;
root.confetti-started();
}
}
if current-page == Page.HomeAssistant: HomeAssistant {
back-clicked => {
root.hide-home-assistant();
root.current-page = Page.Main;
}
}
// Confetti overlay — rendered on top of all pages
if root.show-confetti: ConfettiOverlay {
falling: root.confetti-falling;
}
}
}