tabs.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*************************************************************************/
  2. /* tabs.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 TABS_H
  31. #define TABS_H
  32. #include "scene/gui/control.h"
  33. class Tabs : public Control {
  34. GDCLASS(Tabs, Control);
  35. public:
  36. enum TabAlign {
  37. ALIGN_LEFT,
  38. ALIGN_CENTER,
  39. ALIGN_RIGHT,
  40. ALIGN_MAX
  41. };
  42. enum CloseButtonDisplayPolicy {
  43. CLOSE_BUTTON_SHOW_NEVER,
  44. CLOSE_BUTTON_SHOW_ACTIVE_ONLY,
  45. CLOSE_BUTTON_SHOW_ALWAYS,
  46. CLOSE_BUTTON_MAX
  47. };
  48. private:
  49. struct Tab {
  50. String text;
  51. String xl_text;
  52. Ref<Texture> icon;
  53. int ofs_cache;
  54. bool disabled;
  55. int size_cache;
  56. int size_text;
  57. int x_cache;
  58. int x_size_cache;
  59. Ref<Texture> right_button;
  60. Rect2 rb_rect;
  61. Rect2 cb_rect;
  62. };
  63. int offset;
  64. int max_drawn_tab;
  65. int highlight_arrow;
  66. bool buttons_visible;
  67. bool missing_right;
  68. Vector<Tab> tabs;
  69. int current;
  70. int _get_top_margin() const;
  71. TabAlign tab_align;
  72. int rb_hover;
  73. bool rb_pressing;
  74. bool select_with_rmb;
  75. int cb_hover;
  76. bool cb_pressing;
  77. CloseButtonDisplayPolicy cb_displaypolicy;
  78. int hover; // Hovered tab.
  79. int min_width;
  80. bool scrolling_enabled;
  81. bool drag_to_rearrange_enabled;
  82. int tabs_rearrange_group;
  83. int get_tab_width(int p_idx) const;
  84. void _ensure_no_over_offset();
  85. void _update_hover();
  86. void _update_cache();
  87. void _on_mouse_exited();
  88. protected:
  89. void _gui_input(const Ref<InputEvent> &p_event);
  90. void _notification(int p_what);
  91. static void _bind_methods();
  92. Variant get_drag_data(const Point2 &p_point);
  93. bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
  94. void drop_data(const Point2 &p_point, const Variant &p_data);
  95. int get_tab_idx_at_point(const Point2 &p_point) const;
  96. public:
  97. void add_tab(const String &p_str = "", const Ref<Texture> &p_icon = Ref<Texture>());
  98. void set_tab_title(int p_tab, const String &p_title);
  99. String get_tab_title(int p_tab) const;
  100. void set_tab_icon(int p_tab, const Ref<Texture> &p_icon);
  101. Ref<Texture> get_tab_icon(int p_tab) const;
  102. void set_tab_disabled(int p_tab, bool p_disabled);
  103. bool get_tab_disabled(int p_tab) const;
  104. void set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button);
  105. Ref<Texture> get_tab_right_button(int p_tab) const;
  106. void set_tab_align(TabAlign p_align);
  107. TabAlign get_tab_align() const;
  108. void move_tab(int from, int to);
  109. void set_tab_close_display_policy(CloseButtonDisplayPolicy p_policy);
  110. CloseButtonDisplayPolicy get_tab_close_display_policy() const;
  111. int get_tab_count() const;
  112. void set_current_tab(int p_current);
  113. int get_current_tab() const;
  114. int get_hovered_tab() const;
  115. int get_tab_offset() const;
  116. bool get_offset_buttons_visible() const;
  117. void remove_tab(int p_idx);
  118. void clear_tabs();
  119. void set_scrolling_enabled(bool p_enabled);
  120. bool get_scrolling_enabled() const;
  121. void set_drag_to_rearrange_enabled(bool p_enabled);
  122. bool get_drag_to_rearrange_enabled() const;
  123. void set_tabs_rearrange_group(int p_group_id);
  124. int get_tabs_rearrange_group() const;
  125. void set_select_with_rmb(bool p_enabled);
  126. bool get_select_with_rmb() const;
  127. void ensure_tab_visible(int p_idx);
  128. void set_min_width(int p_width);
  129. Rect2 get_tab_rect(int p_tab) const;
  130. Size2 get_minimum_size() const;
  131. Tabs();
  132. };
  133. VARIANT_ENUM_CAST(Tabs::TabAlign);
  134. VARIANT_ENUM_CAST(Tabs::CloseButtonDisplayPolicy);
  135. #endif // TABS_H