- 56
- 1
- Версия MoonLoader
- .026-beta
Функция создания:
Lua:
function imgui.ToggleButton(str_id, bool)
local rBool = false
if LastActiveTime == nil then
LastActiveTime = {}
end
if LastActive == nil then
LastActive = {}
end
local function ImSaturate(f)
return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
end
local p = imgui.GetCursorScreenPos()
local draw_list = imgui.GetWindowDrawList()
local height = imgui.GetTextLineHeightWithSpacing() + (imgui.GetStyle().FramePadding.y / 2)
local width = height * 1.55
local radius = height * 0.50
local ANIM_SPEED = 0.15
if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
bool.v = not bool.v
rBool = true
LastActiveTime[tostring(str_id)] = os.clock()
LastActive[str_id] = true
end
local t = bool.v and 1.0 or 0.0
if LastActive[str_id] then
local time = os.clock() - LastActiveTime[tostring(str_id)]
if time <= ANIM_SPEED then
local t_anim = ImSaturate(time / ANIM_SPEED)
t = bool.v and t_anim or 1.0 - t_anim
else
LastActive[str_id] = false
end
end
local col_bg
if imgui.IsItemHovered() then
col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
else
col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBg])
end
draw_list:AddRectFilled(p, imgui.ImVec2(p.x + width, p.y + height), col_bg, height * 0.5)
draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 1.5, imgui.GetColorU32(bool.v and imgui.GetStyle().Colors[imgui.Col.ButtonActive] or imgui.GetStyle().Colors[imgui.Col.Button]))
return rBool
end