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.

44 lines
1.1KB

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