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.

Label.hpp 963B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include "widgets/Widget.hpp"
  3. #include "ui/common.hpp"
  4. namespace rack {
  5. struct Label : virtual Widget {
  6. std::string text;
  7. float fontSize;
  8. NVGcolor color;
  9. enum Alignment {
  10. LEFT_ALIGNMENT,
  11. CENTER_ALIGNMENT,
  12. RIGHT_ALIGNMENT,
  13. };
  14. Alignment alignment = LEFT_ALIGNMENT;
  15. Label() {
  16. box.size.y = BND_WIDGET_HEIGHT;
  17. fontSize = 13;
  18. color = bndGetTheme()->regularTheme.textColor;
  19. }
  20. void draw(NVGcontext *vg) override {
  21. // TODO
  22. // Custom font sizes do not work with right or center alignment
  23. float x;
  24. switch (alignment) {
  25. default:
  26. case LEFT_ALIGNMENT: {
  27. x = 0.0;
  28. } break;
  29. case RIGHT_ALIGNMENT: {
  30. x = box.size.x - bndLabelWidth(vg, -1, text.c_str());
  31. } break;
  32. case CENTER_ALIGNMENT: {
  33. x = (box.size.x - bndLabelWidth(vg, -1, text.c_str())) / 2.0;
  34. } break;
  35. }
  36. bndIconLabelValue(vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL);
  37. }
  38. };
  39. } // namespace rack