-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUi.ttslua
executable file
·158 lines (136 loc) · 3.59 KB
/
Ui.ttslua
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
require('ge_tts.License')
---@class ge_tts__static_Ui
local Ui = {}
-- Common
Ui.Alignment = {
UpperLeft = "UpperLeft",
UpperCenter = "UpperCenter",
UpperRight = "UpperRight",
MiddleLeft = "MiddleLeft",
MiddleCenter = "MiddleCenter",
MiddleRight = "MiddleRight",
LowerLeft = "LowerLeft",
LowerCenter = "LowerCenter",
LowerRight = "LowerRight",
}
Ui.Animation = {
Hide = {
None = "None",
Shrink = "Shrink",
FadeOut = "FadeOut",
SlideOutLeft = "SlideOut_Left",
SlideOutRight = "SlideOut_Right",
SlideOutTop = "SlideOut_Top",
SlideOutBottom = "SlideOut_Bottom",
},
Show = {
None = "None",
Grow = "Grow",
FadeIn = "FadeIn",
SlideInLeft = "SlideIn_Left",
SlideInRight = "SlideIn_Right",
SlideInTop = "SlideIn_Top",
SlideInBottom = "SlideIn_Bottom",
},
}
Ui.ContentSizeFit = {
Vertical = "vertical",
Horizontal = "horizontal",
Both = "both",
None = "none",
}
Ui.FontStyle = {
Normal = "Normal",
Bold = "Bold",
Italic = "Italic",
BoldItalic = "BoldItalic",
}
Ui.IconAlignment = {
Left = "Left",
Right = "Right",
}
Ui.MouseButton = {
Left = "-1",
Right = "-2",
Middle = "-3",
}
Ui.Navigation = {
None = "None",
Horizontal = "Horizontal",
Vertical = "Vertical",
Automatic = "Automatic",
Explicit = "Explicit",
}
Ui.Tag = {
Button = "Button",
Defaults = "Defaults",
HorizontalLayout = "HorizontalLayout",
Image = "Image",
Option = "Option",
Panel = "Panel",
Text = "Text",
VerticalLayout = "VerticalLayout",
}
Ui.TooltipPosition = {
Above = "Above",
Below = "Below",
Left = "Left",
Right = "Right",
}
-- Elements
Ui.Button = {
Transition = {
None = "None",
ColorTint = "ColorTint",
SpriteSwap = "SpriteSwap",
Animation = "Animation",
}
}
Ui.Text = {
HorizontalOverflow = {
Wrap = "Wrap",
Overflow = "Overflow",
},
VerticalOverflow = {
Truncate = "Truncate",
Overflow = "Overflow",
}
}
---@generic Attributes : tts__UIElementBase_Attributes
---@generic Child : tts__UIElement
---@generic Element : tts__UIElementBase<Attributes, Child>
---@param element Element
---@param attributes Attributes
function Ui.setAttributes(element, attributes)
if not element.attributes then
element.attributes = --[[---@type Attributes]] {}
end
for k, v in pairs(attributes) do
(--[[---@type any]] element.attributes)[k] = v
end
end
-- UI.setAttribute is buggy and in certain cases unrelated attributes to the one being updated are visually discarded.
-- This is particularly prominent with buttons, setting 'text' or 'interactable' result in 'color' and 'textColor' being
-- discarded. We provide convenience functions that (re)set all attributes rather than just the one/few being targetted.
Ui.Runtime = {}
---@param id tts__UIElement_Id
---@param name string
---@param value string | number | boolean
---@return boolean
function Ui.Runtime.setAttribute(id, name, value)
local attributes = UI.getAttributes(id)
attributes[name] = tostring(value)
return UI.setAttributes(id, attributes)
end
---@generic V : (string | number | boolean)
---@param id tts__UIElement_Id
---@param attributes table<string, V>
---@return boolean
function Ui.Runtime.setAttributes(id, attributes)
local allAttributes = UI.getAttributes(id)
for k, v in pairs(attributes) do
allAttributes[k] = tostring(v)
end
return UI.setAttributes(id, allAttributes)
end
return Ui