-
Notifications
You must be signed in to change notification settings - Fork 2
/
example01.lua
70 lines (59 loc) · 2.31 KB
/
example01.lua
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
local lwtk = require("lwtk")
local Application = lwtk.Application
local Column = lwtk.Column
local Row = lwtk.Row
local PushButton = lwtk.PushButton
local TextInput = lwtk.TextInput
local TitleText = lwtk.TitleText
local Space = lwtk.Space
local app = Application("example01.lua")
local function quit()
app:close()
end
local win = app:newWindow {
title = "example01",
Column {
id = "c1",
onInputChanged = function(widget, input)
widget:byId("b1"):setDisabled(input.text == "")
end,
TitleText { text = "What's your name?" },
TextInput { id = "i1", focus = true, style = { Columns = 40 } },
Row {
Space {},
PushButton { id = "b1", text = "&OK", disabled = true,
default = true,
onClicked = function(widget)
local name = widget:byId("i1").text
widget:byId("t2"):setText("Hello "..name.."!")
widget:byId("c1"):setVisible(false)
widget:byId("c2"):setVisible(true)
end },
PushButton { id = "b2", text = "&Quit", onClicked = quit },
Space {}
}
},
Column {
id = "c2",
visible = false,
Space {},
TitleText { id = "t2", style = { TextAlign = "center" } },
Space {},
Row {
Space {},
PushButton { id = "b3", text = "&Again",
onClicked = function(widget)
widget:byId("i1"):setText("")
widget:byId("i1"):setFocus()
widget:byId("t2"):setText("")
widget:byId("c2"):setVisible(false)
widget:byId("c1"):setVisible(true)
end },
PushButton { id = "b4", text = "&Quit", default = true,
onClicked = quit },
Space {}
}
}
}
win:show()
app:runEventLoop()