You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
920B

  1. #include <ui/Tooltip.hpp>
  2. #include <context.hpp>
  3. #include <app/Scene.hpp>
  4. namespace rack {
  5. namespace ui {
  6. void Tooltip::step() {
  7. // Wrap size to contents
  8. nvgSave(APP->window->vg);
  9. nvgTextLineHeight(APP->window->vg, 1.2);
  10. box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str());
  11. box.size.y = bndLabelHeight(APP->window->vg, -1, text.c_str(), INFINITY);
  12. // Position near cursor. This assumes that the Tooltip is added to the root widget.
  13. box.pos = APP->scene->mousePos.plus(math::Vec(15, 15));
  14. // Fit inside parent
  15. assert(parent);
  16. box = box.nudge(parent->box.zeroPos());
  17. nvgRestore(APP->window->vg);
  18. Widget::step();
  19. }
  20. void Tooltip::draw(const DrawArgs& args) {
  21. bndTooltipBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y);
  22. nvgTextLineHeight(args.vg, 1.2);
  23. bndMenuLabel(args.vg, 0.0, 0.0, INFINITY, box.size.y, -1, text.c_str());
  24. Widget::draw(args);
  25. }
  26. } // namespace ui
  27. } // namespace rack