@@ -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); | ||||
@@ -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) | ||||
@@ -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; | ||||