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.

39 lines
825B

  1. #include <ui/Label.hpp>
  2. namespace rack {
  3. namespace ui {
  4. Label::Label() {
  5. box.size.y = BND_WIDGET_HEIGHT;
  6. fontSize = BND_LABEL_FONT_SIZE;
  7. lineHeight = 1.2;
  8. color = bndGetTheme()->regularTheme.textColor;
  9. }
  10. void Label::draw(const DrawArgs& args) {
  11. // TODO
  12. // Custom font sizes do not work with right or center alignment
  13. float x;
  14. switch (alignment) {
  15. default:
  16. case LEFT_ALIGNMENT: {
  17. x = 0.0;
  18. } break;
  19. case RIGHT_ALIGNMENT: {
  20. x = box.size.x - bndLabelWidth(args.vg, -1, text.c_str());
  21. } break;
  22. case CENTER_ALIGNMENT: {
  23. x = (box.size.x - bndLabelWidth(args.vg, -1, text.c_str())) / 2.0;
  24. } break;
  25. }
  26. nvgTextLineHeight(args.vg, lineHeight);
  27. bndIconLabelValue(args.vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL);
  28. }
  29. } // namespace ui
  30. } // namespace rack