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.

41 lines
983B

  1. #pragma once
  2. #include <widget/OpaqueWidget.hpp>
  3. #include <ui/common.hpp>
  4. #include <app.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. TextField();
  18. void draw(const DrawArgs& args) override;
  19. void onDragHover(const event::DragHover& e) override;
  20. void onButton(const event::Button& e) override;
  21. void onSelectText(const event::SelectText& e) override;
  22. void onSelectKey(const event::SelectKey& e) override;
  23. /** Inserts text at the cursor, replacing the selection if necessary */
  24. void insertText(std::string text);
  25. /** Replaces the entire text */
  26. void setText(std::string text);
  27. void selectAll();
  28. virtual int getTextPosition(math::Vec mousePos);
  29. };
  30. } // namespace ui
  31. } // namespace rack