diff --git a/src/ui/MenuOverlay.cpp b/src/ui/MenuOverlay.cpp new file mode 100644 index 00000000..a7dca391 --- /dev/null +++ b/src/ui/MenuOverlay.cpp @@ -0,0 +1,36 @@ +#include "ui/MenuOverlay.hpp" + + +namespace rack { + + +void MenuOverlay::step() { + // Adopt parent's size + box.size = parent->box.size; + + // Fit all children in the box + for (Widget *child : children) { + child->box = child->box.nudge(box.zeroPos()); + } + + Widget::step(); +} + +void MenuOverlay::onButton(const event::Button &e) { + OpaqueWidget::onButton(e); + + if (e.getConsumed() == this && e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) { + requestedDelete = true; + } +} + +void MenuOverlay::onHoverKey(const event::HoverKey &e) { + OpaqueWidget::onHoverKey(e); + + if (e.getConsumed() == this && e.action == GLFW_PRESS && e.key == GLFW_KEY_ESCAPE) { + requestedDelete = true; + } +} + + +} // namespace rack diff --git a/src/ui/Tooltip.cpp b/src/ui/Tooltip.cpp new file mode 100644 index 00000000..4972a25b --- /dev/null +++ b/src/ui/Tooltip.cpp @@ -0,0 +1,23 @@ +#include "ui/Tooltip.hpp" +#include "context.hpp" +#include "window.hpp" + + +namespace rack { + + +void Tooltip::step() { + // Wrap size to contents + box.size.x = bndLabelWidth(context()->window->vg, -1, text.c_str()) + 10.0; + box.size.y = bndLabelHeight(context()->window->vg, -1, text.c_str(), INFINITY); + Widget::step(); +} + +void Tooltip::draw(NVGcontext *vg) { + bndTooltipBackground(vg, 0.0, 0.0, box.size.x, box.size.y); + bndMenuLabel(vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); + Widget::draw(vg); +} + + +} // namespace rack