binding gadgets

Just starting out? Need help? Post your questions and find answers here.
mrbungle
Enthusiast
Enthusiast
Posts: 112
Joined: Wed Dec 30, 2020 3:18 am

binding gadgets

Post by mrbungle »

What's the real benefit to binding gadgets? When should we use binding and when should we not?

Thank you
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: binding gadgets

Post by Olli »

These are two equivalents. Just the binding are more flexible and lighter for the syntax.

* Bind/Unbind : enable/disable an event control
* Could be forced by a procedure call or a postevent.
* Main loop is simple more easily readable.
User avatar
Demivec
Addict
Addict
Posts: 4086
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: binding gadgets

Post by Demivec »

Binding of gadgets is one of the two or three options available for processing events in the event loop.

According to the PB Help:
It's an additional way to handle events in PureBasic, which works without problem with the regulars WindowEvent() / WaitWindowEvent() commands. It also allows to have real-time event notifications as the callback can be invoked as soon as the event occurs (useful for ScrollBarGadget(), ScrollAreaGadget() etc.).
If you are not dealing with real-time events as noted above you can also process events equally well by writing out a series of comparisons for each event detected to determine how to respond to it. Gadget events that are bound to a callback still show up in the event loop with the processing of WindowEvent() and WaitWindowEvent() so care should be taken to not inadvertently handling the same events in both a callback via BindGadget() and in the event loop.

The real benefit to binding gadgets is a degree of modularity. You code a procedure for certain gadget's and bind it to the gadget or gadget events without necessarily weaving it into the rest of the processing of the Event Loop. The alternative is to possibly modify the Event Loop each time there are changes in code that change the number and handling of different gadgets.

An Event Loop can be easier to view everything in one place without having to chase down individuals procedures. The more complex the Event Loop the more individual portions are broken out into separate procedures and so the distinction with binding tend to disappear. All differences except the real-time handling as mentioned in the Help quoted above.
mrbungle
Enthusiast
Enthusiast
Posts: 112
Joined: Wed Dec 30, 2020 3:18 am

Re: binding gadgets

Post by mrbungle »

This is helpful. Thank you all.
Rinzwind
Enthusiast
Enthusiast
Posts: 636
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: binding gadgets

Post by Rinzwind »

Wish something similar would exist for low level Windows messages.
Jeff8888
User
User
Posts: 38
Joined: Fri Jan 31, 2020 6:48 pm

Re: binding gadgets

Post by Jeff8888 »

Look at the help for ScrollBarGadget. It shows an example of binding. I have used it to display the value of the scroll bar while moving it, that is while the mouse button is depressed.
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: binding gadgets

Post by Marc56us »

There are not only advantages to the bind method.

- An event will be re-triggered without stopping, whereas the classic method allows you to wait for the end of a block of instructions before returning the hand. This is to be taken into account if the update of an element is dependent on another one.
- If you delete a window and then rebuild it, you have to think about redoing the bindxxx as well since they are attached to the window ID

Bind is for example excellent for displaying a clock, because it will rotate without stopping even if you move a window. On the other hand, it should be avoided for a database.

Fortunately you can use both systems together.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: binding gadgets

Post by mk-soft »

For example, the event #PB_Event_SizeWindow makes a big difference. In WaitWindowEent only the last event is passed on and in BindEvent every event. (Only macOS has a quirk there).

If you write your own controls as modules with the CanvasGadget, you can write the event processing in the module. To do this, store the pointer to the data of your own canvas control with SetGadgetData and retrieve the pointer again for the gadget event with GetGadgetData.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Jeff8888
User
User
Posts: 38
Joined: Fri Jan 31, 2020 6:48 pm

Re: binding gadgets

Post by Jeff8888 »

Look at the help for ScrollBarGadget. It shows an example of binding. I have used it to display the value of the scroll bar while moving it, that is while the mouse button is depressed. ScrollBarGadge only signals an event in the normal event chain when the mouse is no longer depressed so binding is required if you want to show the value of the scroll bar while it is being moved.
Post Reply