forked from SparkUniverse/Elementa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentsGui.kt
More file actions
312 lines (250 loc) · 10.6 KB
/
ComponentsGui.kt
File metadata and controls
312 lines (250 loc) · 10.6 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package com.example.examplemod
import gg.virtualclient.virtualgui.WindowScreen
import gg.virtualclient.virtualgui.components.*
import gg.virtualclient.virtualgui.components.image.BlurHashImage
import gg.virtualclient.virtualgui.components.input.UIMultilineTextInput
import gg.virtualclient.virtualgui.components.input.UITextInput
import gg.virtualclient.virtualgui.components.inspector.Inspector
import gg.virtualclient.virtualgui.constraints.*
import gg.virtualclient.virtualgui.dsl.*
import gg.virtualclient.virtualgui.effects.OutlineEffect
import gg.virtualclient.virtualgui.markdown.MarkdownComponent
import net.kyori.adventure.text.Component
import java.awt.Color
import java.net.URL
class ComponentsGui : WindowScreen(Component.empty()) {
init {
ComponentType("UIContainer") {
val bar = UIBlock().constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 150.pixels()
height = 50.pixels()
} childOf this
val container = UIContainer().constrain {
x = 0.pixels(true)
width = ChildBasedSizeConstraint(padding = 2f)
height = ChildBasedMaxSizeConstraint()
} childOf bar effect OutlineEffect(Color.BLUE, 2f)
repeat(3) {
UIBlock(Color.RED).constrain {
x = SiblingConstraint(padding = 2f)
width = 25.pixels()
height = 25.pixels()
} childOf container
}
} childOf window
ComponentType("UIBlock") {
UIBlock().constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 50.pixels()
height = 50.pixels()
} childOf this
} childOf window
ComponentType("UIText") {
UIText("This is my non-wrapping text").constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
// I have no need to set a width/height, UIText sets those to the
// inherent width/height of the passed string.
} childOf this
UIText("I can scale!").constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
textScale = (1.5f).pixels()
} childOf this
UIText("Shadowless...", shadow = false).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
} childOf this
} childOf window
ComponentType("UIWrappedText") {
UIWrappedText("This is my text that is wrapping at 100 pixels!").constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
} childOf this
UIWrappedText("I'm going to wrap at 100 pixels, but centered :)", centered = true).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
} childOf this
UIWrappedText("I have a height, a lot of text, and will trim. foo bar baz qux", trimText = true).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 30.pixels()
} childOf this
} childOf window
ComponentType("UIRoundedRectangle") {
UIRoundedRectangle(2f).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 50.pixels()
} childOf this
UIRoundedRectangle(10f).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 50.pixels()
} childOf this
} childOf window
ComponentType("UICircle") {
UICircle().constrain {
// These x & y positions describe the CENTER of the circle
x = 30.pixels()
y = SiblingConstraint() + 15.pixels()
// We do not specify the width & height of the circle, rather, we specify
// its radius.
radius = 10.pixels()
} childOf this
UICircle(10f).constrain {
x = 30.pixels()
y = SiblingConstraint() + 15.pixels()
} childOf this
} childOf window
ComponentType("UIShape") {
val shapeHolder = UIContainer().constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 50.pixels()
height = 40.pixels()
} childOf this
ComponentType("UIImage") {
UIImage.ofURL(URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 50.pixels()
} childOf this
UIImage.ofURL(URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 150.pixels()
height = ImageAspectConstraint()
} childOf this
} childOf window
ComponentType("BlurHashImage") {
BlurHashImage("L4ESU,OD1e#:=GwwJSAr1M,r|]Ar").constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 50.pixels()
} childOf this
BlurHashImage.ofURL("L4ESU,OD1e#:=GwwJSAr1M,r|]Ar", URL("https://i.imgur.com/Pc6iMw3.png")).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 50.pixels()
} childOf this
} childOf window
ComponentType("Text Input") {
val box1 = UIBlock(Color(50, 50, 50)).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = 12.pixels()
} childOf this
val textInput1 = UITextInput("My single line text input!").constrain {
x = 2.pixels()
y = 2.pixels()
width = RelativeConstraint(1f) - 6.pixels()
} childOf box1
box1.onMouseClick { textInput1.grabWindowFocus() }
val box2 = UIBlock(Color(50, 50, 50)).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 100.pixels()
height = ChildBasedSizeConstraint() + 4.pixels()
} childOf this
val textInput2 = UIMultilineTextInput("My multiline text input!").constrain {
x = 2.pixels()
y = 2.pixels()
width = RelativeConstraint(1f) - 6.pixels()
}.setMaxLines(4) childOf box2
box2.onMouseClick { textInput2.grabWindowFocus() }
} childOf window
ComponentType("ScrollComponent") {
val scroll1 = ScrollComponent().constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 150.pixels()
height = 75.pixels()
} childOf this
repeat(5) {
UIBlock(Color.RED).constrain {
x = CenterConstraint()
y = SiblingConstraint(padding = 2f)
width = 50.pixels()
height = 25.pixels()
} childOf scroll1
}
ScrollComponent("I'm empty :(").constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 150.pixels()
height = 75.pixels()
} childOf this
} childOf window
ComponentType("Markdown") {
MarkdownComponent(
"""
# Markdown!
This is pretty cool. We [can](https://google.com) now render arbitrary markdown beautifully.
```
We even have code :)
```
""".trimIndent()
).constrain {
x = 2.pixels()
y = SiblingConstraint(padding = 2f)
width = 200.pixels()
height = 100.pixels()
} childOf this
} childOf window
ComponentType("SVG") {
SVGComponent.ofResource("/svg/test.svg").constrain {
x = 2.pixels()
y = SiblingConstraint(padding = 2f)
width = 50.pixels()
height = 50.pixels()
} childOf this
} childOf window
ComponentType("Gradient") {
GradientComponent(Color.BLACK, Color.PINK).constrain {
x = 2.pixels()
y = SiblingConstraint() + 5.pixels()
width = 50.pixels()
height = 50.pixels()
} childOf this
} childOf window
Inspector(window).constrain {
x = 10.pixels(true)
y = 10.pixels(true)
} childOf window
}
}
class ComponentType(componentName: String, initBlock: ComponentType.() -> Unit) : UIContainer() {
init {
constrain {
x = CramSiblingConstraint(10f) coerceAtLeast 5.pixels()
y = CramSiblingConstraint(10f) coerceAtLeast 5.pixels()
width = ChildBasedMaxSizeConstraint() + 5.pixels()
height = ChildBasedSizeConstraint(padding = 5f) + 5.pixels()
}
enableEffect(OutlineEffect(OUTLINE_COLOR, OUTLINE_WIDTH))
UIText(componentName).constrain {
x = 2.pixels()
y = 2.pixels()
textScale = (1.5f).pixels()
} childOf this
this.initBlock()
}
companion object {
private val OUTLINE_COLOR = Color.BLACK
private const val OUTLINE_WIDTH = 2f
}
}
}