tabs.h 5.2 KB

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