scroll_container.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*************************************************************************/
  2. /* scroll_container.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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 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. HScrollBar *h_scroll;
  37. VScrollBar *v_scroll;
  38. Size2 child_max_size;
  39. void update_scrollbars();
  40. Vector2 drag_speed;
  41. Vector2 drag_accum;
  42. Vector2 drag_from;
  43. Vector2 last_drag_accum;
  44. float time_since_motion = 0.0f;
  45. bool drag_touching = false;
  46. bool drag_touching_deaccel = false;
  47. bool beyond_deadzone = false;
  48. bool scroll_h = true;
  49. bool scroll_v = true;
  50. bool h_scroll_visible = true;
  51. bool v_scroll_visible = true;
  52. int deadzone = 0;
  53. bool follow_focus = false;
  54. void _cancel_drag();
  55. protected:
  56. Size2 get_minimum_size() const override;
  57. virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
  58. void _gui_focus_changed(Control *p_control);
  59. void _update_dimensions();
  60. void _notification(int p_what);
  61. void _scroll_moved(float);
  62. static void _bind_methods();
  63. bool _updating_scrollbars = false;
  64. void _update_scrollbar_position();
  65. public:
  66. void set_h_scroll(int p_pos);
  67. int get_h_scroll() const;
  68. void set_v_scroll(int p_pos);
  69. int get_v_scroll() const;
  70. void set_enable_h_scroll(bool p_enable);
  71. bool is_h_scroll_enabled() const;
  72. void set_enable_v_scroll(bool p_enable);
  73. bool is_v_scroll_enabled() const;
  74. void set_h_scroll_visible(bool p_visible);
  75. bool is_h_scroll_visible() const;
  76. void set_v_scroll_visible(bool p_visible);
  77. bool is_v_scroll_visible() const;
  78. int get_deadzone() const;
  79. void set_deadzone(int p_deadzone);
  80. bool is_following_focus() const;
  81. void set_follow_focus(bool p_follow);
  82. HScrollBar *get_h_scrollbar();
  83. VScrollBar *get_v_scrollbar();
  84. void ensure_control_visible(Control *p_control);
  85. TypedArray<String> get_configuration_warnings() const override;
  86. ScrollContainer();
  87. };
  88. #endif