LMMS
Loading...
Searching...
No Matches
juce::ComponentDragger Class Reference

#include <juce_ComponentDragger.h>

Public Member Functions

 ComponentDragger ()
virtual ~ComponentDragger ()
void startDraggingComponent (Component *componentToDrag, const MouseEvent &e)
void dragComponent (Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)

Private Attributes

Point< intmouseDownWithinTarget

Detailed Description

An object to take care of the logic for dragging components around with the mouse.

Very easy to use - in your mouseDown() callback, call startDraggingComponent(), then in your mouseDrag() callback, call dragComponent().

When starting a drag, you can give it a ComponentBoundsConstrainer to use to limit the component's position and keep it on-screen.

e.g.

class MyDraggableComp
{
ComponentDragger myDragger;
void mouseDown (const MouseEvent& e)
{
myDragger.startDraggingComponent (this, e);
}
void mouseDrag (const MouseEvent& e)
{
myDragger.dragComponent (this, e, nullptr);
}
};
ComponentDragger()
Definition juce_ComponentDragger.cpp:29
void dragComponent(Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
Definition juce_ComponentDragger.cpp:42
void startDraggingComponent(Component *componentToDrag, const MouseEvent &e)
Definition juce_ComponentDragger.cpp:33
Definition juce_MouseEvent.h:39
* e
Definition inflate.c:1404

@tags{GUI}

Constructor & Destructor Documentation

◆ ComponentDragger()

juce::ComponentDragger::ComponentDragger ( )

Creates a ComponentDragger.

◆ ~ComponentDragger()

juce::ComponentDragger::~ComponentDragger ( )
virtual

Destructor.

Member Function Documentation

◆ dragComponent()

void juce::ComponentDragger::dragComponent ( Component * componentToDrag,
const MouseEvent & e,
ComponentBoundsConstrainer * constrainer )

Call this from your mouseDrag() callback to move the component.

This will move the component, using the given constrainer object to check the new position.

Parameters
componentToDragthe component that you want to drag
ethe current mouse-drag event
constraineran optional constrainer object that should be used to apply limits to the component's position. Pass null if you don't want to constrain the movement.
See also
startDraggingComponent

◆ startDraggingComponent()

void juce::ComponentDragger::startDraggingComponent ( Component * componentToDrag,
const MouseEvent & e )

Call this from your component's mouseDown() method, to prepare for dragging.

Parameters
componentToDragthe component that you want to drag
ethe mouse event that is triggering the drag
See also
dragComponent

Member Data Documentation

◆ mouseDownWithinTarget

Point<int> juce::ComponentDragger::mouseDownWithinTarget
private

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