Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
component_dragger.hpp File Reference

ComponentDragger — drag-to-move helper for any View. More...

#include <algorithm>
#include <pulp/view/geometry.hpp>
#include <pulp/view/view.hpp>

Go to the source code of this file.

Classes

class  pulp::view::ComponentDragger

Namespaces

namespace  pulp
namespace  pulp::view
 Hover-cursor tracking for platform window hosts.

Detailed Description

ComponentDragger — drag-to-move helper for any View.

A ComponentDragger adds "click and drag to move me within my parent" behavior to any View. It is intentionally a free helper (not a mixin) so that owners stay in control of which mouse phases get forwarded.

Usage:

ComponentDragger dragger;
class DraggableBox : public View {
ComponentDragger dragger;
public:
void on_mouse_event(const MouseEvent& e) override {
if (e.isPress()) dragger.start_dragging(*this, e.position);
else if (e.isDrag()) dragger.drag_view(*this, e.position);
}
};

start_dragging() snapshots the drag origin (in the dragged view's local coordinates) plus the view's bounds at gesture start. drag_view() translates the bounds by the delta between the current pointer position and that snapshot, optionally constraining the new origin so the view stays inside its parent's local bounds.

Headless-friendly: no window host, no scheduler. Pure arithmetic over the dragged view's bounds; tests can call start_dragging / drag_view directly without simulating real mouse events.

License-lineage note: the name is Pulp-native. The behavior mirrors a well-trodden idiom across UI toolkits, but the implementation here is independent.