ui-example.lua
· 3.3 KiB · Lua
Raw
local runtime = require("@rave/runtime")
local reactive = require("@rave/reactive")
local task = require("@rave/task")
local ui = require("@rave/ui")
assert(runtime.is_client, "This script must run on the client")
local clicks = reactive.source(0)
local elapsed = reactive.source(0)
ui.mount(function()
return ui.panel {
align = "center",
color = "#090E1A",
padding = 6,
children = {
ui.column {
color = "#151E32",
padding = 28,
gap = 12,
width = 420,
children = {
ui.text {
text = "RAVE ENGINE BABYY",
color = "#8B5CF6",
font_size = 18,
},
ui.text {
text = "Client Script Test",
color = "#F4F7FF",
font_size = 28,
},
ui.text {
text = "Reactive UI",
color = "#94A3B8",
font_size = 15,
},
ui.spacer {
size = 12,
},
ui.panel {
color = "#0E1628",
padding = 14,
children = {
ui.text {
text = function()
return string.format(
"Running for %.1f seconds",
elapsed()
)
end,
color = "#46BE6E",
},
},
},
ui.spacer {
size = 8,
},
ui.button {
text = function()
if clicks() == 0 then
return "Try the reactive button"
end
return string.format(
"Clicked %d %s ✓",
clicks(),
clicks() == 1 and "time" or "times"
)
end,
color = function()
return clicks() > 0 and "#16A36A" or "#6D4CE8"
end,
accessibility_label = "Press to do +1",
pressed = function()
clicks:update(function(value)
return value + 1
end)
print(string.format(
"Client button clicked: %d",
clicks()
))
end,
},
ui.spacer {
size = 4,
},
ui.text {
text = "Peepeepoopoo",
color = "#64748B",
font_size = 13,
},
},
},
},
}
end)
| 1 | local runtime = require("@rave/runtime") |
| 2 | local reactive = require("@rave/reactive") |
| 3 | local task = require("@rave/task") |
| 4 | local ui = require("@rave/ui") |
| 5 | |
| 6 | assert(runtime.is_client, "This script must run on the client") |
| 7 | |
| 8 | local clicks = reactive.source(0) |
| 9 | local elapsed = reactive.source(0) |
| 10 | |
| 11 | ui.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 | } |
| 113 | end) |
| 114 | |
| 115 |