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 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <widget/OpaqueWidget.hpp>
  3. #include <ui/common.hpp>
  4. #include <context.hpp>
  5. namespace rack {
  6. namespace ui {
  7. struct TextField : widget::OpaqueWidget {
  8. std::string text;
  9. std::string placeholder;
  10. /** Masks text with "*". */
  11. bool password = false;
  12. bool multiline = false;
  13. /** The index of the text cursor */
  14. int cursor = 0;
  15. /** The index of the other end of the selection.
  16. If nothing is selected, this is equal to `cursor`.
  17. */
  18. int selection = 0;
  19. /** For Tab and Shift-Tab focusing.
  20. */
  21. Widget* prevField = NULL;
  22. Widget* nextField = NULL;
  23. TextField();
  24. void draw(const DrawArgs& args) override;
  25. void onDragHover(const DragHoverEvent& e) override;
  26. void onButton(const ButtonEvent& e) override;
  27. void onSelectText(const SelectTextEvent& e) override;
  28. void onSelectKey(const SelectKeyEvent& e) override;
  29. virtual int getTextPosition(math::Vec mousePos);
  30. std::string getText();
  31. /** Replaces the entire text */
  32. void setText(std::string text);
  33. void selectAll();
  34. std::string getSelectedText();
  35. /** Inserts text at the cursor, replacing the selection if necessary */
  36. void insertText(std::string text);
  37. void copyClipboard();
  38. void cutClipboard();
  39. void pasteClipboard();
  40. void cursorToPrevWord();
  41. void cursorToNextWord();
  42. void createContextMenu();
  43. };
  44. struct PasswordField : TextField {
  45. PasswordField() {
  46. password = true;
  47. }
  48. };
  49. } // namespace ui
  50. } // namespace rack