-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Style.lua
227 lines (191 loc) · 5.9 KB
/
Style.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
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
--[[
MIT License
Copyright (c) 2019-2021 Love2D Community <love2d.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
local Config = require(SLAB_PATH .. '.Internal.Core.Config')
local Cursor = require(SLAB_PATH .. '.Internal.Core.Cursor')
local FileSystem = require(SLAB_PATH .. '.Internal.Core.FileSystem')
local Utility = require(SLAB_PATH .. '.Internal.Core.Utility')
local API = {}
local Styles = {}
local StylePaths = {}
local DefaultStyles = {}
local CurrentStyle = ""
local FontStack = {}
local Style =
{
Font = nil,
FontSize = 14,
MenuColor = {0.2, 0.2, 0.2, 1.0},
ScrollBarColor = {0.4, 0.4, 0.4, 1.0},
ScrollBarHoveredColor = {0.8, 0.8, 0.8, 1.0},
SeparatorColor = {0.5, 0.5, 0.5, 0.7},
WindowBackgroundColor = {0.2, 0.2, 0.2, 1.0},
WindowTitleFocusedColor = {0.26, 0.53, 0.96, 1.0},
WindowCloseBgColor = {0.64, 0.64, 0.64, 1.0},
WindowCloseColor = {0.0, 0.0, 0.0, 1.0},
ButtonColor = {0.55, 0.55, 0.55, 1.0},
RadioButtonSelectedColor = {0.2, 0.2, 0.2, 1.0},
ButtonHoveredColor = {0.7, 0.7, 0.7, 1.0},
ButtonPressedColor = {0.8, 0.8, 0.8, 1.0},
ButtonDisabledTextColor = {0.35, 0.35, 0.35, 1.0},
CheckBoxSelectedColor = {0.0, 0.0, 0.0, 1.0},
CheckBoxDisabledColor = {0.35, 0.35, 0.35, 1.0},
TextColor = {0.875, 0.875, 0.875, 1.0},
TextDisabledColor = {0.45, 0.45, 0.45, 1.0},
TextHoverBgColor = {0.5, 0.5, 0.5, 1.0},
TextURLColor = {0.2, 0.2, 1.0, 1.0},
ComboBoxColor = {0.4, 0.4, 0.4, 1.0},
ComboBoxHoveredColor = {0.55, 0.55, 0.55, 1.0},
ComboBoxDropDownColor = {0.4, 0.4, 0.4, 1.0},
ComboBoxDropDownHoveredColor = {0.55, 0.55, 0.55, 1.0},
ComboBoxArrowColor = {1.0, 1.0, 1.0, 1.0},
InputBgColor = {0.4, 0.4, 0.4, 1.0},
InputEditBgColor = {0.6, 0.6, 0.6, 1.0},
InputSelectColor = {0.14, 0.29, 0.53, 0.4},
InputSliderColor = {0.1, 0.1, 0.1, 1.0},
MultilineTextColor = {0.0, 0.0, 0.0, 1.0},
ListBoxBgColor = {0.0, 0.0, 0.0, 0.0},
WindowRounding = 2.0,
WindowBorder = 4.0,
WindowTitleH = 0.0,
ButtonRounding = 2.0,
CheckBoxRounding = 2.0,
ComboBoxRounding = 2.0,
InputBgRounding = 2.0,
ScrollBarRounding = 2.0,
Indent = 14.0,
MenuPadH = 0.0,
MenuItemPadH = 0.0,
API = API
}
function API.Initialize()
local StylePath = "/Internal/Resources/Styles/"
local Path = SLAB_FILE_PATH .. StylePath
-- Use love's filesystem functions to support both packaged and unpackaged builds
local Items = love.filesystem.getDirectoryItems(Path)
local StyleName = nil
for I, V in ipairs(Items) do
if string.find(V, Path, 1, true) == nil then
V = Path .. V
end
local LoadedStyle = API.LoadStyle(V, false, true)
if LoadedStyle ~= nil then
local Name = FileSystem.GetBaseName(V, true)
if StyleName == nil then
StyleName = Name
end
end
end
if not API.SetStyle("Dark") then
API.SetStyle(StyleName)
end
Style.Font = love.graphics.newFont(Style.FontSize)
API.PushFont(Style.Font)
Cursor.SetNewLineSize(Style.Font:getHeight())
end
function API.LoadStyle(Path, Set, IsDefault)
local Contents, Error = Config.LoadFile(Path, IsDefault)
if Contents ~= nil then
local Name = FileSystem.GetBaseName(Path, true)
Styles[Name] = Contents
StylePaths[Name] = Path
if IsDefault then
table.insert(DefaultStyles, Name)
end
if Set then
API.SetStyle(Name)
end
else
print("Failed to load style '" .. Path .. "'.\n" .. Error)
end
return Contents
end
function API.SetStyle(Name)
if Name == nil then
return false
end
local Other = Styles[Name]
if Other ~= nil then
CurrentStyle = Name
for K, V in pairs(Style) do
local New = Other[K]
if New ~= nil then
if type(V) == "table" then
Utility.CopyValues(Style[K], New)
else
Style[K] = New
end
end
end
return true
else
print("Style '" .. Name .. "' is not loaded.")
end
return false
end
function API.GetStyleNames()
local Result = {}
for K, V in pairs(Styles) do
table.insert(Result, K)
end
return Result
end
function API.GetCurrentStyleName()
return CurrentStyle
end
function API.CopyCurrentStyle(Path)
local NewStyle = Utility.Copy(Styles[CurrentStyle])
local Result, Error = Config.Save(Path, NewStyle)
if Result then
local NewStyleName = FileSystem.GetBaseName(Path, true)
Styles[NewStyleName] = NewStyle
StylePaths[NewStyleName] = Path
API.SetStyle(NewStyleName)
else
print("Failed to create new style at path '" .. Path "'. " .. Error)
end
end
function API.SaveCurrentStyle()
API.StoreCurrentStyle()
local Path = StylePaths[CurrentStyle]
local Settings = Styles[CurrentStyle]
local Result, Error = Config.Save(Path, Settings)
if not Result then
print("Failed to save style '" .. CurrentStyle .. "'. " .. Error)
end
end
function API.StoreCurrentStyle()
Utility.CopyValues(Styles[CurrentStyle], Style)
end
function API.IsDefaultStyle(Name)
return Utility.Contains(DefaultStyles, Name)
end
function API.PushFont(Font)
if Font ~= nil then
Style.Font = Font
table.insert(FontStack, 1, Font)
end
end
function API.PopFont()
if #FontStack > 1 then
table.remove(FontStack, 1)
Style.Font = FontStack[1]
end
end
return Style