Browse Source

Rename ui::ScrollBar to Scrollbar. (Wikipedia says "scrollbar" rather than "scroll bar".)

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
18f8283e34
5 changed files with 44 additions and 40 deletions
  1. +5
    -4
      include/ui/ScrollWidget.hpp
  2. +6
    -3
      include/ui/Scrollbar.hpp
  3. +6
    -6
      src/app/RackScrollWidget.cpp
  4. +19
    -19
      src/ui/ScrollWidget.cpp
  5. +8
    -8
      src/ui/Scrollbar.cpp

+ 5
- 4
include/ui/ScrollWidget.hpp View File

@@ -1,24 +1,25 @@
#pragma once #pragma once
#include <ui/common.hpp> #include <ui/common.hpp>
#include <widget/OpaqueWidget.hpp> #include <widget/OpaqueWidget.hpp>
#include <ui/ScrollBar.hpp>
#include <ui/Scrollbar.hpp>




namespace rack { namespace rack {
namespace ui { namespace ui {




/** Handles a container with ScrollBar */
/** Handles a container with Scrollbar */
struct ScrollWidget : widget::OpaqueWidget { struct ScrollWidget : widget::OpaqueWidget {
struct Internal; struct Internal;
Internal* internal; Internal* internal;


widget::Widget* container; widget::Widget* container;
ScrollBar* horizontalScrollBar;
ScrollBar* verticalScrollBar;
Scrollbar* horizontalScrollbar;
Scrollbar* verticalScrollbar;


math::Vec offset; math::Vec offset;
math::Rect containerBox; math::Rect containerBox;
bool hideScrollbars = false;


ScrollWidget(); ScrollWidget();
void scrollTo(math::Rect r); void scrollTo(math::Rect r);


include/ui/ScrollBar.hpp → include/ui/Scrollbar.hpp View File

@@ -8,14 +8,14 @@ namespace ui {




/** Parent must be a ScrollWidget */ /** Parent must be a ScrollWidget */
struct ScrollBar : widget::OpaqueWidget {
struct Scrollbar : widget::OpaqueWidget {
struct Internal; struct Internal;
Internal* internal; Internal* internal;


bool vertical = false; bool vertical = false;


ScrollBar();
~ScrollBar();
Scrollbar();
~Scrollbar();
void draw(const DrawArgs& args) override; void draw(const DrawArgs& args) override;
void onButton(const event::Button& e) override; void onButton(const event::Button& e) override;
void onDragStart(const event::DragStart& e) override; void onDragStart(const event::DragStart& e) override;
@@ -24,5 +24,8 @@ struct ScrollBar : widget::OpaqueWidget {
}; };




DEPRECATED typedef Scrollbar ScrollBar;


} // namespace ui } // namespace ui
} // namespace rack } // namespace rack

+ 6
- 6
src/app/RackScrollWidget.cpp View File

@@ -81,15 +81,15 @@ void RackScrollWidget::draw(const DrawArgs& args) {
bool horizontalVisible; bool horizontalVisible;
bool verticalVisible; bool verticalVisible;
if (fullscreen) { if (fullscreen) {
horizontalVisible = horizontalScrollBar->visible;
verticalVisible = verticalScrollBar->visible;
horizontalScrollBar->visible = false;
verticalScrollBar->visible = false;
horizontalVisible = horizontalScrollbar->visible;
verticalVisible = verticalScrollbar->visible;
horizontalScrollbar->visible = false;
verticalScrollbar->visible = false;
} }
ScrollWidget::draw(args); ScrollWidget::draw(args);
if (fullscreen) { if (fullscreen) {
horizontalScrollBar->visible = horizontalVisible;
verticalScrollBar->visible = verticalVisible;
horizontalScrollbar->visible = horizontalVisible;
verticalScrollbar->visible = verticalVisible;
} }
} }




+ 19
- 19
src/ui/ScrollWidget.cpp View File

@@ -13,15 +13,15 @@ ScrollWidget::ScrollWidget() {
container = new widget::Widget; container = new widget::Widget;
addChild(container); addChild(container);


horizontalScrollBar = new ScrollBar;
horizontalScrollBar->vertical = false;
horizontalScrollBar->hide();
addChild(horizontalScrollBar);
verticalScrollBar = new ScrollBar;
verticalScrollBar->vertical = true;
verticalScrollBar->hide();
addChild(verticalScrollBar);
horizontalScrollbar = new Scrollbar;
horizontalScrollbar->vertical = false;
horizontalScrollbar->hide();
addChild(horizontalScrollbar);
verticalScrollbar = new Scrollbar;
verticalScrollbar->vertical = true;
verticalScrollbar->hide();
addChild(verticalScrollbar);
} }




@@ -70,15 +70,15 @@ void ScrollWidget::step() {
container->box.pos = offset.neg().round(); container->box.pos = offset.neg().round();


// Make scrollbars visible only if there is a positive range to scroll. // Make scrollbars visible only if there is a positive range to scroll.
horizontalScrollBar->setVisible(offsetBounds.size.x > 0.f);
verticalScrollBar->setVisible(offsetBounds.size.y > 0.f);
horizontalScrollbar->setVisible(offsetBounds.size.x > 0.f);
verticalScrollbar->setVisible(offsetBounds.size.y > 0.f);


// Reposition and resize scroll bars // Reposition and resize scroll bars
math::Vec inner = box.size.minus(math::Vec(verticalScrollBar->box.size.x, horizontalScrollBar->box.size.y));
horizontalScrollBar->box.pos.y = inner.y;
verticalScrollBar->box.pos.x = inner.x;
horizontalScrollBar->box.size.x = verticalScrollBar->isVisible() ? inner.x : box.size.x;
verticalScrollBar->box.size.y = horizontalScrollBar->isVisible() ? inner.y : box.size.y;
math::Vec inner = box.size.minus(math::Vec(verticalScrollbar->box.size.x, horizontalScrollbar->box.size.y));
horizontalScrollbar->box.pos.y = inner.y;
verticalScrollbar->box.pos.x = inner.x;
horizontalScrollbar->box.size.x = verticalScrollbar->isVisible() ? inner.x : box.size.x;
verticalScrollbar->box.size.y = horizontalScrollbar->isVisible() ? inner.y : box.size.y;
} }




@@ -88,7 +88,7 @@ void ScrollWidget::onButton(const event::Button& e) {
return; return;


// Consume right button only if the scrollbars are visible // Consume right button only if the scrollbars are visible
if (!(horizontalScrollBar->isVisible() || verticalScrollBar->isVisible()))
if (!(horizontalScrollbar->isVisible() || verticalScrollbar->isVisible()))
return; return;


if (e.button == GLFW_MOUSE_BUTTON_MIDDLE) { if (e.button == GLFW_MOUSE_BUTTON_MIDDLE) {
@@ -106,7 +106,7 @@ void ScrollWidget::onDragStart(const event::DragStart& e) {


void ScrollWidget::onDragMove(const event::DragMove& e) { void ScrollWidget::onDragMove(const event::DragMove& e) {
// Scroll only if the scrollbars are visible // Scroll only if the scrollbars are visible
if (!(horizontalScrollBar->isVisible() || verticalScrollBar->isVisible()))
if (!(horizontalScrollbar->isVisible() || verticalScrollbar->isVisible()))
return; return;


math::Vec offsetDelta = e.mouseDelta.div(getAbsoluteZoom()); math::Vec offsetDelta = e.mouseDelta.div(getAbsoluteZoom());
@@ -120,7 +120,7 @@ void ScrollWidget::onHoverScroll(const event::HoverScroll& e) {
return; return;


// Scroll only if the scrollbars are visible // Scroll only if the scrollbars are visible
if (!(horizontalScrollBar->isVisible() || verticalScrollBar->isVisible()))
if (!(horizontalScrollbar->isVisible() || verticalScrollbar->isVisible()))
return; return;


math::Vec scrollDelta = e.scrollDelta; math::Vec scrollDelta = e.scrollDelta;


src/ui/ScrollBar.cpp → src/ui/Scrollbar.cpp View File

@@ -1,4 +1,4 @@
#include <ui/ScrollBar.hpp>
#include <ui/Scrollbar.hpp>
#include <ui/ScrollWidget.hpp> #include <ui/ScrollWidget.hpp>
#include <context.hpp> #include <context.hpp>
#include <window.hpp> #include <window.hpp>
@@ -11,16 +11,16 @@ namespace ui {
// Internal not currently used // Internal not currently used




ScrollBar::ScrollBar() {
Scrollbar::Scrollbar() {
box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT); box.size = math::Vec(BND_SCROLLBAR_WIDTH, BND_SCROLLBAR_HEIGHT);
} }




ScrollBar::~ScrollBar() {
Scrollbar::~Scrollbar() {
} }




void ScrollBar::draw(const DrawArgs& args) {
void Scrollbar::draw(const DrawArgs& args) {
ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent); ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent);
assert(sw); assert(sw);


@@ -36,7 +36,7 @@ void ScrollBar::draw(const DrawArgs& args) {
} }




void ScrollBar::onButton(const event::Button& e) {
void Scrollbar::onButton(const event::Button& e) {
if (e.button == GLFW_MOUSE_BUTTON_LEFT && e.action == GLFW_PRESS) { if (e.button == GLFW_MOUSE_BUTTON_LEFT && e.action == GLFW_PRESS) {
ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent); ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent);
assert(sw); assert(sw);
@@ -58,15 +58,15 @@ void ScrollBar::onButton(const event::Button& e) {
} }




void ScrollBar::onDragStart(const event::DragStart& e) {
void Scrollbar::onDragStart(const event::DragStart& e) {
} }




void ScrollBar::onDragEnd(const event::DragEnd& e) {
void Scrollbar::onDragEnd(const event::DragEnd& e) {
} }




void ScrollBar::onDragMove(const event::DragMove& e) {
void Scrollbar::onDragMove(const event::DragMove& e) {
ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent); ScrollWidget* sw = dynamic_cast<ScrollWidget*>(parent);
assert(sw); assert(sw);



Loading…
Cancel
Save