对不起,我的英语不好。我做了一个倒计时计时器使用CE图形用户界面自定义进度条使用CE面板宽度。
对于倒计时计时器是不成问题的,用下面的函数就可以正常工作了。
function performWithDelay(delay,onFinish,onTick,onTickInterval)
if type(delay)~='number' -- mandatory
then error('delay is not a number') end
if type(onFinish)~='function' -- mandatory
then error('onFinish is not a function') end
if onTick and type(onTick)~='function' -- optional
then error('onTick is not a function') end
if onTickInterval and type(onTickInterval)~='number' -- optional, default 1 second
then error('onTickInterval is not a number') end
onTickInterval = onTickInterval or 1000 -- default 1 second
local f = function (t) -- thread function start
local getTickCount = getTickCount
local startTick = getTickCount()
local endTick = startTick + delay
local nextOnTick = startTick + onTickInterval
local ticks
if onTick then
while true do
ticks=getTickCount()
if nextOnTick<ticks then
nextOnTick=ticks+onTickInterval
synchronize(onTick,endTick-ticks)
end
if endTick<ticks then break end
sleep(1)
end
else
while true do
ticks=getTickCount()
if endTick<ticks then break end
sleep(1)
end
end
if onFinish then synchronize(onFinish) end
end -- thread function end
local t = createNativeThreadSuspended(f)
t.name = 'performWithDelay thread'
t.resume()
end
function showTimeLeft(millisecondsLeft)
local totalSeconds = millisecondsLeft // 1000
local deciseconds = (millisecondsLeft % 1000) // 100
LabelTimer.Caption = os.date("!%M:%S",totalSeconds)..'.'..deciseconds
end
function whenFinished()
LabelTimer.Caption = "00:00.0"
-- do something
ButtonTimer.Enabled = true
end
function startCountDown()
-- do something
performWithDelay(20000,whenFinished,showTimeLeft,10)
--- 20000 = 20 seconds
ButtonTimer.Enabled = false
end
ButtonTimer.onClick = startCountDown
现在,对于自定义进度条,我已经创建了一个计时器和变量:
progressbar.width = 0 -- at start
progessbar max. width = 208 -- at the end
time = 20 seconds
timer interval = 100 (1/10 seconds)
progess bar step = ??
如何使用纯Lua脚本计算进度条宽度,使其在倒计时计时器=0时达到最大宽度?
发布于 2019-06-08 10:20:23
已解决:
function start()
st = edtSpTimer.Text --- input how many seconds from user
if tonumber(st) == nil then return nil end -- accept only number
sec = tonumber(st) -- convert text to number
pnPBar.Width = 208 -- set panel width as maximum progrees bar value
step = 208 / sec -- set step by value
tmr.Enabled = true -- triggering a timer
performWithDelay(st*1000,whenFinished,showTimeLeft,10)
end
function bar()
sec = sec - 1 -- counter down the seconds value
pnPBar.width = pnPBar.width - step -- decrease progress bar width
end
tmr = createTimer() -- a timer
tmr.interval = 1000 -- set interval to 1000 = 1 second
tmr.enabled = false
tmr.OnTimer = bar
https://stackoverflow.com/questions/56477948
复制相似问题