forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printerdemo.slint
162 lines (135 loc) · 4.73 KB
/
printerdemo.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: MIT
import { DemoPalette, Page } from "common.slint";
import { HomePage } from "./home_page.slint";
import { InkLevel, InkPage } from "./ink_page.slint";
import { SettingsPage } from "./settings_page.slint";
import { PrinterQueue } from "./printer_queue.slint";
// re-export for the native code
export { PrinterQueue }
import "./fonts/NotoSans-Regular.ttf";
import "./fonts/NotoSans-Bold.ttf";
component SideBarIcon inherits Rectangle {
in-out property <bool> active;
callback activate;
GridLayout {
padding: 0px;
@children
}
TouchArea {
clicked => { root.activate(); }
}
}
component MainWindow inherits Window {
/// Note that this property is overwritten in the .cpp and .rs code.
/// The data is only in this file so it looks good in the viewer
in property <[InkLevel]> ink-levels: [
{color: #0ff, level: 60%},
{color: #ff0, level: 80%},
{color: #f0f, level: 70%},
{color: #000, level: 30%},
];
out property <int> active-page: 0;
callback quit();
width: 772px;
height: 504px;
title: @tr("Slint printer demo");
background: DemoPalette.main-background;
default-font-family: "Noto Sans";
default-font-size: DemoPalette.base-font-size;
HorizontalLayout {
padding: 10px;
padding-left: 67px;
main-view := Rectangle {
height: 100%;
border-radius: 30px;
background: DemoPalette.page-background-color;
Rectangle {
clip: true;
x: main-view.border-radius / 2;
y: main-view.border-radius / 2;
width: main-view.width - main-view.border-radius;
height: main-view.height - main-view.border-radius;
home-page := HomePage {
y: root.active-page == 0 ? 0 : root.active-page < 0 ? - self.height - 1px : parent.height + 1px;
animate y { duration: 125ms; easing: ease; }
}
SettingsPage {
y: root.active-page == 1 ? 0 : root.active-page < 1 ? - self.height - 1px : parent.height + 1px;
animate y { duration: 125ms; easing: ease; }
}
InkPage {
y: root.active-page == 2 ? 0 : root.active-page < 2 ? - self.height - 1px : parent.height + 1px;
ink-levels <=> root.ink-levels;
page-visible: root.active-page == 2;
animate y { duration: 125ms; easing: ease; }
}
}
}
}
sidebar := Rectangle {
function icon-y(index: int) -> length {
return 100px // top padding
+ index * 72px;
}
width: 57px;
x: 10px;
Image {
x:0;
source: @image-url("images/page_selection.svg");
y: sidebar.icon-y(root.active-page) - self.width / 2;
width: main-view.x - sidebar.x + 1px;
height: 1.75 * self.width;
colorize: DemoPalette.page-background-color;
animate y {
duration: 125ms;
}
}
for page-icon[idx] in [
@image-url("images/home.svg"),
@image-url("images/settings.svg"),
@image-url("images/ink.svg"),
] : SideBarIcon {
activate => {
root.active-page = idx;
}
y: sidebar.icon-y(idx);
x: 16px;
height: 35px;
width: 30px;
icon := Image {
colorize: (root.active-page == idx) ? DemoPalette.active-page-icon-color : DemoPalette.inactive-page-icon-color;
animate colorize {
duration: 125ms;
}
source: page-icon;
image-fit: contain;
width: 100%;
height: 100%;
}
}
Rectangle {
y: sidebar.icon-y(3) + 17px;
x: 12px;
background: #6284FF;
height: 2px;
width: 37px;
}
SideBarIcon {
activate => {
DemoPalette.night-mode = !DemoPalette.night-mode;
}
y: sidebar.icon-y(4);
x: 16px;
height: 35px;
width: 30px;
Image {
colorize: DemoPalette.night-mode ? #F1FF98 : DemoPalette.inactive-page-icon-color;
source: DemoPalette.night-mode ? @image-url("images/moon_full.svg") : @image-url("images/moon.svg");
image-fit: contain;
width: 100%;
height: 100%;
}
}
}
}