Skip to content

Commit ab554d5

Browse files
committed
Add scroll hints to ScrollContainer and Tree
1 parent cb3af5a commit ab554d5

File tree

11 files changed

+268
-12
lines changed

11 files changed

+268
-12
lines changed

doc/classes/ScrollContainer.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
<member name="scroll_deadzone" type="int" setter="set_deadzone" getter="get_deadzone" default="0">
5353
Deadzone for touch scrolling. Lower deadzone makes the scrolling more sensitive.
5454
</member>
55+
<member name="scroll_hint_mode" type="int" setter="set_scroll_hint_mode" getter="get_scroll_hint_mode" enum="ScrollContainer.ScrollHintMode" default="0">
56+
The way which scroll hints (indicators that show that the content can still be scrolled in a certain direction) will be shown.
57+
[b]Note:[/b] Hints won't be shown if the content can be scrolled both vertically and horizontally.
58+
</member>
5559
<member name="scroll_horizontal" type="int" setter="set_h_scroll" getter="get_h_scroll" default="0">
5660
The current horizontal scroll value.
5761
[b]Note:[/b] If you are setting this value in the [method Node._ready] function or earlier, it needs to be wrapped with [method Object.set_deferred], since scroll bar's [member Range.max_value] is not initialized yet.
@@ -74,6 +78,9 @@
7478
<member name="scroll_vertical_custom_step" type="float" setter="set_vertical_custom_step" getter="get_vertical_custom_step" default="-1.0">
7579
Overrides the [member ScrollBar.custom_step] used when clicking the internal scroll bar's vertical increment and decrement buttons or when using arrow keys when the [ScrollBar] is focused.
7680
</member>
81+
<member name="tile_scroll_hint" type="bool" setter="set_tile_scroll_hint" getter="is_scroll_hint_tiled" default="false">
82+
If [code]true[/code], the scroll hint texture will be tiled instead of stretched. See [member scroll_hint_mode].
83+
</member>
7784
<member name="vertical_scroll_mode" type="int" setter="set_vertical_scroll_mode" getter="get_vertical_scroll_mode" enum="ScrollContainer.ScrollMode" default="1">
7885
Controls whether vertical scrollbar can be used and when it should be visible.
7986
</member>
@@ -108,6 +115,18 @@
108115
<constant name="SCROLL_MODE_RESERVE" value="4" enum="ScrollMode">
109116
Combines [constant SCROLL_MODE_AUTO] and [constant SCROLL_MODE_SHOW_ALWAYS]. The scrollbar is only visible if necessary, but the content size is adjusted as if it was always visible. It's useful for ensuring that content size stays the same regardless if the scrollbar is visible.
110117
</constant>
118+
<constant name="SCROLL_HINT_MODE_DISABLED" value="0" enum="ScrollHintMode">
119+
Scroll hints will never be shown.
120+
</constant>
121+
<constant name="SCROLL_HINT_MODE_ALL" value="1" enum="ScrollHintMode">
122+
Scroll hints will be shown at the top and bottom (if vertical), or left and right (if horizontal).
123+
</constant>
124+
<constant name="SCROLL_HINT_MODE_TOP_AND_LEFT" value="2" enum="ScrollHintMode">
125+
Scroll hints will be shown at the top (if vertical), or the left (if horizontal).
126+
</constant>
127+
<constant name="SCROLL_HINT_MODE_BOTTOM_AND_RIGHT" value="3" enum="ScrollHintMode">
128+
Scroll hints will be shown at the bottom (if horizontal), or the right (if horizontal).
129+
</constant>
111130
</constants>
112131
<theme_items>
113132
<theme_item name="scrollbar_h_separation" data_type="constant" type="int" default="0">
@@ -116,6 +135,12 @@
116135
<theme_item name="scrollbar_v_separation" data_type="constant" type="int" default="0">
117136
The space between the ScrollContainer's horizontal scroll bar and its content, in pixels. No space will be added when the content's minimum size is larger than the ScrollContainer's size.
118137
</theme_item>
138+
<theme_item name="scroll_hint_horizontal" data_type="icon" type="Texture2D">
139+
The indicator that will be shown when the content can still be scrolled horizontally. See [member scroll_hint_mode].
140+
</theme_item>
141+
<theme_item name="scroll_hint_vertical" data_type="icon" type="Texture2D">
142+
The indicator that will be shown when the content can still be scrolled vertically. See [member scroll_hint_mode].
143+
</theme_item>
119144
<theme_item name="focus" data_type="style" type="StyleBox">
120145
The focus border [StyleBox] of the [ScrollContainer]. Only used if [member draw_focus_border] is [code]true[/code].
121146
</theme_item>

doc/classes/Tree.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@
383383
<member name="hide_root" type="bool" setter="set_hide_root" getter="is_root_hidden" default="false">
384384
If [code]true[/code], the tree's root is hidden.
385385
</member>
386+
<member name="scroll_hint_mode" type="int" setter="set_scroll_hint_mode" getter="get_scroll_hint_mode" enum="Tree.ScrollHintMode" default="0">
387+
The way which scroll hints (indicators that show that the content can still be scrolled in a certain direction) will be shown.
388+
</member>
386389
<member name="scroll_horizontal_enabled" type="bool" setter="set_h_scroll_enabled" getter="is_h_scroll_enabled" default="true">
387390
If [code]true[/code], enables horizontal scrolling.
388391
</member>
@@ -392,6 +395,9 @@
392395
<member name="select_mode" type="int" setter="set_select_mode" getter="get_select_mode" enum="Tree.SelectMode" default="0">
393396
Allows single or multiple selection. See the [enum SelectMode] constants.
394397
</member>
398+
<member name="tile_scroll_hint" type="bool" setter="set_tile_scroll_hint" getter="is_scroll_hint_tiled" default="false">
399+
If [code]true[/code], the scroll hint texture will be tiled instead of stretched. See [member scroll_hint_mode].
400+
</member>
395401
</members>
396402
<signals>
397403
<signal name="button_clicked">
@@ -514,6 +520,18 @@
514520
Enables "above item" and "below item" drop sections. The "above item" drop section covers the top half of the item, and the "below item" drop section covers the bottom half.
515521
When combined with [constant DROP_MODE_ON_ITEM], these drop sections halves the height and stays on top / bottom accordingly.
516522
</constant>
523+
<constant name="SCROLL_HINT_MODE_DISABLED" value="0" enum="ScrollHintMode">
524+
Scroll hints will never be shown.
525+
</constant>
526+
<constant name="SCROLL_HINT_MODE_BOTH" value="1" enum="ScrollHintMode">
527+
Scroll hints will be shown at the top and bottom.
528+
</constant>
529+
<constant name="SCROLL_HINT_MODE_TOP" value="2" enum="ScrollHintMode">
530+
Only the top scroll hint will be shown.
531+
</constant>
532+
<constant name="SCROLL_HINT_MODE_BOTTOM" value="3" enum="ScrollHintMode">
533+
Only the bottom scroll hint will be shown.
534+
</constant>
517535
</constants>
518536
<theme_items>
519537
<theme_item name="children_hl_line_color" data_type="color" type="Color" default="Color(0.27, 0.27, 0.27, 1)">
@@ -667,6 +685,9 @@
667685
<theme_item name="indeterminate_disabled" data_type="icon" type="Texture2D">
668686
The check icon to display when the [constant TreeItem.CELL_MODE_CHECK] mode cell is indeterminate and non-editable (see [method TreeItem.set_editable]).
669687
</theme_item>
688+
<theme_item name="scroll_hint" data_type="icon" type="Texture2D">
689+
The indicator that will be shown when the content can still be scrolled. See [member scroll_hint_mode].
690+
</theme_item>
670691
<theme_item name="select_arrow" data_type="icon" type="Texture2D">
671692
The arrow icon to display for the [constant TreeItem.CELL_MODE_RANGE] mode cell.
672693
</theme_item>

editor/docks/inspector_dock.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ InspectorDock::InspectorDock(EditorData &p_editor_data) {
873873
inspector->set_property_name_style(property_name_style);
874874
inspector->set_use_folding(!bool(EDITOR_GET("interface/inspector/disable_folding")));
875875
inspector->register_text_enter(search);
876+
inspector->set_scroll_hint_mode(ScrollContainer::SCROLL_HINT_MODE_TOP_AND_LEFT);
876877

877878
inspector->set_use_filter(true);
878879

editor/themes/theme_classic.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "editor/themes/editor_scale.h"
3636
#include "editor/themes/editor_theme_manager.h"
3737
#include "scene/gui/graph_edit.h"
38+
#include "scene/resources/compressed_texture.h"
3839
#include "scene/resources/dpi_texture.h"
3940
#include "scene/resources/image_texture.h"
4041
#include "scene/resources/style_box_flat.h"
@@ -1551,6 +1552,13 @@ void ThemeClassic::populate_editor_styles(const Ref<EditorTheme> &p_theme, Edito
15511552
Ref<StyleBoxFlat> style_widget_scroll_container = p_config.button_style_focus->duplicate();
15521553
p_theme->set_stylebox("focus", "ScrollContainer", style_widget_scroll_container);
15531554

1555+
// Hide scroll hints.
1556+
Ref<CompressedTexture2D> empty_texture;
1557+
empty_texture.instantiate();
1558+
p_theme->set_icon("scroll_hint_vertical", "ScrollContainer", empty_texture);
1559+
p_theme->set_icon("scroll_hint_horizontal", "ScrollContainer", empty_texture);
1560+
p_theme->set_icon("scroll_hint", "Tree", empty_texture);
1561+
15541562
// This stylebox is used in 3d and 2d viewports (no borders).
15551563
Ref<StyleBoxFlat> style_content_panel_vp = p_config.content_panel_style->duplicate();
15561564
style_content_panel_vp->set_content_margin_individual(p_config.border_width * 2, p_config.base_margin * EDSCALE, p_config.border_width * 2, p_config.border_width * 2);

scene/gui/scroll_container.cpp

Lines changed: 105 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "core/config/project_settings.h"
3434
#include "scene/gui/panel_container.h"
35+
#include "scene/gui/texture_rect.h"
3536
#include "scene/main/window.h"
3637
#include "scene/theme/theme_db.h"
3738

@@ -343,6 +344,7 @@ void ScrollContainer::ensure_control_visible(Control *p_control) {
343344

344345
void ScrollContainer::_reposition_children() {
345346
update_scrollbars();
347+
update_scroll_hints();
346348

347349
Rect2 margins = _get_margins();
348350
Size2 size = get_size();
@@ -362,10 +364,7 @@ void ScrollContainer::_reposition_children() {
362364

363365
for (int i = 0; i < get_child_count(); i++) {
364366
Control *c = as_sortable_control(get_child(i));
365-
if (!c) {
366-
continue;
367-
}
368-
if (c == h_scroll || c == v_scroll || c == focus_panel) {
367+
if (!c || c->is_internal()) {
369368
continue;
370369
}
371370
Size2 minsize = c->get_combined_minimum_size();
@@ -445,7 +444,10 @@ void ScrollContainer::_notification(int p_what) {
445444
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_SET_SCROLL_OFFSET, callable_mp(this, &ScrollContainer::_accessibility_action_scroll_set));
446445
} break;
447446

448-
case NOTIFICATION_THEME_CHANGED:
447+
case NOTIFICATION_THEME_CHANGED: {
448+
update_scroll_hints();
449+
[[fallthrough]];
450+
}
449451
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
450452
case NOTIFICATION_TRANSLATION_CHANGED: {
451453
_updating_scrollbars = true;
@@ -602,6 +604,48 @@ void ScrollContainer::update_scrollbars() {
602604
callable_mp(this, &ScrollContainer::_update_scrollbar_position).call_deferred();
603605
}
604606

607+
void ScrollContainer::update_scroll_hints() {
608+
Size2 size = get_size();
609+
Rect2 margins = _get_margins();
610+
Size2 scroll_size = size - margins.position + margins.size;
611+
612+
float v_scroll_value = v_scroll->get_value();
613+
bool v_scroll_below_max = v_scroll_value < (largest_child_min_size.height - scroll_size.height - 1);
614+
bool show_vertical_hints = v_scroll_value > 1 || v_scroll_below_max;
615+
616+
float h_scroll_value = h_scroll->get_value();
617+
bool h_scroll_below_max = h_scroll_value < (largest_child_min_size.width - scroll_size.width - 1);
618+
bool show_horizontal_hints = h_scroll_value > 1 || h_scroll_below_max;
619+
620+
if (show_vertical_hints) {
621+
scroll_hint_top_left->set_texture(theme_cache.scroll_hint_vertical);
622+
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);
623+
scroll_hint_top_left->set_offsets_preset(PRESET_TOP_WIDE, LayoutPresetMode::PRESET_MODE_MINSIZE);
624+
625+
scroll_hint_bottom_right->set_flip_h(false);
626+
scroll_hint_bottom_right->set_flip_v(true);
627+
scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_vertical);
628+
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);
629+
scroll_hint_bottom_right->set_offsets_preset(PRESET_BOTTOM_WIDE, LayoutPresetMode::PRESET_MODE_MINSIZE);
630+
} else {
631+
bool rtl = is_layout_rtl();
632+
633+
scroll_hint_top_left->set_texture(theme_cache.scroll_hint_horizontal);
634+
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);
635+
scroll_hint_top_left->set_offsets_preset(rtl ? PRESET_RIGHT_WIDE : PRESET_LEFT_WIDE, LayoutPresetMode::PRESET_MODE_MINSIZE);
636+
if (rtl) {
637+
// TODO: Find out why this is even necessary.
638+
scroll_hint_top_left->set_position(Point2(0, scroll_hint_top_left->get_position().y));
639+
}
640+
641+
scroll_hint_bottom_right->set_flip_h(true);
642+
scroll_hint_bottom_right->set_flip_v(false);
643+
scroll_hint_bottom_right->set_texture(theme_cache.scroll_hint_horizontal);
644+
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);
645+
scroll_hint_bottom_right->set_offsets_preset(rtl ? PRESET_LEFT_WIDE : PRESET_RIGHT_WIDE, LayoutPresetMode::PRESET_MODE_MINSIZE);
646+
}
647+
}
648+
605649
void ScrollContainer::_scroll_moved(float) {
606650
queue_sort();
607651
}
@@ -676,6 +720,32 @@ void ScrollContainer::set_deadzone(int p_deadzone) {
676720
deadzone = p_deadzone;
677721
}
678722

723+
void ScrollContainer::set_scroll_hint_mode(ScrollHintMode p_mode) {
724+
if (scroll_hint_mode == p_mode) {
725+
return;
726+
}
727+
728+
scroll_hint_mode = p_mode;
729+
update_scroll_hints();
730+
}
731+
732+
ScrollContainer::ScrollHintMode ScrollContainer::get_scroll_hint_mode() const {
733+
return scroll_hint_mode;
734+
}
735+
736+
void ScrollContainer::set_tile_scroll_hint(bool p_enable) {
737+
if (tile_scroll_hint != p_enable) {
738+
return;
739+
}
740+
741+
tile_scroll_hint = p_enable;
742+
update_scroll_hints();
743+
}
744+
745+
bool ScrollContainer::is_scroll_hint_tiled() {
746+
return tile_scroll_hint;
747+
}
748+
679749
bool ScrollContainer::is_following_focus() const {
680750
return follow_focus;
681751
}
@@ -691,10 +761,7 @@ PackedStringArray ScrollContainer::get_configuration_warnings() const {
691761

692762
for (int i = 0; i < get_child_count(); i++) {
693763
Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);
694-
if (!c) {
695-
continue;
696-
}
697-
if (c == h_scroll || c == v_scroll || c == focus_panel) {
764+
if (!c || c->is_internal()) {
698765
continue;
699766
}
700767

@@ -742,6 +809,12 @@ void ScrollContainer::_bind_methods() {
742809
ClassDB::bind_method(D_METHOD("set_deadzone", "deadzone"), &ScrollContainer::set_deadzone);
743810
ClassDB::bind_method(D_METHOD("get_deadzone"), &ScrollContainer::get_deadzone);
744811

812+
ClassDB::bind_method(D_METHOD("set_scroll_hint_mode", "scroll_hint_mode"), &ScrollContainer::set_scroll_hint_mode);
813+
ClassDB::bind_method(D_METHOD("get_scroll_hint_mode"), &ScrollContainer::get_scroll_hint_mode);
814+
815+
ClassDB::bind_method(D_METHOD("set_tile_scroll_hint", "tile_scroll_hint"), &ScrollContainer::set_tile_scroll_hint);
816+
ClassDB::bind_method(D_METHOD("is_scroll_hint_tiled"), &ScrollContainer::is_scroll_hint_tiled);
817+
745818
ClassDB::bind_method(D_METHOD("set_follow_focus", "enabled"), &ScrollContainer::set_follow_focus);
746819
ClassDB::bind_method(D_METHOD("is_following_focus"), &ScrollContainer::is_following_focus);
747820

@@ -758,7 +831,7 @@ void ScrollContainer::_bind_methods() {
758831
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_focus"), "set_follow_focus", "is_following_focus");
759832
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_focus_border"), "set_draw_focus_border", "get_draw_focus_border");
760833

761-
ADD_GROUP("Scroll", "scroll_");
834+
ADD_GROUP("Scrollbar", "");
762835
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal", PROPERTY_HINT_NONE, "suffix:px"), "set_h_scroll", "get_h_scroll");
763836
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_vertical", PROPERTY_HINT_NONE, "suffix:px"), "set_v_scroll", "get_v_scroll");
764837
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_horizontal_custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_horizontal_custom_step", "get_horizontal_custom_step");
@@ -767,18 +840,30 @@ void ScrollContainer::_bind_methods() {
767840
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show,Reserve"), "set_vertical_scroll_mode", "get_vertical_scroll_mode");
768841
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_deadzone"), "set_deadzone", "get_deadzone");
769842

843+
ADD_GROUP("Scroll Hint", "");
844+
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");
845+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tile_scroll_hint"), "set_tile_scroll_hint", "is_scroll_hint_tiled");
846+
770847
BIND_ENUM_CONSTANT(SCROLL_MODE_DISABLED);
771848
BIND_ENUM_CONSTANT(SCROLL_MODE_AUTO);
772849
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_ALWAYS);
773850
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_NEVER);
774851
BIND_ENUM_CONSTANT(SCROLL_MODE_RESERVE);
775852

853+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_DISABLED);
854+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_ALL);
855+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP_AND_LEFT);
856+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTTOM_AND_RIGHT);
857+
776858
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_h_separation);
777859
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_v_separation);
778860

779861
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, panel_style, "panel");
780862
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, focus_style, "focus");
781863

864+
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ScrollContainer, scroll_hint_vertical);
865+
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ScrollContainer, scroll_hint_horizontal);
866+
782867
GLOBAL_DEF("gui/common/default_scroll_deadzone", 0);
783868
}
784869

@@ -802,6 +887,16 @@ bool ScrollContainer::child_has_focus() {
802887
}
803888

804889
ScrollContainer::ScrollContainer() {
890+
scroll_hint_top_left = memnew(TextureRect);
891+
scroll_hint_top_left->set_mouse_filter(MOUSE_FILTER_IGNORE);
892+
scroll_hint_top_left->hide();
893+
add_child(scroll_hint_top_left, false, INTERNAL_MODE_BACK);
894+
895+
scroll_hint_bottom_right = memnew(TextureRect);
896+
scroll_hint_bottom_right->set_mouse_filter(MOUSE_FILTER_IGNORE);
897+
scroll_hint_bottom_right->hide();
898+
add_child(scroll_hint_bottom_right, false, INTERNAL_MODE_BACK);
899+
805900
h_scroll = memnew(HScrollBar);
806901
h_scroll->set_name("_h_scroll");
807902
add_child(h_scroll, false, INTERNAL_MODE_BACK);

0 commit comments

Comments
 (0)