Entry.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "Text.hpp"
  3. #include "RoundedRectangle.hpp"
  4. #include <mglpp/graphics/Text.hpp>
  5. #include <functional>
  6. namespace mgl {
  7. class Font;
  8. class Event;
  9. class Window;
  10. class Shader;
  11. }
  12. namespace QuickMedia {
  13. // Return true to clear the text
  14. using OnEntrySubmit = std::function<bool(std::string text)>;
  15. class Entry {
  16. public:
  17. Entry(const std::string &placeholder_text, mgl::Shader *rounded_rectangle_shader);
  18. void process_event(mgl::Window &window, mgl::Event &event);
  19. void draw(mgl::Window &window);
  20. void set_single_line(bool single_line);
  21. void set_editable(bool editable);
  22. void set_text(std::string text);
  23. void set_position(const mgl::vec2f &pos);
  24. void set_max_width(float width);
  25. void move_caret_to_end();
  26. void insert_text_at_caret_position(const std::string &str);
  27. void replace(size_t start_index, size_t length, const std::string &insert_str);
  28. int get_caret_index() const;
  29. bool is_editable() const;
  30. float get_height();
  31. const std::string& get_text() const;
  32. void set_background_color(mgl::Color color);
  33. void set_padding_scale(float scale);
  34. OnEntrySubmit on_submit_callback;
  35. bool draw_background;
  36. private:
  37. Text text;
  38. float width;
  39. RoundedRectangle background;
  40. mgl::Text placeholder;
  41. bool mouse_left_inside;
  42. float padding_scale = 1.0f;
  43. };
  44. }