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

## 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);
}
};
juce::ComponentDragger::ComponentDragger
ComponentDragger()
Creates a ComponentDragger.
juce::ComponentDragger::dragComponent
void dragComponent(Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
Call this from your mouseDrag() callback to move the component.
juce::ComponentDragger::startDraggingComponent
void startDraggingComponent(Component *componentToDrag, const MouseEvent &e)
Call this from your component's mouseDown() method, to prepare for dragging.
juce::MouseEvent
Contains position and status information about a mouse event.
Definition juce_MouseEvent.h:48

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

- juce_gui_basics/mouse/juce_ComponentDragger.h

## Public Member Functions

| ComponentDragger ()
| Creates a ComponentDragger.
virtual | ~ComponentDragger ()
| Destructor.
void | startDraggingComponent (Component *componentToDrag, const MouseEvent &e)
| Call this from your component's mouseDown() method, to prepare for dragging.
void | dragComponent (Component *componentToDrag, const MouseEvent &e, ComponentBoundsConstrainer *constrainer)
| Call this from your mouseDrag() callback to move the component.

## Constructors and Destructors

## ComponentDragger()

juce::ComponentDragger::ComponentDragger | ( |  | ) |

Creates a ComponentDragger.

Referenced by dragComponent().

## ~ComponentDragger()

virtual juce::ComponentDragger::~ComponentDragger | ( |  | ) |

virtual

Destructor.

## Member Functions

## startDraggingComponent()

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

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

Parameters

  componentToDrag | the component that you want to drag
  e | the mouse event that is triggering the drag

See also
  dragComponent

## 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

  componentToDrag | the component that you want to drag
  e | the current mouse-drag event
  constrainer | an 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

References ComponentDragger().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited