Countdown TImer With Custom Progress Bar in CE Lua

Keywords´╝Ü lua

Question: 

Sorry for my bad English. I make a countdown timer using CE GUI with custom progress bar using CE Panel width.

For countdown timer is not a problem, with this function below it work properly.

    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

Now, for custom progress bar, I have create a timer and variables has known:

  progressbar.width = 0  -- at start
  progessbar max. width = 208  -- at the end
  time = 20 seconds
  timer interval = 100  (1/10 seconds)
  progess bar step = ??

How to calculating progress bar width to reach maximum width when countdown timer = 0 using pure Lua script?.

Answers: