Godot Engine – Multi-platform 2D and 3D game engine
Add more scroll hint modes to `ScrollContainer`
Michael Alexsanderb5592122c0a9
diff --git a/doc/classes/ScrollContainer.xml b/doc/classes/ScrollContainer.xmlindex 1bea4f0acab..9cae3440513 100644--- a/doc/classes/ScrollContainer.xml+++ b/doc/classes/ScrollContainer.xml@@ -55,7 +55,7 @@</member><member name="scroll_hint_mode" type="int" setter="set_scroll_hint_mode" getter="get_scroll_hint_mode" enum="ScrollContainer.ScrollHintMode" default="0">The way which scroll hints (indicators that show that the content can still be scrolled in a certain direction) will be shown.- [b]Note:[/b] Hints won't be shown if the content can be scrolled both vertically and horizontally.+ [b]Note:[/b] Modes with perpendicular hints won't be shown if the content can be scrolled both vertically and horizontally.</member><member name="scroll_horizontal" type="int" setter="set_h_scroll" getter="get_h_scroll" default="0">The current horizontal scroll value.@@ -135,6 +135,24 @@<constant name="SCROLL_HINT_MODE_BOTTOM_AND_RIGHT" value="3" enum="ScrollHintMode">Scroll hints will be shown at the bottom (if horizontal), or the right (if horizontal).</constant>+ <constant name="SCROLL_HINT_MODE_TOP_AND_BOTTOM" value="4" enum="ScrollHintMode">+ Scroll hints will be shown at the top and bottom.+ </constant>+ <constant name="SCROLL_HINT_MODE_LEFT_AND_RIGHT" value="5" enum="ScrollHintMode">+ Scroll hints will be shown on the left and right.+ </constant>+ <constant name="SCROLL_HINT_MODE_TOP" value="6" enum="ScrollHintMode">+ Scroll hint will be shown at the top.+ </constant>+ <constant name="SCROLL_HINT_MODE_BOTTOM" value="7" enum="ScrollHintMode">+ Scroll hint will be shown at the bottom.+ </constant>+ <constant name="SCROLL_HINT_MODE_LEFT" value="8" enum="ScrollHintMode">+ Scroll hint will be shown on the left.+ </constant>+ <constant name="SCROLL_HINT_MODE_RIGHT" value="9" enum="ScrollHintMode">+ Scroll hint will be shown on the right.+ </constant></constants><theme_items><theme_item name="scroll_hint_horizontal_color" data_type="color" type="Color" default="Color(0, 0, 0, 1)">diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cppindex c49f94b7077..a41305ce809 100644--- a/scene/gui/scroll_container.cpp+++ b/scene/gui/scroll_container.cpp@@ -759,50 +759,77 @@ void ScrollContainer::_update_scroll_hints() {float v_scroll_value = v_scroll->get_value();bool v_scroll_below_max = v_scroll_value < (largest_child_min_size.height - scroll_size.height - 1);- bool show_vertical_hints = v_scroll_value > 1 || v_scroll_below_max;+ bool is_v_scrolled = v_scroll_value > 1 || v_scroll_below_max;float h_scroll_value = h_scroll->get_value();bool h_scroll_below_max = h_scroll_value < (largest_child_min_size.width - scroll_size.width - 1);- bool show_horizontal_hints = h_scroll_value > 1 || h_scroll_below_max;+ bool is_h_scrolled = h_scroll_value > 1 || h_scroll_below_max;++ bool show_top_left = false;+ bool show_bottom_right = false;bool rtl = is_layout_rtl();- if (show_vertical_hints) {- scroll_hint_top_left->set_texture(theme_cache.scroll_hint_vertical);- scroll_hint_top_left->set_modulate(theme_cache.scroll_hint_vertical_color);- scroll_hint_top_left->set_visible(!show_horizontal_hints && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT) && v_scroll_value > 1);- scroll_hint_top_left->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? -size.x : 0);- scroll_hint_top_left->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? 0 : size.x);- scroll_hint_top_left->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);- scroll_hint_top_left->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_BEGIN, theme_cache.scroll_hint_vertical->get_height());-- scroll_hint_bottom_right->set_flip_h(false);- scroll_hint_bottom_right->set_flip_v(true);- scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_vertical);- scroll_hint_bottom_right->set_modulate(theme_cache.scroll_hint_vertical_color);- scroll_hint_bottom_right->set_visible(!show_horizontal_hints && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT) && v_scroll_below_max);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? -size.x : 0);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? 0 : size.x);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -theme_cache.scroll_hint_vertical->get_height());- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);- } else {- scroll_hint_top_left->set_texture(theme_cache.scroll_hint_horizontal);- scroll_hint_top_left->set_modulate(theme_cache.scroll_hint_horizontal_color);- scroll_hint_top_left->set_visible(!show_vertical_hints && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT : scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT)) && h_scroll_value > 1);- scroll_hint_top_left->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? (size.x - theme_cache.scroll_hint_horizontal->get_width()) : 0);- scroll_hint_top_left->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_BEGIN, rtl ? size.x : theme_cache.scroll_hint_horizontal->get_width());- scroll_hint_top_left->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);- scroll_hint_top_left->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);-- scroll_hint_bottom_right->set_flip_h(true);- scroll_hint_bottom_right->set_flip_v(false);- scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_horizontal);- scroll_hint_bottom_right->set_modulate(theme_cache.scroll_hint_horizontal_color);- scroll_hint_bottom_right->set_visible(!show_vertical_hints && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT : scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT)) && h_scroll_below_max);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, rtl ? -size.x : -theme_cache.scroll_hint_horizontal->get_width());- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? (-size.x + theme_cache.scroll_hint_horizontal->get_width()) : 0);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);- scroll_hint_bottom_right->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);++ if (is_v_scrolled && scroll_hint_mode != SCROLL_HINT_MODE_RIGHT && scroll_hint_mode != SCROLL_HINT_MODE_LEFT && scroll_hint_mode != SCROLL_HINT_MODE_LEFT_AND_RIGHT) {+ if (v_scroll_value > 1) {+ show_top_left = (!h_scroll->is_visible() && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT)) ||+ scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_BOTTOM || scroll_hint_mode == SCROLL_HINT_MODE_TOP;+ }+ if (show_top_left) {+ scroll_hint_top_left->set_texture(theme_cache.scroll_hint_vertical);+ scroll_hint_top_left->set_modulate(theme_cache.scroll_hint_vertical_color);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? -size.x : 0);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? 0 : size.x);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_BEGIN, theme_cache.scroll_hint_vertical->get_height());+ }++ if (v_scroll_below_max) {+ show_bottom_right = (!h_scroll->is_visible() && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT)) ||+ scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_BOTTOM || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM;+ }+ if (show_bottom_right) {+ scroll_hint_bottom_right->set_flip_h(false);+ scroll_hint_bottom_right->set_flip_v(true);+ scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_vertical);+ scroll_hint_bottom_right->set_modulate(theme_cache.scroll_hint_vertical_color);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? -size.x : 0);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? 0 : size.x);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -theme_cache.scroll_hint_vertical->get_height());+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);+ }+ } else if (is_h_scrolled) {+ if (h_scroll_value > 1) {+ show_top_left = (!v_scroll->is_visible() && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT : scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT))) ||+ scroll_hint_mode == SCROLL_HINT_MODE_LEFT_AND_RIGHT || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_RIGHT : scroll_hint_mode == SCROLL_HINT_MODE_LEFT);+ }+ if (show_top_left) {+ scroll_hint_top_left->set_texture(theme_cache.scroll_hint_horizontal);+ scroll_hint_top_left->set_modulate(theme_cache.scroll_hint_horizontal_color);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, rtl ? (size.x - theme_cache.scroll_hint_horizontal->get_width()) : 0);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_BEGIN, rtl ? size.x : theme_cache.scroll_hint_horizontal->get_width());+ scroll_hint_top_left->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);+ scroll_hint_top_left->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);+ }++ if (h_scroll_below_max) {+ show_bottom_right = (!v_scroll->is_visible() && (scroll_hint_mode == SCROLL_HINT_MODE_ALL || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT : scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT))) ||+ scroll_hint_mode == SCROLL_HINT_MODE_LEFT_AND_RIGHT || (rtl ? scroll_hint_mode == SCROLL_HINT_MODE_LEFT : scroll_hint_mode == SCROLL_HINT_MODE_RIGHT);+ }+ if (show_bottom_right) {+ scroll_hint_bottom_right->set_flip_h(true);+ scroll_hint_bottom_right->set_flip_v(false);+ scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_horizontal);+ scroll_hint_bottom_right->set_modulate(theme_cache.scroll_hint_horizontal_color);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, rtl ? -size.x : -theme_cache.scroll_hint_horizontal->get_width());+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, rtl ? (-size.x + theme_cache.scroll_hint_horizontal->get_width()) : 0);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);+ scroll_hint_bottom_right->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);+ }}++ scroll_hint_top_left->set_visible(show_top_left);+ scroll_hint_bottom_right->set_visible(show_bottom_right);}void ScrollContainer::_scroll_moved(float) {@@ -1014,7 +1041,7 @@ void ScrollContainer::_bind_methods() {ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_deadzone"), "set_deadzone", "get_deadzone");ADD_GROUP("Scroll Hint", "");- ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_hint_mode", PROPERTY_HINT_ENUM, "Disabled,All,Top and Left,Bottom and Right"), "set_scroll_hint_mode", "get_scroll_hint_mode");+ ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_hint_mode", PROPERTY_HINT_ENUM, "Disabled,All,Top and Left,Bottom and Right,Top and Bottom,Left and Right,Top,Bottom,Left,Right"), "set_scroll_hint_mode", "get_scroll_hint_mode");ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tile_scroll_hint"), "set_tile_scroll_hint", "is_scroll_hint_tiled");BIND_ENUM_CONSTANT(SCROLL_MODE_DISABLED);@@ -1028,6 +1055,12 @@ void ScrollContainer::_bind_methods() {BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_ALL);BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP_AND_LEFT);BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTTOM_AND_RIGHT);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP_AND_BOTTOM);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_LEFT_AND_RIGHT);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTTOM);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_LEFT);+ BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_RIGHT);BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_h_separation);BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_v_separation);diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.hindex 3526086fbb8..d90ac37b380 100644--- a/scene/gui/scroll_container.h+++ b/scene/gui/scroll_container.h@@ -54,6 +54,12 @@ public:SCROLL_HINT_MODE_ALL,SCROLL_HINT_MODE_TOP_AND_LEFT,SCROLL_HINT_MODE_BOTTOM_AND_RIGHT,+ SCROLL_HINT_MODE_TOP_AND_BOTTOM,+ SCROLL_HINT_MODE_LEFT_AND_RIGHT,+ SCROLL_HINT_MODE_TOP,+ SCROLL_HINT_MODE_BOTTOM,+ SCROLL_HINT_MODE_LEFT,+ SCROLL_HINT_MODE_RIGHT,};private: