ImFusion SDK 4.3
EventResult Struct Reference

#include <ImFusion/GUI/EventResult.h>

Simple record intended to be used as return value of the a handleInputEvent() function to indicate how to proceed. More...

Detailed Description

Simple record intended to be used as return value of the a handleInputEvent() function to indicate how to proceed.

Its main property is a flag whether to continue or stop the event propagation (other event systems often call this "accepted"). Furthermore, it stores additional optional members describing visual cues or elements that the GUI should show to the user as reaction to the event (e.g. mouse cursor shape, tooltip, context menu).

Since InputEvents are often propagated to a series of handlers until propagation shall stop, the EventResult offers a combine() function to conveniently combine its additional payload (mouse cursor shape, etc.). A typical usage looks like this

EventResult result;
for (InputEventHandler* handler : handlers) {
result.combine(handler->handleInputEvent(event));
if (result.stopPropagation)
return result;
}
return result;
const EventResult & combine(EventResult other)
Combines two results from different event handling functions.
bool stopPropagation
Flag whether the event was accepted and event processing should stop.
Definition EventResult.h:76
EventResult()=default
Creates an empty result indicating to continue event propagation.

Public Types

enum  Propagation { ContinuePropagation = 0 , StopPropagation = 1 }
 Named enumeration used for the readable constructor.
 

Public Member Functions

 EventResult ()=default
 Creates an empty result indicating to continue event propagation.
 
 EventResult (Propagation propagation, std::optional< MouseCursorShape > cursorShape=std::nullopt, std::optional< std::string > tooltip=std::nullopt, std::optional< Menu > contextMenu=std::nullopt)
 Creates an EventResult indicating whether to continue event propagation an optionally a mouse cursor to use.
 
 EventResult (Propagation propagation, std::optional< Menu > contextMenu)
 Convenience constructor overload so that you can write EventResult(<Propagation>, <Menu>) without specifying the nullopt cursor shape and tooltip.
 
const EventResultcombine (EventResult other)
 Combines two results from different event handling functions.
 
EventResult combined (const EventResult &other) const
 Combines two results from different event handling functions.
 

Public Attributes

bool stopPropagation = false
 Flag whether the event was accepted and event processing should stop.
 
std::optional< MouseCursorShapecursorShape
 Optional field to request showing a particular mouse cursor.
 
std::optional< std::stringtooltip
 Optional text to show hovering next to the mouse cursor.
 
std::optional< MenucontextMenu
 An optional menu to show to the user as reaction to the event (usually populated as reaction to a ContextMenuEvent).
 

Constructor & Destructor Documentation

◆ EventResult()

EventResult ( Propagation propagation,
std::optional< MouseCursorShape > cursorShape = std::nullopt,
std::optional< std::string > tooltip = std::nullopt,
std::optional< Menu > contextMenu = std::nullopt )

Creates an EventResult indicating whether to continue event propagation an optionally a mouse cursor to use.

Is implicit by design so that you can write return EventResult::StopPropagation

Member Function Documentation

◆ combine()

const EventResult & combine ( EventResult other)

Combines two results from different event handling functions.

The combination logic is as follows to implement the regular use case of passing input events through a hierarchy of event handlers:

  • stopPropagation: will be determined by logical or of the two input states.
  • cursorShape: If one of the two inputs has an empty cursor it will use the value of the other input. If both results have a value the one with stopPropagation = true will take precedence. If both results have a non-empty cursor and stop the propagation, the value of this has precedence.
  • tooltip: will append the tooltip of other to the ones of this and put a newline break in between if necessary.
  • contextMenu: will append the menu items of other to the ones of this and put a separator in between if necessary.

◆ combined()

EventResult combined ( const EventResult & other) const

Combines two results from different event handling functions.

The combination logic is as follows to implement the regular use case of passing input events through a hierarchy of event handlers:

  • stopPropagation: will be determined by logical or of the two input states.
  • cursorShape: If one of the two inputs has an empty cursor it will use the value of the other input. If both results have a value the one with stopPropagation = true will take precedence. If both results have a non-empty cursor and stop the propagation, the value of this has precedence.
  • tooltip: will append the tooltip of other to the ones of this and put a newline break in between if necessary.
  • contextMenu: will append the menu items of other to the ones of this and put a separator in between if necessary.

The documentation for this struct was generated from the following file:
Search Tab / S to search, Esc to close