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.

TextField.hpp 997B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "widgets/OpaqueWidget.hpp"
  3. #include "ui/common.hpp"
  4. #include "event.hpp"
  5. #include "app.hpp"
  6. namespace rack {
  7. struct TextField : OpaqueWidget {
  8. std::string text;
  9. std::string placeholder;
  10. bool multiline = false;
  11. /** The index of the text cursor */
  12. int cursor = 0;
  13. /** The index of the other end of the selection.
  14. If nothing is selected, this is equal to `cursor`.
  15. */
  16. int selection = 0;
  17. TextField();
  18. void draw(NVGcontext *vg) override;
  19. void onButton(const event::Button &e) override;
  20. void onHover(const event::Hover &e) override;
  21. void onEnter(const event::Enter &e) override;
  22. void onSelectText(const event::SelectText &e) override;
  23. void onSelectKey(const event::SelectKey &e) override;
  24. /** Inserts text at the cursor, replacing the selection if necessary */
  25. void insertText(std::string text);
  26. /** Replaces the entire text */
  27. void setText(std::string text);
  28. void selectAll();
  29. virtual int getTextPosition(math::Vec mousePos);
  30. };
  31. } // namespace rack