Base button-event listener class, for receiving events when buttons on the Grabba device are pressed or released.
The following events are supported by this class:
Each event may invoke callbacks in two ways:
By default, each listener object will register itself for callbacks upon construction, and deregister itself at destruction; the enable and disable methods may be used if an object requires manual control over when its callbacks are triggered.
The default behaviour for each event, if not overridden, on an enabled listener object is as follows:
Overrides need not call the superclass' equivalent method unless it is necessary to preserve the delegation (i.e. to support both subclassing and delegation from a single object).
Thread safety: This interface is intended to be thread-safe; any classes deriving or delegating from it should ensure that the relevant methods are callable from any thread.
Instance Methods | |
(void) | - disable |
Disable listening for events from this object, if not already disabled. More... | |
(void) | - enable |
Enable listening for events from this object, if not already enabled. More... | |
(instancetype _Nullable) | - init |
Default initialiser - builds an object then enables event callbacks to it. More... | |
(instancetype _Nullable) | - initWithEnabled: |
Initialiser which allows control over whether event callbacks should be enabled. More... | |
(void) | - leftButtonEvent: |
Callback which is invoked when the left button is pressed or released. More... | |
(void) | - rightButtonEvent: |
Callback which is invoked when the right button is pressed or released. More... | |
Properties | |
ProtocolType _Nullable | delegate |
Delegate for receiving events from non-subclassed listener objects; defaults to nil. More... | |
- (void) disable |
Disable listening for events from this object, if not already disabled.
This will remove the listener object from the relevant event handler, if it had previously been added. Callbacks will no longer be triggered on this object, although they may be re-enabled by calling enable.
- (void) enable |
Enable listening for events from this object, if not already enabled.
This will add the listener object to the relevant event handler, if it has not already been added. Events will then trigger callbacks on this object until it is destroyed or disable is called.
- (instancetype _Nullable) init |
Default initialiser - builds an object then enables event callbacks to it.
nil
if it failed - (instancetype _Nullable) initWithEnabled: | (BOOL) | startEnabled |
Initialiser which allows control over whether event callbacks should be enabled.
startEnabled | If YES, the newly-allocated listener object is added to the relevant event handler, enabling receipt of event callbacks. If NO, no callbacks are received until enable is called. |
nil
if it failed - (void) leftButtonEvent: | (BOOL) | pressed |
Callback which is invoked when the left button is pressed or released.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
pressed | YES if the button has just been pressed, or NO if the button has just been released |
- (void) rightButtonEvent: | (BOOL) | pressed |
Callback which is invoked when the right button is pressed or released.
Override this method to receive callbacks when the object is enabled (via init or enable) and the event is triggered.
pressed | YES if the button has just been pressed, or NO if the button has just been released |
|
readwritenonatomicweakinherited |
Delegate for receiving events from non-subclassed listener objects; defaults to nil.
Delegation may be used as an alternative to subclassing for receiving event callbacks. Any Grabba-defined listener class object (as opposed to a subclass thereof) will pass events on to a delegate, if one has been set and it has implemented the relevant protocol method.
If the delegate is to be written to whilst a callback to it is in progress, the write operation will block until that operation has completed. This ensures thread-safety.