Gin
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
LambdaMouseListener Class Reference

Mouse listener that uses std::function callbacks instead of virtual overrides. More...

#include <gin_asyncutilities.h>

Inherits juce::MouseListener.

Public Member Functions

 LambdaMouseListener ()=default
 

Public Attributes

std::function< void(const juce::MouseEvent &)> onMouseMove
 
std::function< void(const juce::MouseEvent &)> onMouseEnter
 
std::function< void(const juce::MouseEvent &)> onMouseExit
 
std::function< void(const juce::MouseEvent &)> onMouseDown
 
std::function< void(const juce::MouseEvent &)> onMouseDrag
 
std::function< void(const juce::MouseEvent &)> onMouseUp
 
std::function< void(const juce::MouseEvent &)> onMouseDoubleClick
 
std::function< void(const juce::MouseEvent &, const juce::MouseWheelDetails &)> onMouseWheelMove
 
std::function< void(const juce::MouseEvent &, float)> onMouseMagnify
 

Detailed Description

Mouse listener that uses std::function callbacks instead of virtual overrides.

LambdaMouseListener provides a convenient alternative to juce::MouseListener by accepting lambda functions for each mouse event type. This is particularly useful when adding a mouse listener to a component to monitor its child components, avoiding the "double event" problem where the component would receive both its own mouse events and the forwarded ones from being its own listener.

Key Features:

Available Callbacks:

Only assign callbacks for the events you need. Unassigned callbacks are safely ignored.

Usage:

// Monitor child component mouse events
mouseMonitor.onMouseDown = [this](const MouseEvent& e) {
DBG("Mouse clicked at: " + e.position.toString());
};
mouseMonitor.onMouseDrag = [this](const MouseEvent& e) {
handleDrag(e.getDistanceFromDragStart());
};
// Add to child component (not to self!)
childComponent.addMouseListener(&mouseMonitor, true);
// Multiple event types
listener.onMouseEnter = [](const MouseEvent& e) { showTooltip(); };
listener.onMouseExit = [](const MouseEvent& e) { hideTooltip(); };
listener.onMouseWheelMove = [](const MouseEvent& e, const MouseWheelDetails& w) {
zoom(w.deltaY);
};
Mouse listener that uses std::function callbacks instead of virtual overrides.
Definition gin_asyncutilities.h:190
A lightweight 2D point class for projects that don't use juce_graphics.
Definition gin_point.h:25
See also
juce::MouseListener, juce::MouseEvent

Constructor & Destructor Documentation

◆ LambdaMouseListener()

LambdaMouseListener::LambdaMouseListener ( )
default

Member Data Documentation

◆ onMouseMove

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseMove

◆ onMouseEnter

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseEnter

◆ onMouseExit

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseExit

◆ onMouseDown

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseDown

◆ onMouseDrag

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseDrag

◆ onMouseUp

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseUp

◆ onMouseDoubleClick

std::function<void (const juce::MouseEvent&)> LambdaMouseListener::onMouseDoubleClick

◆ onMouseWheelMove

std::function<void (const juce::MouseEvent&, const juce::MouseWheelDetails&)> LambdaMouseListener::onMouseWheelMove

◆ onMouseMagnify

std::function<void (const juce::MouseEvent&, float)> LambdaMouseListener::onMouseMagnify

The documentation for this class was generated from the following file: