tab_container.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**************************************************************************/
  2. /* tab_container.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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/gui/tab_bar.h"
  35. class TabContainer : public Container {
  36. GDCLASS(TabContainer, Container);
  37. TabBar *tab_bar = nullptr;
  38. bool tabs_visible = true;
  39. bool all_tabs_in_front = false;
  40. bool menu_hovered = false;
  41. mutable ObjectID popup_obj_id;
  42. bool drag_to_rearrange_enabled = false;
  43. bool use_hidden_tabs_for_min_size = false;
  44. bool theme_changing = false;
  45. Vector<Control *> children_removing;
  46. struct ThemeCache {
  47. int side_margin = 0;
  48. Ref<StyleBox> panel_style;
  49. Ref<StyleBox> tabbar_style;
  50. Ref<Texture2D> menu_icon;
  51. Ref<Texture2D> menu_hl_icon;
  52. // TabBar overrides.
  53. int icon_separation = 0;
  54. int outline_size = 0;
  55. Ref<StyleBox> tab_unselected_style;
  56. Ref<StyleBox> tab_selected_style;
  57. Ref<StyleBox> tab_disabled_style;
  58. Ref<Texture2D> increment_icon;
  59. Ref<Texture2D> increment_hl_icon;
  60. Ref<Texture2D> decrement_icon;
  61. Ref<Texture2D> decrement_hl_icon;
  62. Ref<Texture2D> drop_mark_icon;
  63. Color drop_mark_color;
  64. Color font_selected_color;
  65. Color font_unselected_color;
  66. Color font_disabled_color;
  67. Color font_outline_color;
  68. Ref<Font> tab_font;
  69. int tab_font_size;
  70. } theme_cache;
  71. int _get_top_margin() const;
  72. Vector<Control *> _get_tab_controls() const;
  73. void _on_theme_changed();
  74. void _repaint();
  75. void _refresh_tab_names();
  76. void _update_margins();
  77. void _on_mouse_exited();
  78. void _on_tab_changed(int p_tab);
  79. void _on_tab_selected(int p_tab);
  80. void _on_tab_button_pressed(int p_tab);
  81. Variant _get_drag_data_fw(const Point2 &p_point, Control *p_from_control);
  82. bool _can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const;
  83. void _drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control);
  84. protected:
  85. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  86. virtual void _update_theme_item_cache() override;
  87. void _notification(int p_what);
  88. virtual void add_child_notify(Node *p_child) override;
  89. virtual void move_child_notify(Node *p_child) override;
  90. virtual void remove_child_notify(Node *p_child) override;
  91. static void _bind_methods();
  92. public:
  93. int get_tab_idx_at_point(const Point2 &p_point) const;
  94. int get_tab_idx_from_control(Control *p_child) const;
  95. void set_tab_alignment(TabBar::AlignmentMode p_alignment);
  96. TabBar::AlignmentMode get_tab_alignment() const;
  97. void set_clip_tabs(bool p_clip_tabs);
  98. bool get_clip_tabs() const;
  99. void set_tabs_visible(bool p_visible);
  100. bool are_tabs_visible() const;
  101. void set_all_tabs_in_front(bool p_is_front);
  102. bool is_all_tabs_in_front() const;
  103. void set_tab_title(int p_tab, const String &p_title);
  104. String get_tab_title(int p_tab) const;
  105. void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon);
  106. Ref<Texture2D> get_tab_icon(int p_tab) const;
  107. void set_tab_disabled(int p_tab, bool p_disabled);
  108. bool is_tab_disabled(int p_tab) const;
  109. void set_tab_hidden(int p_tab, bool p_hidden);
  110. bool is_tab_hidden(int p_tab) const;
  111. void set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon);
  112. Ref<Texture2D> get_tab_button_icon(int p_tab) const;
  113. int get_tab_count() const;
  114. void set_current_tab(int p_current);
  115. int get_current_tab() const;
  116. int get_previous_tab() const;
  117. Control *get_tab_control(int p_idx) const;
  118. Control *get_current_tab_control() const;
  119. virtual Size2 get_minimum_size() const override;
  120. void set_popup(Node *p_popup);
  121. Popup *get_popup() const;
  122. void set_drag_to_rearrange_enabled(bool p_enabled);
  123. bool get_drag_to_rearrange_enabled() const;
  124. void set_tabs_rearrange_group(int p_group_id);
  125. int get_tabs_rearrange_group() const;
  126. void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs);
  127. bool get_use_hidden_tabs_for_min_size() const;
  128. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  129. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  130. TabContainer();
  131. };
  132. #endif // TAB_CONTAINER_H