scroll_container.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. SCROLL_MODE_RESERVE,
  43. };
  44. private:
  45. HScrollBar *h_scroll = nullptr;
  46. VScrollBar *v_scroll = nullptr;
  47. mutable Size2 largest_child_min_size; // The largest one among the min sizes of all available child controls.
  48. void update_scrollbars();
  49. Vector2 drag_speed;
  50. Vector2 drag_accum;
  51. Vector2 drag_from;
  52. Vector2 last_drag_accum;
  53. float time_since_motion = 0.0f;
  54. bool drag_touching = false;
  55. bool drag_touching_deaccel = false;
  56. bool beyond_deadzone = false;
  57. ScrollMode horizontal_scroll_mode = SCROLL_MODE_AUTO;
  58. ScrollMode vertical_scroll_mode = SCROLL_MODE_AUTO;
  59. int deadzone = 0;
  60. bool follow_focus = false;
  61. struct ThemeCache {
  62. Ref<StyleBox> panel_style;
  63. } theme_cache;
  64. void _cancel_drag();
  65. bool _is_h_scroll_visible() const;
  66. bool _is_v_scroll_visible() const;
  67. protected:
  68. Size2 get_minimum_size() const override;
  69. void _gui_focus_changed(Control *p_control);
  70. void _reposition_children();
  71. void _notification(int p_what);
  72. static void _bind_methods();
  73. bool _updating_scrollbars = false;
  74. void _update_scrollbar_position();
  75. void _scroll_moved(float);
  76. public:
  77. virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
  78. void set_h_scroll(int p_pos);
  79. int get_h_scroll() const;
  80. void set_v_scroll(int p_pos);
  81. int get_v_scroll() const;
  82. void set_horizontal_custom_step(float p_custom_step);
  83. float get_horizontal_custom_step() const;
  84. void set_vertical_custom_step(float p_custom_step);
  85. float get_vertical_custom_step() const;
  86. void set_horizontal_scroll_mode(ScrollMode p_mode);
  87. ScrollMode get_horizontal_scroll_mode() const;
  88. void set_vertical_scroll_mode(ScrollMode p_mode);
  89. ScrollMode get_vertical_scroll_mode() const;
  90. int get_deadzone() const;
  91. void set_deadzone(int p_deadzone);
  92. bool is_following_focus() const;
  93. void set_follow_focus(bool p_follow);
  94. HScrollBar *get_h_scroll_bar();
  95. VScrollBar *get_v_scroll_bar();
  96. void ensure_control_visible(Control *p_control);
  97. PackedStringArray get_configuration_warnings() const override;
  98. ScrollContainer();
  99. };
  100. VARIANT_ENUM_CAST(ScrollContainer::ScrollMode);
  101. #endif // SCROLL_CONTAINER_H