split_container.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**************************************************************************/
  2. /* split_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 SPLIT_CONTAINER_H
  31. #define SPLIT_CONTAINER_H
  32. #include "scene/gui/container.h"
  33. class SplitContainerDragger : public Control {
  34. GDCLASS(SplitContainerDragger, Control);
  35. protected:
  36. void _notification(int p_what);
  37. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  38. private:
  39. bool dragging = false;
  40. int drag_from = 0;
  41. int drag_ofs = 0;
  42. bool mouse_inside = false;
  43. public:
  44. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const override;
  45. };
  46. class SplitContainer : public Container {
  47. GDCLASS(SplitContainer, Container);
  48. friend class SplitContainerDragger;
  49. public:
  50. enum DraggerVisibility {
  51. DRAGGER_VISIBLE,
  52. DRAGGER_HIDDEN,
  53. DRAGGER_HIDDEN_COLLAPSED
  54. };
  55. private:
  56. int split_offset = 0;
  57. int middle_sep = 0;
  58. bool vertical = false;
  59. bool collapsed = false;
  60. DraggerVisibility dragger_visibility = DRAGGER_VISIBLE;
  61. SplitContainerDragger *dragging_area_control = nullptr;
  62. struct ThemeCache {
  63. int separation = 0;
  64. int minimum_grab_thickness = 0;
  65. bool autohide = false;
  66. Ref<Texture2D> grabber_icon;
  67. Ref<Texture2D> grabber_icon_h;
  68. Ref<Texture2D> grabber_icon_v;
  69. } theme_cache;
  70. Control *_getch(int p_idx) const;
  71. Ref<Texture2D> _get_grabber_icon() const;
  72. void _compute_middle_sep(bool p_clamp);
  73. void _resort();
  74. protected:
  75. bool is_fixed = false;
  76. void _notification(int p_what);
  77. void _validate_property(PropertyInfo &p_property) const;
  78. static void _bind_methods();
  79. public:
  80. void set_split_offset(int p_offset);
  81. int get_split_offset() const;
  82. void clamp_split_offset();
  83. void set_collapsed(bool p_collapsed);
  84. bool is_collapsed() const;
  85. void set_dragger_visibility(DraggerVisibility p_visibility);
  86. DraggerVisibility get_dragger_visibility() const;
  87. void set_vertical(bool p_vertical);
  88. bool is_vertical() const;
  89. virtual Size2 get_minimum_size() const override;
  90. virtual Vector<int> get_allowed_size_flags_horizontal() const override;
  91. virtual Vector<int> get_allowed_size_flags_vertical() const override;
  92. SplitContainer(bool p_vertical = false);
  93. };
  94. VARIANT_ENUM_CAST(SplitContainer::DraggerVisibility);
  95. class HSplitContainer : public SplitContainer {
  96. GDCLASS(HSplitContainer, SplitContainer);
  97. public:
  98. HSplitContainer() :
  99. SplitContainer(false) { is_fixed = true; }
  100. };
  101. class VSplitContainer : public SplitContainer {
  102. GDCLASS(VSplitContainer, SplitContainer);
  103. public:
  104. VSplitContainer() :
  105. SplitContainer(true) { is_fixed = true; }
  106. };
  107. #endif // SPLIT_CONTAINER_H