scroll_container.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**************************************************************************/
  2. /* scroll_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 SCROLL_CONTAINER_H
  31. #define SCROLL_CONTAINER_H
  32. #include "container.h"
  33. #include "scroll_bar.h"
  34. class ScrollContainer : public Container {
  35. GDCLASS(ScrollContainer, Container);
  36. public:
  37. enum ScrollMode {
  38. SCROLL_MODE_DISABLED = 0,
  39. SCROLL_MODE_AUTO,
  40. SCROLL_MODE_SHOW_ALWAYS,
  41. SCROLL_MODE_SHOW_NEVER,
  42. };
  43. private:
  44. HScrollBar *h_scroll = nullptr;
  45. VScrollBar *v_scroll = nullptr;
  46. mutable Size2 largest_child_min_size; // The largest one among the min sizes of all available child controls.
  47. void update_scrollbars();
  48. Vector2 drag_speed;
  49. Vector2 drag_accum;
  50. Vector2 drag_from;
  51. Vector2 last_drag_accum;
  52. float time_since_motion = 0.0f;
  53. bool drag_touching = false;
  54. bool drag_touching_deaccel = false;
  55. bool beyond_deadzone = false;
  56. ScrollMode horizontal_scroll_mode = SCROLL_MODE_AUTO;
  57. ScrollMode vertical_scroll_mode = SCROLL_MODE_AUTO;
  58. int deadzone = 0;
  59. bool follow_focus = false;
  60. struct ThemeCache {
  61. Ref<StyleBox> panel_style;
  62. } theme_cache;
  63. void _cancel_drag();
  64. protected:
  65. virtual void _update_theme_item_cache() override;
  66. Size2 get_minimum_size() const override;
  67. void _gui_focus_changed(Control *p_control);
  68. void _reposition_children();
  69. void _notification(int p_what);
  70. void _scroll_moved(float);
  71. static void _bind_methods();
  72. bool _updating_scrollbars = false;
  73. void _update_scrollbar_position();
  74. public:
  75. virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
  76. void set_h_scroll(int p_pos);
  77. int get_h_scroll() const;
  78. void set_v_scroll(int p_pos);
  79. int get_v_scroll() const;
  80. void set_horizontal_scroll_mode(ScrollMode p_mode);
  81. ScrollMode get_horizontal_scroll_mode() const;
  82. void set_vertical_scroll_mode(ScrollMode p_mode);
  83. ScrollMode get_vertical_scroll_mode() const;
  84. int get_deadzone() const;
  85. void set_deadzone(int p_deadzone);
  86. bool is_following_focus() const;
  87. void set_follow_focus(bool p_follow);
  88. HScrollBar *get_h_scroll_bar();
  89. VScrollBar *get_v_scroll_bar();
  90. void ensure_control_visible(Control *p_control);
  91. PackedStringArray get_configuration_warnings() const override;
  92. ScrollContainer();
  93. };
  94. VARIANT_ENUM_CAST(ScrollContainer::ScrollMode);
  95. #endif // SCROLL_CONTAINER_H