Last active 1785483122

ui-example.lua Raw
1local runtime = require("@rave/runtime")
2local reactive = require("@rave/reactive")
3local task = require("@rave/task")
4local ui = require("@rave/ui")
5
6assert(runtime.is_client, "This script must run on the client")
7
8local clicks = reactive.source(0)
9local elapsed = reactive.source(0)
10
11ui.mount(function()
12 return ui.panel {
13 align = "center",
14 color = "#090E1A",
15 padding = 6,
16
17 children = {
18 ui.column {
19 color = "#151E32",
20 padding = 28,
21 gap = 12,
22 width = 420,
23
24 children = {
25 ui.text {
26 text = "RAVE ENGINE BABYY",
27 color = "#8B5CF6",
28 font_size = 18,
29 },
30
31 ui.text {
32 text = "Client Script Test",
33 color = "#F4F7FF",
34 font_size = 28,
35 },
36
37 ui.text {
38 text = "Reactive UI",
39 color = "#94A3B8",
40 font_size = 15,
41 },
42
43 ui.spacer {
44 size = 12,
45 },
46
47 ui.panel {
48 color = "#0E1628",
49 padding = 14,
50
51 children = {
52 ui.text {
53 text = function()
54 return string.format(
55 "Running for %.1f seconds",
56 elapsed()
57 )
58 end,
59
60 color = "#46BE6E",
61 },
62 },
63 },
64
65 ui.spacer {
66 size = 8,
67 },
68
69 ui.button {
70 text = function()
71 if clicks() == 0 then
72 return "Try the reactive button"
73 end
74
75 return string.format(
76 "Clicked %d %s ✓",
77 clicks(),
78 clicks() == 1 and "time" or "times"
79 )
80 end,
81
82 color = function()
83 return clicks() > 0 and "#16A36A" or "#6D4CE8"
84 end,
85
86 accessibility_label = "Press to do +1",
87
88 pressed = function()
89 clicks:update(function(value)
90 return value + 1
91 end)
92
93 print(string.format(
94 "Client button clicked: %d",
95 clicks()
96 ))
97 end,
98 },
99
100 ui.spacer {
101 size = 4,
102 },
103
104 ui.text {
105 text = "Peepeepoopoo",
106 color = "#64748B",
107 font_size = 13,
108 },
109 },
110 },
111 },
112 }
113end)
114
115