BaseGUI.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #ifndef BASE_GUI_H
  2. #define BASE_GUI_H
  3. #include "input/TextInput.h"
  4. #include "math/Vector.h"
  5. #include "utils/List.h"
  6. #include "utils/Size.h"
  7. struct BaseGUI final {
  8. static const Vector2 FIXED_SIZE;
  9. float scale;
  10. Vector2 scaledSize;
  11. struct Base {
  12. Vector2 pos;
  13. Vector2 size;
  14. bool hovered;
  15. bool pressed;
  16. Base();
  17. };
  18. struct Label {
  19. Base base;
  20. StringBuffer<50> text;
  21. };
  22. List<Label> labels;
  23. struct Input {
  24. Base base;
  25. TextInput text;
  26. };
  27. List<Input> inputs;
  28. struct Button {
  29. Base base;
  30. StringBuffer<20> text;
  31. };
  32. List<Button> buttons;
  33. void tick();
  34. void updateScale();
  35. void render();
  36. Vector2 round(const Vector2& v) const;
  37. void renderString(const Vector2& pos, const char* s);
  38. Label& addLabel(const char* text);
  39. Input& addInput();
  40. Button& addButton(const char* text);
  41. bool isIn(const Vector2& pos, const Vector2& size,
  42. const Vector2& point) const;
  43. private:
  44. void tickBase(Base& b);
  45. Vector2 renderCenteredString(const Base& b, const char* text);
  46. void renderBase(const Base& b);
  47. void renderLabels();
  48. void renderInputs();
  49. void renderButtons();
  50. };
  51. #endif