Tabs.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "RoundedRectangle.hpp"
  3. #include <mglpp/graphics/Rectangle.hpp>
  4. #include <mglpp/graphics/Text.hpp>
  5. #include <mglpp/graphics/Sprite.hpp>
  6. #include <vector>
  7. #include <functional>
  8. namespace mgl {
  9. class Event;
  10. class Window;
  11. class Shader;
  12. }
  13. namespace QuickMedia {
  14. class Body;
  15. class Tabs {
  16. public:
  17. Tabs(mgl::Shader *rounded_rectangle_shader);
  18. Tabs(mgl::Shader *rounded_rectangle_shader, mgl::Color shade_color);
  19. static float get_height();
  20. static float get_shade_height();
  21. // Returns the id (index) of the tab. The ids start from 0
  22. int add_tab(std::string title, Body *body);
  23. void on_event(mgl::Event &event);
  24. void draw(mgl::Window &window, mgl::vec2f pos, float width);
  25. void set_text(int index, const std::string &text);
  26. void set_selected(int index);
  27. int get_selected() const;
  28. std::function<void(int prev_tab, int new_tab)> on_change_tab = nullptr;
  29. private:
  30. void move_selected_tab(int new_tab);
  31. float tab_index_to_x_offset(int index);
  32. private:
  33. struct Tab {
  34. mgl::Text text;
  35. Body *body;
  36. };
  37. std::vector<Tab> tabs;
  38. RoundedRectangle background;
  39. mgl::Rectangle shade;
  40. int selected_tab = 0;
  41. float scroll = 0.0f;
  42. float width_per_tab = 0.0f;
  43. float tab_background_width = 0.0f;
  44. float container_width = 0.0f;
  45. int tab_offset = 0;
  46. mgl::Color shade_color;
  47. mgl::Sprite arrow_sprite;
  48. };
  49. }