Add progress bar to AlertWindow() #720
dnaldoog
started this conversation in
Show and tell
Replies: 2 comments 1 reply
-
|
Here is an example of |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Here is another way using |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Here is a way of creating a progress bar within an AlertWindow using an embedded
uiComponentThe secret seems to be you have to declare the
uiComponentas in 1 or 2 below, but not 3 otherwise crashes on both Ctrlr and CtrlX1
PBAR=panel:getModulatorByName("pbar"):getComponent()-- declared in init2
panel:getModulatorByName("pbar"):getComponent()3
mw:addCustomComponent(panel:getComponent("pbar"))I haven't yet been able to get the AlertWindow method addProgressBarComponent working.
init = function(--[[ CtrlrInstance --]] type) progPerc=0 PBAR=panel:getModulatorByName("pbar"):getComponent() end -- -- Called when a component needs repainting -- @comp -- @g http://ctrlr.org/api/class_ctrlr_lua_graphics.html -- see also http://www.rawmaterialsoftware.com/juce/api/classGraphics.html -- paintPbar = function(--[[ CtrlrComponent --]] comp --[[ CtrlrComponent --]], g) g:fillAll(Colour(0xffffcc00)) -- background colour local w, h = comp:getWidth(), comp:getHeight() g:setColour(Colour(0xff99ccff)) -- progress bar colour local r = Rectangle(0, 0, w * progress, h) g:fillRect(r) g:setColour(Colour(0xff000000)) -- font colour g:setFont(13) r = Rectangle(comp:getLocalBounds()) -- centre text in component g:drawText(string.format("%s%%", progPerc), r, Justification(Justification.centred), true) end -- -- Called when a mouse is down on this component -- alert = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) mw = AlertWindow("BULK DATA DUMP SAVE", "Save INTERNAL or CARD data to file?", AlertWindow.QuestionIcon) mw:addButton("INTERNAL ", 1, KeyPress(KeyPress.returnKey), KeyPress()) mw:addButton("CARD", 2, KeyPress(), KeyPress()) mw:addButton("Cancel", 0, KeyPress(KeyPress.escapeKey), KeyPress()) -- mw:addProgressBarComponent(bar) not working if PBAR ~= nil then mw:addCustomComponent(PBAR) end mw:setEscapeKeyCancels(true) local ret = mw:runModalLoop() if ret == 1 then -- mw:setVisible(false) progress=0 timercounter = 0 timer:setCallback(1, TimerCallback) timer:startTimer(1, 600) elseif ret == 2 then utils.warnWindow("OPTION2", "Not set to do anything") mw:setVisible(false) else mw:setVisible(false) end --mw:setVisible(false) end TimerCallback = function(timerId) if timerId == 1 then timercounter = timercounter + 1 progress = round(timercounter / #t, 3) console(string.format("%f %d %d", progress, timercounter, #t)) progPerc=progress*100 PBAR:repaint() mw:repaint() if timercounter >= #t then timer:stopTimer(timerId) progPerc=0 mw:setVisible(false) end end end function round(num, numDecimalPlaces) -- rounding function local mult = 10 ^ (numDecimalPlaces or 0) return math.floor(num * mult + 0.5) / mult end --functionaddProgressBar_4.zip
Beta Was this translation helpful? Give feedback.
All reactions