diff --git a/include/rack.hpp b/include/rack.hpp index 16424230..f729b9c2 100644 --- a/include/rack.hpp +++ b/include/rack.hpp @@ -41,9 +41,9 @@ #include #include #include -#include #include #include +#include #include #include diff --git a/include/ui/Button.hpp b/include/ui/Button.hpp index 7f7c7e61..aef03275 100644 --- a/include/ui/Button.hpp +++ b/include/ui/Button.hpp @@ -8,6 +8,13 @@ namespace rack { namespace ui { +/** A clickable button with text. +Dispatches Action event when clicked. + +If quantity is set, its value is set to 1.0 when pressed, 0.0 when released. + +If text is not set, the quantity label is used. +*/ struct Button : widget::OpaqueWidget { std::string text; /** Not owned. Tracks the pressed state of the button.*/ diff --git a/include/ui/ChoiceButton.hpp b/include/ui/ChoiceButton.hpp index e64123c1..847ddc06 100644 --- a/include/ui/ChoiceButton.hpp +++ b/include/ui/ChoiceButton.hpp @@ -7,6 +7,8 @@ namespace rack { namespace ui { +/** Button with a dropdown icon on its right. +*/ struct ChoiceButton : Button { void draw(const DrawArgs& args) override; }; diff --git a/include/ui/IconButton.hpp b/include/ui/IconButton.hpp deleted file mode 100644 index 01d540d4..00000000 --- a/include/ui/IconButton.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include -#include -#include -#include - - -namespace rack { -namespace ui { - - -struct IconButton : Button { - widget::FramebufferWidget* fw; - widget::SvgWidget* sw; - - IconButton(); - void setSvg(std::shared_ptr svg); - DEPRECATED void setSVG(std::shared_ptr svg) { - setSvg(svg); - } -}; - - -} // namespace ui -} // namespace rack diff --git a/include/ui/OptionButton.hpp b/include/ui/OptionButton.hpp index 3f541259..c5e99007 100644 --- a/include/ui/OptionButton.hpp +++ b/include/ui/OptionButton.hpp @@ -1,21 +1,16 @@ #pragma once -#include #include -#include +#include namespace rack { namespace ui { -struct OptionButton : widget::OpaqueWidget { - std::string text; - /** Not owned. Tracks the pressed state of the button.*/ - Quantity* quantity = NULL; - - OptionButton(); +/** Behaves like a RadioButton and appears with a checkmark beside text. +*/ +struct OptionButton : RadioButton { void draw(const DrawArgs& args) override; - void onDragDrop(const DragDropEvent& e) override; }; diff --git a/include/ui/RadioButton.hpp b/include/ui/RadioButton.hpp index 21b9a36e..5d095ee8 100644 --- a/include/ui/RadioButton.hpp +++ b/include/ui/RadioButton.hpp @@ -1,20 +1,18 @@ #pragma once #include -#include -#include -#include +#include namespace rack { namespace ui { -struct RadioButton : widget::OpaqueWidget { - /** Not owned. */ - Quantity* quantity = NULL; - - RadioButton(); +/** Toggles a Quantity between 1.0 and 0.0 when clicked. +*/ +struct RadioButton : Button { void draw(const DrawArgs& args) override; + void onDragStart(const DragStartEvent& e) override; + void onDragEnd(const DragEndEvent& e) override; void onDragDrop(const DragDropEvent& e) override; }; diff --git a/src/ui/Button.cpp b/src/ui/Button.cpp index 9117ac82..02243ba7 100644 --- a/src/ui/Button.cpp +++ b/src/ui/Button.cpp @@ -10,15 +10,21 @@ Button::Button() { box.size.y = BND_WIDGET_HEIGHT; } + void Button::draw(const DrawArgs& args) { BNDwidgetState state = BND_DEFAULT; - if (APP->event->hoveredWidget == this) + if (APP->event->getHoveredWidget() == this) state = BND_HOVER; - if (APP->event->draggedWidget == this) + if (APP->event->getDraggedWidget() == this) state = BND_ACTIVE; + + std::string text = this->text; + if (text.empty() && quantity) + text = quantity->getLabel(); bndToolButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } + void Button::onDragStart(const DragStartEvent& e) { if (e.button != GLFW_MOUSE_BUTTON_LEFT) return; @@ -27,11 +33,13 @@ void Button::onDragStart(const DragStartEvent& e) { quantity->setMax(); } + void Button::onDragEnd(const DragEndEvent& e) { if (quantity) quantity->setMin(); } + void Button::onDragDrop(const DragDropEvent& e) { if (e.origin == this) { ActionEvent eAction; diff --git a/src/ui/ChoiceButton.cpp b/src/ui/ChoiceButton.cpp index b32a66b4..09932fc6 100644 --- a/src/ui/ChoiceButton.cpp +++ b/src/ui/ChoiceButton.cpp @@ -8,10 +8,14 @@ namespace ui { void ChoiceButton::draw(const DrawArgs& args) { BNDwidgetState state = BND_DEFAULT; - if (APP->event->hoveredWidget == this) + if (APP->event->getHoveredWidget() == this) state = BND_HOVER; - if (APP->event->draggedWidget == this) + if (APP->event->getDraggedWidget() == this) state = BND_ACTIVE; + + std::string text = this->text; + if (text.empty() && quantity) + text = quantity->getLabel(); bndChoiceButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); } diff --git a/src/ui/IconButton.cpp b/src/ui/IconButton.cpp deleted file mode 100644 index 2cbecd12..00000000 --- a/src/ui/IconButton.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include - - -namespace rack { -namespace ui { - - -IconButton::IconButton() { - box.size.x = BND_TOOL_WIDTH; - - fw = new widget::FramebufferWidget; - fw->oversample = 2; - addChild(fw); - - sw = new widget::SvgWidget; - sw->box.pos = math::Vec(2, 2); - fw->addChild(sw); -} - -void IconButton::setSvg(std::shared_ptr svg) { - sw->setSvg(svg); - fw->dirty = true; -} - - -} // namespace ui -} // namespace rack diff --git a/src/ui/OptionButton.cpp b/src/ui/OptionButton.cpp index 9ec8430b..55672c85 100644 --- a/src/ui/OptionButton.cpp +++ b/src/ui/OptionButton.cpp @@ -5,27 +5,17 @@ namespace rack { namespace ui { -OptionButton::OptionButton() { - box.size.y = BND_WIDGET_HEIGHT; -} - void OptionButton::draw(const DrawArgs& args) { BNDwidgetState state = BND_DEFAULT; - if (quantity && !quantity->isMin()) - state = BND_ACTIVE; - - bndOptionButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, state, text.c_str()); -} - - -void OptionButton::onDragDrop(const DragDropEvent& e) { - if (e.origin == this) { - if (quantity) - quantity->toggle(); - - ActionEvent eAction; - onAction(eAction); + if (quantity) { + if (quantity->isMax()) + state = BND_ACTIVE; } + + std::string text = this->text; + if (text.empty() && quantity) + text = quantity->getLabel(); + bndOptionButton(args.vg, 0.0, 0.0, INFINITY, box.size.y, state, text.c_str()); } diff --git a/src/ui/RadioButton.cpp b/src/ui/RadioButton.cpp index cfa6df43..e746a935 100644 --- a/src/ui/RadioButton.cpp +++ b/src/ui/RadioButton.cpp @@ -1,36 +1,42 @@ #include +#include namespace rack { namespace ui { -RadioButton::RadioButton() { - box.size.y = BND_WIDGET_HEIGHT; -} - void RadioButton::draw(const DrawArgs& args) { BNDwidgetState state = BND_DEFAULT; - if (APP->event->hoveredWidget == this) + if (APP->event->getHoveredWidget() == this) state = BND_HOVER; - std::string label; if (quantity) { - label = quantity->getLabel(); if (quantity->isMax()) state = BND_ACTIVE; } - bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, label.c_str()); + + std::string text = this->text; + if (text.empty() && quantity) + text = quantity->getLabel(); + bndRadioButton(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str()); +} + + +void RadioButton::onDragStart(const DragStartEvent& e) { + OpaqueWidget::onDragStart(e); } + +void RadioButton::onDragEnd(const DragEndEvent& e) { + OpaqueWidget::onDragEnd(e); +} + + void RadioButton::onDragDrop(const DragDropEvent& e) { if (e.origin == this) { - if (quantity) { - if (quantity->isMax()) - quantity->setMin(); - else - quantity->setMax(); - } + if (quantity) + quantity->toggle(); ActionEvent eAction; onAction(eAction);