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