-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy paththeme_loader.lua
More file actions
80 lines (73 loc) · 2.84 KB
/
theme_loader.lua
File metadata and controls
80 lines (73 loc) · 2.84 KB
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
-- zemhunt/theme_loader.lua
local mq = require('mq')
local ImGui = require('ImGui')
local LoadTheme = {}
function LoadTheme.shallowcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
else
copy = orig
end
return copy
end
function LoadTheme.PCallString(str)
local func, err = load(str)
if not func then print(err) return false, err end
return pcall(func)
end
function LoadTheme.EvaluateLua(str)
local runEnv = [[mq = require('mq')
%s
]]
return LoadTheme.PCallString(string.format(runEnv, str))
end
function LoadTheme.StartTheme(tName, tTable, mouseOver, mouseHovered, mouseOvaerAlpha)
if mouseOver == nil then mouseOver = false end
if mouseHovered == nil then mouseHovered = false end
if mouseOvaerAlpha == nil then mouseOvaerAlpha = 1 end
local StyleCounter = 0
local ColorCounter = 0
local themeID = 0
if tTable.Theme == nil then return StyleCounter, ColorCounter, themeID end
for tID, tData in pairs(tTable.Theme or {}) do
if tData.Name == tName then
themeID = tID
for _, cData in pairs(tTable.Theme[tID].Color) do
if cData.PropertyName == 'WindowBg' and mouseOver then
if mouseHovered then
ImGui.PushStyleColor(ImGuiCol.WindowBg, ImVec4(cData.Color[1], cData.Color[2], cData.Color[3], 1.0))
ColorCounter = ColorCounter + 1
else
ImGui.PushStyleColor(ImGuiCol.WindowBg, ImVec4(cData.Color[1], cData.Color[2], cData.Color[3], mouseOvaerAlpha))
ColorCounter = ColorCounter + 1
end
else
ImGui.PushStyleColor(ImGuiCol[cData.PropertyName], ImVec4(cData.Color[1], cData.Color[2], cData.Color[3], cData.Color[4]))
ColorCounter = ColorCounter + 1
end
end
if tData['Style'] ~= nil and next(tData['Style']) ~= nil then
for sID, sData in pairs(tTable.Theme[tID].Style) do
if sData.Size ~= nil then
ImGui.PushStyleVar(sID, sData.Size)
StyleCounter = StyleCounter + 1
elseif sData.X ~= nil then
ImGui.PushStyleVar(sID, sData.X, sData.Y)
StyleCounter = StyleCounter + 1
end
end
end
end
end
return ColorCounter, StyleCounter, themeID
end
function LoadTheme.EndTheme(themeColorPop, themeStylePop)
if themeColorPop > 0 then ImGui.PopStyleColor(themeColorPop) end
if themeStylePop > 0 then ImGui.PopStyleVar(themeStylePop) end
end
return LoadTheme