scroll_container.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #pragma once
  31. #include "container.h"
  32. #include "scroll_bar.h"
  33. class PanelContainer;
  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. PanelContainer *focus_panel = nullptr;
  48. mutable Size2 largest_child_min_size; // The largest one among the min sizes of all available child controls.
  49. void update_scrollbars();
  50. Vector2 drag_speed;
  51. Vector2 drag_accum;
  52. Vector2 drag_from;
  53. Vector2 last_drag_accum;
  54. float time_since_motion = 0.0f;
  55. bool drag_touching = false;
  56. bool drag_touching_deaccel = false;
  57. bool beyond_deadzone = false;
  58. bool scroll_on_drag_hover = false;
  59. ScrollMode horizontal_scroll_mode = SCROLL_MODE_AUTO;
  60. ScrollMode vertical_scroll_mode = SCROLL_MODE_AUTO;
  61. int deadzone = 0;
  62. bool follow_focus = false;
  63. int scroll_border = 20;
  64. int scroll_speed = 12;
  65. struct ThemeCache {
  66. Ref<StyleBox> panel_style;
  67. Ref<StyleBox> focus_style;
  68. } theme_cache;
  69. void _cancel_drag();
  70. bool _is_h_scroll_visible() const;
  71. bool _is_v_scroll_visible() const;
  72. bool draw_focus_border = false;
  73. bool focus_border_is_drawn = false;
  74. bool child_has_focus();
  75. protected:
  76. Size2 get_minimum_size() const override;
  77. void _gui_focus_changed(Control *p_control);
  78. void _reposition_children();
  79. void _notification(int p_what);
  80. static void _bind_methods();
  81. bool _updating_scrollbars = false;
  82. void _update_scrollbar_position();
  83. void _scroll_moved(float);
  84. void _accessibility_action_scroll_set(const Variant &p_data);
  85. void _accessibility_action_scroll_up(const Variant &p_data);
  86. void _accessibility_action_scroll_down(const Variant &p_data);
  87. void _accessibility_action_scroll_left(const Variant &p_data);
  88. void _accessibility_action_scroll_right(const Variant &p_data);
  89. public:
  90. virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;
  91. void set_h_scroll(int p_pos);
  92. int get_h_scroll() const;
  93. void set_v_scroll(int p_pos);
  94. int get_v_scroll() const;
  95. void set_horizontal_custom_step(float p_custom_step);
  96. float get_horizontal_custom_step() const;
  97. void set_vertical_custom_step(float p_custom_step);
  98. float get_vertical_custom_step() const;
  99. void set_horizontal_scroll_mode(ScrollMode p_mode);
  100. ScrollMode get_horizontal_scroll_mode() const;
  101. void set_vertical_scroll_mode(ScrollMode p_mode);
  102. ScrollMode get_vertical_scroll_mode() const;
  103. int get_deadzone() const;
  104. void set_deadzone(int p_deadzone);
  105. bool is_following_focus() const;
  106. void set_follow_focus(bool p_follow);
  107. void set_scroll_on_drag_hover(bool p_scroll);
  108. HScrollBar *get_h_scroll_bar();
  109. VScrollBar *get_v_scroll_bar();
  110. void ensure_control_visible(Control *p_control);
  111. PackedStringArray get_configuration_warnings() const override;
  112. void set_draw_focus_border(bool p_draw);
  113. bool get_draw_focus_border();
  114. ScrollContainer();
  115. };
  116. VARIANT_ENUM_CAST(ScrollContainer::ScrollMode);