|
Gin
|
Animated grid container with drag-and-drop reordering support. More...
#include <gin_componentgrid.h>
Inherits juce::Component, and juce::Timer.
Classes | |
| struct | DragInfo |
Public Types | |
| enum | Orientation { vertical , horizontal } |
| Grid layout orientation. More... | |
Public Member Functions | |
| ComponentGrid (const juce::String &name={}, Orientation o=horizontal) | |
| Creates a ComponentGrid with the specified name and orientation. | |
| ~ComponentGrid () override | |
| Destructor. | |
| bool | isDragInProgress () |
| Checks if a drag operation is currently in progress. | |
| void | setGap (int gap) |
| Sets the gap/spacing between grid items. | |
| void | setOrientation (Orientation o) |
| Sets the grid layout orientation. | |
| void | timerCallback () override |
| void | mouseDown (const juce::MouseEvent &e) override |
| void | mouseDrag (const juce::MouseEvent &e) override |
| void | mouseUp (const juce::MouseEvent &e) override |
| void | resized () override |
Static Public Member Functions | |
| static bool | isGridDrag (juce::var dragSourceDetails) |
| Checks if a drag source represents a ComponentGrid drag operation. | |
| static int | getDragIndex (juce::var dragSourceDetails) |
| Gets the index of the dragged component from drag source details. | |
Public Attributes | |
| std::function< bool(const juce::MouseEvent &)> | onDragStart |
| Callback invoked when a drag operation starts. | |
| std::function< void(int, int)> | onOrderChanged |
| Callback invoked when items are reordered via drag-and-drop. | |
| std::function< void(int, int)> | onDragFinished |
| Callback invoked when a drag operation completes. | |
Protected Member Functions | |
| void | layoutAnimated () |
| int | componentIndex (juce::Component &c) |
| juce::Array< juce::Rectangle< int > > | getComponentRects () |
Protected Attributes | |
| bool | dragStarted = false |
| bool | dragging = false |
| bool | dragOut = false |
| Orientation | orientation = horizontal |
| int | gap = 1 |
| juce::Array< juce::Component * > | originalOrder |
| juce::ComponentAnimator | animator |
Animated grid container with drag-and-drop reordering support.
ComponentGrid arranges child components in a row or column with smooth animated transitions. Components can be reordered via drag-and-drop, making it ideal for customizable toolbars, tab bars, or any UI where users can rearrange elements.
Key Features:
The grid handles layout and animation automatically. When children are reordered via drag-and-drop, the grid smoothly animates them to their new positions.
Usage:
| ComponentGrid::ComponentGrid | ( | const juce::String & | name = {}, |
| Orientation | o = horizontal |
||
| ) |
Creates a ComponentGrid with the specified name and orientation.
| name | Name for the grid component |
| o | Layout orientation (horizontal or vertical) |
|
override |
Destructor.
| bool ComponentGrid::isDragInProgress | ( | ) |
Checks if a drag operation is currently in progress.
Sets the gap/spacing between grid items.
| gap | Spacing in pixels between items |
| void ComponentGrid::setOrientation | ( | Orientation | o | ) |
Sets the grid layout orientation.
| o | New orientation (horizontal or vertical) |
Checks if a drag source represents a ComponentGrid drag operation.
| dragSourceDetails | Drag source information from JUCE drag-and-drop |
Gets the index of the dragged component from drag source details.
| dragSourceDetails | Drag source information from JUCE drag-and-drop |
|
override |
Timer callback for animations
Mouse down handler for drag initiation
Mouse drag handler for reordering
Mouse up handler for drag completion
|
override |
Resized handler for layout updates
|
protected |
Performs animated layout of all child components
|
protected |
Gets the index of a component in the grid
| c | The component to find |
|
protected |
Calculates the target rectangles for all components
Callback invoked when a drag operation starts.
Return false to prevent dragging. Default behavior allows all drags.
Example:
| MouseEvent | The mouse event that initiated the drag |
Callback invoked when items are reordered via drag-and-drop.
Called after the drag completes and items have been reordered.
Example:
| oldIndex | Original position of the dragged item |
| newIndex | New position after reordering |
Callback invoked when a drag operation completes.
Called when the mouse is released, whether or not reordering occurred.
| oldIndex | Original position of the dragged item |
| newIndex | Final position (may be same as oldIndex if no reorder) |
|
protected |
Current layout orientation
|
protected |
Spacing between items in pixels
|
protected |
Original order before drag
|
protected |
Handles smooth animations