MCPcopy Create free account
hub / github.com/VCVRack/Rack / onButton

Method onButton

src/ui/Scrollbar.cpp:40–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38
39
40void 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
62void Scrollbar::onDragStart(const DragStartEvent& e) {

Callers

nothing calls this directly

Calls 4

fabsFunction · 0.85
getHandleOffsetMethod · 0.80
getHandleSizeMethod · 0.80
rescaleFunction · 0.50

Tested by

no test coverage detected