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.

53 lines
1.2KB

  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. 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. /** For Tab and Shift-Tab focusing.
  18. */
  19. Widget* prevField = NULL;
  20. Widget* nextField = NULL;
  21. TextField();
  22. void draw(const DrawArgs& args) override;
  23. void onDragHover(const DragHoverEvent& e) override;
  24. void onButton(const ButtonEvent& e) override;
  25. void onSelectText(const SelectTextEvent& e) override;
  26. void onSelectKey(const SelectKeyEvent& e) override;
  27. virtual int getTextPosition(math::Vec mousePos);
  28. std::string getText();
  29. /** Replaces the entire text */
  30. void setText(std::string text);
  31. void selectAll();
  32. std::string getSelectedText();
  33. /** Inserts text at the cursor, replacing the selection if necessary */
  34. void insertText(std::string text);
  35. void copyClipboard();
  36. void cutClipboard();
  37. void pasteClipboard();
  38. void cursorToPrevWord();
  39. void cursorToNextWord();
  40. void createContextMenu();
  41. };
  42. } // namespace ui
  43. } // namespace rack