- Версия MoonLoader
- .026-beta
lua:
LastActiveTime = {}
LastActive = {}
function imgui.ToggleButton(str_id, bool)
local rBool = false
local p = imgui.GetCursorScreenPos()
local draw_list = imgui.GetWindowDrawList()
local height = 20
local width = height * 1.55
local radius = height * 0.50
if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
bool[0] = not bool[0]
rBool = true
LastActiveTime[tostring(str_id)] = imgui.GetTime()
LastActive[tostring(str_id)] = true
end
local hovered = imgui.IsItemHovered()
if str_id ~= "" then
imgui.SameLine()
imgui.SetCursorPosY(imgui.GetCursorPosY()+3)
text = str_id:find("##") and str_id:match("(.*)##.*") or str_id
if text ~= "" and text ~= nil then
imgui.Text(text)
end
end
local t = bool[0] and 1.0 or 0.0
if LastActive[tostring(str_id)] then
local time = imgui.GetTime() - LastActiveTime[tostring(str_id)]
if time <= 0.13 then
local t_anim = ImSaturate(time / 0.13)
t = bool[0] and 1.0 + t_anim or 1.0 - t_anim
else
LastActive[tostring(str_id)] = false
end
end
local col_bg = imgui.ColorConvertFloat4ToU32(imgui.ImVec4(100 / 255, 100 / 255, 100 / 255, hovered and 220 or 180 / 255))
draw_list:AddRectFilled(
imgui.ImVec2(p.x, p.y + (height / 8)),
imgui.ImVec2(p.x + width, p.y + (height - (height / 8))),
col_bg, 10
)
draw_list:AddRectFilled(
imgui.ImVec2(p.x + (bool[0] and radius / 2 or 0) + t * (width - radius * 2.0), p.y + (height / 8)),
imgui.ImVec2(p.x + (bool[0] and 30 or 15), p.y + (height - (height / 8))),
imgui.ColorConvertFloat4ToU32(imgui.GetStyle().Colors[imgui.Col.Text]),
6, 1 + (bool[0] and 9 or 4)
)
return rBool
end
Вложения
Последнее редактирование: