| 38 | |
| 39 | |
| 40 | void Scrollbar::onButton(const ButtonEvent& e) { |
| 41 | if (e.button == GLFW_MOUSE_BUTTON_LEFT && e.action == GLFW_PRESS) { |
| 42 | ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent); |
| 43 | assert(sw); |
| 44 | |
| 45 | float pos = e.pos[vertical]; |
| 46 | pos /= box.size[vertical]; |
| 47 | float handleOffset = sw->getHandleOffset()[vertical]; |
| 48 | float handleSize = sw->getHandleSize()[vertical]; |
| 49 | float handlePos = math::rescale(handleOffset, 0.f, 1.f, handleSize / 2.f, 1.f - handleSize / 2.f); |
| 50 | |
| 51 | // Check if user clicked on handle |
| 52 | if (std::fabs(pos - handlePos) > handleSize / 2.f) { |
| 53 | // Jump to absolute position of the handle |
| 54 | float offset = math::rescale(pos, handleSize / 2.f, 1.f - handleSize / 2.f, 0.f, 1.f); |
| 55 | sw->offset[vertical] = sw->containerBox.pos[vertical] + offset * (sw->containerBox.size[vertical] - sw->box.size[vertical]); |
| 56 | } |
| 57 | } |
| 58 | OpaqueWidget::onButton(e); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void Scrollbar::onDragStart(const DragStartEvent& e) { |
nothing calls this directly
no test coverage detected