Browse Source

Add Widget::isDescendantOf(). Only scroll RackScrollWidget when dragging a child of its container with the left mouse button.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
d847d9791b
3 changed files with 14 additions and 1 deletions
  1. +3
    -0
      include/widget/Widget.hpp
  2. +2
    -1
      src/app/RackScrollWidget.cpp
  3. +9
    -0
      src/widget/Widget.cpp

+ 3
- 0
include/widget/Widget.hpp View File

@@ -54,6 +54,9 @@ struct Widget : WeakBase {
*/ */
virtual math::Rect getChildrenBoundingBox(); virtual math::Rect getChildrenBoundingBox();
virtual math::Rect getVisibleChildrenBoundingBox(); virtual math::Rect getVisibleChildrenBoundingBox();
/** Returns whether `ancestor` is a parent or distant parent of this widget.
*/
bool isDescendantOf(Widget* ancestor);
/** Returns `v` (given in local coordinates) transformed into the coordinate system of `ancestor`. /** Returns `v` (given in local coordinates) transformed into the coordinate system of `ancestor`.
*/ */
virtual math::Vec getRelativeOffset(math::Vec v, Widget* ancestor); virtual math::Vec getRelativeOffset(math::Vec v, Widget* ancestor);


+ 2
- 1
src/app/RackScrollWidget.cpp View File

@@ -98,7 +98,8 @@ void RackScrollWidget::step() {
// Scroll rack if dragging cable near the edge of the screen // Scroll rack if dragging cable near the edge of the screen
math::Vec pos = APP->scene->mousePos; math::Vec pos = APP->scene->mousePos;
math::Rect viewport = getViewport(box.zeroPos()); math::Rect viewport = getViewport(box.zeroPos());
if (APP->event->getDraggedWidget()) {
widget::Widget* draggedWidget = APP->event->getDraggedWidget();
if (draggedWidget && draggedWidget->isDescendantOf(container) && APP->event->dragButton == GLFW_MOUSE_BUTTON_LEFT) {
float margin = 20.0; float margin = 20.0;
float speed = 15.0; float speed = 15.0;
if (pos.x <= viewport.pos.x + margin) if (pos.x <= viewport.pos.x + margin)


+ 9
- 0
src/widget/Widget.cpp View File

@@ -112,6 +112,15 @@ math::Rect Widget::getVisibleChildrenBoundingBox() {
} }




bool Widget::isDescendantOf(Widget* ancestor) {
if (!parent)
return false;
if (parent == ancestor)
return true;
return parent->isDescendantOf(ancestor);
}


math::Vec Widget::getRelativeOffset(math::Vec v, Widget* ancestor) { math::Vec Widget::getRelativeOffset(math::Vec v, Widget* ancestor) {
if (this == ancestor) if (this == ancestor)
return v; return v;


Loading…
Cancel
Save