51 mouse_start_ = mouse_local;
52 bounds_start_ =
view.bounds();
61 const Point delta{mouse_local.
x - mouse_start_.x,
62 mouse_local.
y - mouse_start_.y};
63 Rect target = bounds_start_;
67 if (constrain_to_parent_) {
68 if (
auto*
p =
view.parent()) {
69 const Rect parent_local =
p->local_bounds();
70 target.
x = std::clamp(target.
x,
72 std::max(parent_local.
x,
74 target.
y = std::clamp(target.
y,
76 std::max(parent_local.
y,
80 view.set_bounds(target);
108 bool active_ =
false;
109 bool constrain_to_parent_ =
true;
110 Point mouse_start_{};
111 Rect bounds_start_{};
ComponentDragger()=default
std::function< void(Rect)> on_drag
Optional callbacks for tests / app glue.
Definition component_dragger.hpp:104
Rect bounds_start() const
Dragged view's bounds captured at start_dragging.
Definition component_dragger.hpp:101
void start_dragging(View &view, Point mouse_local)
Begin a drag gesture.
Definition component_dragger.hpp:50
bool is_dragging() const
Definition component_dragger.hpp:96
bool constrain_to_parent() const
Definition component_dragger.hpp:94
std::function< void()> on_end
Definition component_dragger.hpp:105
void drag_view(View &view, Point mouse_local)
Continue a drag gesture.
Definition component_dragger.hpp:59
Point mouse_start() const
Mouse-local press position captured at start_dragging.
Definition component_dragger.hpp:99
void end_dragging()
End the gesture.
Definition component_dragger.hpp:86
void set_constrain_to_parent(bool yes)
When true (the default), drag_view clamps the dragged view's origin so it stays fully inside the pare...
Definition component_dragger.hpp:93
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
@ p
Definition input_events.hpp:40
Definition geometry.hpp:20
float x
Definition geometry.hpp:21
float y
Definition geometry.hpp:21
Axis-aligned rectangle in continuous (float) coordinates.
Definition geometry.hpp:52
float x
Definition geometry.hpp:53
constexpr float right() const
Definition geometry.hpp:55
float height
Definition geometry.hpp:53
float width
Definition geometry.hpp:53
float y
Definition geometry.hpp:53
constexpr float bottom() const
Definition geometry.hpp:56