tab_container.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*************************************************************************/
  2. /* tab_container.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef TAB_CONTAINER_H
  31. #define TAB_CONTAINER_H
  32. #include "scene/gui/container.h"
  33. #include "scene/gui/popup.h"
  34. #include "scene/resources/text_line.h"
  35. class TabContainer : public Container {
  36. GDCLASS(TabContainer, Container);
  37. public:
  38. enum TabAlign {
  39. ALIGN_LEFT,
  40. ALIGN_CENTER,
  41. ALIGN_RIGHT
  42. };
  43. private:
  44. int first_tab_cache = 0;
  45. int tabs_ofs_cache = 0;
  46. int last_tab_cache = 0;
  47. int current = 0;
  48. int previous = 0;
  49. bool tabs_visible = true;
  50. bool all_tabs_in_front = false;
  51. bool buttons_visible_cache = false;
  52. bool menu_hovered = false;
  53. int highlight_arrow = -1;
  54. TabAlign align = ALIGN_CENTER;
  55. int _get_top_margin() const;
  56. mutable ObjectID popup_obj_id;
  57. bool drag_to_rearrange_enabled = false;
  58. bool use_hidden_tabs_for_min_size = false;
  59. int tabs_rearrange_group = -1;
  60. Vector<Ref<TextLine>> text_buf;
  61. Vector<Control *> _get_tabs() const;
  62. int _get_tab_width(int p_index) const;
  63. bool _theme_changing = false;
  64. void _on_theme_changed();
  65. void _repaint();
  66. void _on_mouse_exited();
  67. void _update_current_tab();
  68. void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x);
  69. void _refresh_texts();
  70. protected:
  71. void _child_renamed_callback();
  72. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  73. void _notification(int p_what);
  74. virtual void add_child_notify(Node *p_child) override;
  75. virtual void move_child_notify(Node *p_child) override;
  76. virtual void remove_child_notify(Node *p_child) override;
  77. Variant get_drag_data(const Point2 &p_point) override;
  78. bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
  79. void drop_data(const Point2 &p_point, const Variant &p_data) override;
  80. int get_tab_idx_at_point(const Point2 &p_point) const;
  81. static void _bind_methods();
  82. public:
  83. void set_tab_align(TabAlign p_align);
  84. TabAlign get_tab_align() const;
  85. void set_tabs_visible(bool p_visible);
  86. bool are_tabs_visible() const;
  87. void set_all_tabs_in_front(bool p_is_front);
  88. bool is_all_tabs_in_front() const;
  89. void set_tab_title(int p_tab, const String &p_title);
  90. String get_tab_title(int p_tab) const;
  91. void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon);
  92. Ref<Texture2D> get_tab_icon(int p_tab) const;
  93. void set_tab_disabled(int p_tab, bool p_disabled);
  94. bool get_tab_disabled(int p_tab) const;
  95. void set_tab_hidden(int p_tab, bool p_hidden);
  96. bool get_tab_hidden(int p_tab) const;
  97. int get_tab_count() const;
  98. void set_current_tab(int p_current);
  99. int get_current_tab() const;
  100. int get_previous_tab() const;
  101. Control *get_tab_control(int p_idx) const;
  102. Control *get_current_tab_control() const;
  103. virtual Size2 get_minimum_size() const override;
  104. virtual void get_translatable_strings(List<String> *p_strings) const override;
  105. void set_popup(Node *p_popup);
  106. Popup *get_popup() const;
  107. void set_drag_to_rearrange_enabled(bool p_enabled);
  108. bool get_drag_to_rearrange_enabled() const;
  109. void set_tabs_rearrange_group(int p_group_id);
  110. int get_tabs_rearrange_group() const;
  111. void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs);
  112. bool get_use_hidden_tabs_for_min_size() const;
  113. TabContainer();
  114. };
  115. VARIANT_ENUM_CAST(TabContainer::TabAlign);
  116. #endif // TAB_CONTAINER_H