/
common.slint
147 lines (136 loc) · 5.43 KB
/
common.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
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
import { StyleMetrics, ScrollView } from "std-widgets-impl.slint";
export component LineEditInner inherits Rectangle {
callback accepted(string);
callback edited(string);
in-out property <string> placeholder-text;
in-out property font-size <=> input.font-size;
in-out property text <=> input.text;
in-out property placeholder-color <=> placeholder.color;
in-out property enabled <=> input.enabled;
in-out property <bool> has-focus: input.has-focus;
in-out property input-type <=> input.input-type;
in-out property horizontal-alignment <=> input.horizontal-alignment;
in-out property read-only <=> input.read-only;
public function select-all() {
input.select-all();
}
public function cut() {
input.cut();
}
public function copy() {
input.copy();
}
public function paste() {
input.paste();
}
min-height: input.preferred-height;
min-width: max(50px, placeholder.min-width);
clip: true;
forward-focus: input;
placeholder := Text {
height: 100%; width: 100%;
vertical-alignment: center;
text: (root.text == "" && input.preedit-text == "") ? root.placeholder-text : "";
font-size: input.font-size;
font-italic: input.font-italic;
font-weight: input.font-weight;
font-family: input.font-family;
}
input := TextInput {
property <length> computed_x;
x: min(0px, max(parent.width - self.width, self.computed_x));
width: max(parent.width, self.preferred-width);
height: 100%;
color: self.enabled ? StyleMetrics.textedit-text-color : StyleMetrics.textedit-text-color-disabled;
cursor-position-changed(cpos) => {
if (cpos.x + self.computed_x < StyleMetrics.layout-padding) {
self.computed_x = - cpos.x + StyleMetrics.layout-padding;
} else if (cpos.x + self.computed_x > parent.width - StyleMetrics.layout-padding) {
self.computed_x = parent.width - cpos.x - StyleMetrics.layout-padding;
}
}
accepted => { root.accepted(self.text); }
edited => { root.edited(self.text); }
vertical-alignment: center;
single-line: true;
}
}
export component TextEdit inherits ScrollView {
in property <length> font-size <=> input.font-size;
in-out property <string> text <=> input.text;
has-focus: input.has-focus;
enabled <=> input.enabled;
in property <TextWrap> wrap <=> input.wrap;
in property horizontal-alignment <=> input.horizontal-alignment;
in property read-only <=> input.read-only;
callback edited(string);
forward-focus: input;
public function select-all() {
input.select-all();
}
public function cut() {
input.cut();
}
public function copy() {
input.copy();
}
public function paste() {
input.paste();
}
horizontal-stretch: 1;
vertical-stretch: 1;
viewport-width: root.wrap == TextWrap.word-wrap ? root.visible-width : max(root.visible-width, input.preferred-width);
viewport-height: max(self.visible-height, input.preferred-height);
Rectangle {
background: root.enabled ? StyleMetrics.textedit-background : StyleMetrics.textedit-background-disabled;
}
input := TextInput {
enabled: true;
edited => { root.edited(self.text); }
color: self.enabled ? StyleMetrics.textedit-text-color : StyleMetrics.textedit-text-color-disabled;
single-line: false;
wrap: word-wrap;
cursor-position-changed(cpos) => {
if (cpos.x + root.viewport-x < StyleMetrics.layout-padding) {
root.viewport-x = min(0px, max(parent.visible-width - self.width, - cpos.x + StyleMetrics.layout-padding ));
} else if (cpos.x + root.viewport-x > parent.visible-width - StyleMetrics.layout-padding) {
root.viewport-x = min(0px, max(parent.visible-width - self.width, parent.visible-width - cpos.x - StyleMetrics.layout-padding ));
}
if (cpos.y + root.viewport-y < StyleMetrics.layout-padding) {
root.viewport-y = min(0px, max(parent.visible-height - self.height, - cpos.y + StyleMetrics.layout-padding ));
} else if (cpos.y + root.viewport-y > parent.visible-height - StyleMetrics.layout-padding - 20px) {
// FIXME: font-height hardcoded to 20px
root.viewport-y = min(0px, max(parent.visible-height - self.height, parent.visible-height - cpos.y - StyleMetrics.layout-padding - 20px));
}
}
}
}
export component AboutSlint {
preferred-height: 100%;
preferred-width: 100%;
min-height: lay.min-height;
min-width: lay.min-width;
lay := VerticalLayout {
padding: 12px;
spacing: 8px;
alignment: start;
t := Text {
text: "Made with";
font-size: 24px;
font-weight: 700;
horizontal-alignment: center;
}
Image {
source: StyleMetrics.dark-color-scheme ? @image-url("slint-logo-dark.svg") : @image-url("slint-logo-light.svg");
preferred-width: 256px;
min-height: 48px;
}
Text {
text: "Version 1.0.3\nhttps://slint-ui.com/";
font-size: 10px;
horizontal-alignment: center;
}
}
}