Dialogues: Create each time or hide?

BlitzMax Forums/MaxGUI Module/Dialogues: Create each time or hide?

TomToad(Posted 2013) [#1]
If I want to create a dialogue box, should I create it once at the start of the program and hide the window, or should I create and destroy it whenever needed? Which way is best, or does it matter?
Example 1 (Create once and Show/Hide)


example 2 (Create When needed, then destroy)




Henri(Posted 2013) [#2]
Hello,

I would say what ever is more convenient to you. I don't see anything wrong with either way.


-Henri


JoshK(Posted 2013) [#3]
Create at startup and hide it.


Henri(Posted 2013) [#4]
On second example I would add HideGadget before FreeGadget as FreeGadget alone might leave ghost trail if parent window isn't redrawed.

-Henri


TomToad(Posted 2013) [#5]
Creating it once, then hiding it seems to be the easiest way to manage it, just wasn't sure if there was any clear advantage to using one method over the other. Thanks. :)


TAS(Posted 2013) [#6]
I have wonder that too. The cleanest looking approach I have found is to keep ever thing inside the dialog function

Function Mydialog()
Global win:tgadget[10] 'preserve values over calls but hidden from Main
If win[0]=null
win[0]=createwindow(......
else
showgadget win[0]
endif

repeat
waitevent()
'handle .....
exit
forever
hidegadget win[0]
end function


jsp(Posted 2013) [#7]
Your example is somewhat different from TomToad's.
He is using hooks and you use a normal WaitEvent loop.
That means your dialog is modal and you can't click on any other window/gadget outside your dialog. Sometimes this is actually needed, but not always.

For what is better CreateGadget... or ShowGadget...
I recommend always to create the window hidden (use WINDOW_HIDDEN flag) and show it when needed, even if you need the window now, because it will less flicker.
When I need the dialog several times I create the dialog again and again and show as needed, so the user can fill them out in parallel.


Henri(Posted 2013) [#8]
I had to wrestle with dialogs myself and this is my take on this:




-Henri