--[[
bool result, int edit time = imgui.Calendar(const char,button name&os.date format,int unix time,table name days,imgui.ImVec2 size button)
]]
function imgui.Calendar(label,buttonName,time,days,sizebutton)
days = days or {['mo'] = 'Mo',['tu'] = 'Tu',['we'] = 'We',['th'] = 'Th',['fr'] = 'Fr',['sa'] = 'Sa',['su'] = 'Su',}
local daysInMonths = {31,28,31,30,31,30,31,31,30,31,30,31}
if imgui_calendar == nil then imgui_calendar = {} end
if imgui_calendar[label] == nil then imgui_calendar[label] = {
previousDate = time
} end
local t,editTime = imgui_calendar[label],time
if imgui.Button(os.date(buttonName,time),sizebutton or imgui.ImVec2(0,0)) then
imgui.OpenPopup(label)
end
if imgui.BeginPopup(label) then
imgui.SetCursorPosX(imgui.GetWindowWidth() /2 - imgui.CalcTextSize(os.date('%B %Y',time)).x /2)
imgui.Text(os.date('%B %Y',time))
local Y = imgui.GetCursorPosY()-imgui.CalcTextSize(os.date('%B %Y',time)).y
if t.previousDate ~= time then
imgui.SetCursorPosX(imgui.GetWindowWidth() /2 - imgui.CalcTextSize('previous date '..os.date('%d.%m.%Y',t.previousDate)).x /2)
imgui.Text('previous date '..os.date('%d.%m.%Y',t.previousDate))
end
imgui.Spacing()
imgui.Columns(7,'_',true)
for k,v in pairs(days) do
imgui.SetCursorPosX((imgui.GetColumnOffset() + (imgui.GetColumnWidth() / 2)) - imgui.CalcTextSize(tostring(v)).x / 2)
imgui.Text(v)
imgui.NextColumn()
end
for i = 1,daysInMonths[tonumber(os.date('%m',time))] do
if i == 1 then
local K = 0
for k,v in pairs(days) do
K = K + 1
if (os.date('%a',(time-(86400*((tonumber(os.date('%d',time)))-1) ))):lower()):sub(1,2) == k then
for i = 1,K-1 do
imgui.NextColumn()
end
end
end
end
imgui.SetCursorPosX((imgui.GetColumnOffset() + (imgui.GetColumnWidth() / 2)) - imgui.CalcTextSize(tostring(i)).x+5 / 2)
imgui.PushStyleColor(23,imgui.GetStyle().Colors[(os.date('%d',time):gsub('^0','') == tostring(i) and 25 or 23)] )
if imgui.Button(tostring(i)) then
time = os.time({year = os.date("%Y",time), month = os.date('%m',time), day = i,hour = os.date('%H',time), min = os.date('%M',time), sec = os.date('%S',time), isdst = false})
end
imgui.PopStyleColor()
imgui.NextColumn()
end
imgui.Columns(1)
imgui.Text(string.rep('\t',15))
-- <|>
imgui.SetCursorPos(imgui.ImVec2(imgui.GetWindowWidth()-imgui.CalcTextSize('>').x-16,Y-2.5))
if imgui.SmallButton('>') then
time = os.time({year = os.date("%Y",time), month = os.date('%m',time)+1, day = 1,hour = os.date('%H',time), min = os.date('%M',time), sec = os.date('%S',time), isdst = false})
end
imgui.SetCursorPos(imgui.ImVec2(6,Y-2.5))
if imgui.SmallButton('<') then
time = os.time({year = os.date("%Y",time), month = os.date('%m',time)-1, day = 1,hour = os.date('%H',time), min = os.date('%M',time), sec = os.date('%S',time), isdst = false})
end
imgui.EndPopup()
end
if not imgui.IsPopupOpen(label) then imgui_calendar[label] = nil end
return editTime ~= time, time
end