Skip to content

Commit dd6fd90

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

File tree

10 files changed

+233
-3
lines changed

10 files changed

+233
-3
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 scroll 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 in the top and bottom (if horizontal), or left and right (if vertical).
123+
</constant>
124+
<constant name="SCROLL_HINT_MODE_TOP_AND_LEFT" value="2" enum="ScrollHintMode">
125+
Scroll hints will be shown in the top (if horizontal), or the left (if vertical).
126+
</constant>
127+
<constant name="SCROLL_HINT_MODE_BOTTOM_AND_RIGHT" value="3" enum="ScrollHintMode">
128+
Scroll hints will be shown in the bottom (if horizontal), or the right (if vertical).
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 in 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/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: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,38 @@ void ScrollContainer::_notification(int p_what) {
472472
draw_style_box(theme_cache.panel_style, Rect2(Vector2(), get_size()));
473473
focus_border_is_drawn = draw_focus_border && (has_focus(true) || child_has_focus());
474474
focus_panel->set_visible(focus_border_is_drawn);
475+
476+
if (scroll_hint_mode != SCROLL_HINT_MODE_DISABLED) {
477+
Size2 size = get_size();
478+
Rect2 margins = _get_margins();
479+
Size2 scroll_size = size - margins.position + margins.size;
480+
481+
float v_scroll_value = v_scroll->get_value();
482+
bool v_scroll_below_max = v_scroll_value < (largest_child_min_size.height - scroll_size.height - 1);
483+
bool show_vertical_hints = v_scroll_value > 1 || v_scroll_below_max;
484+
485+
float h_scroll_value = h_scroll->get_value();
486+
bool h_scroll_below_max = h_scroll_value < (largest_child_min_size.width - scroll_size.width - 1);
487+
bool show_horizontal_hints = h_scroll_value > 1 || h_scroll_below_max;
488+
489+
if (show_vertical_hints && !show_horizontal_hints) {
490+
int hint_height = theme_cache.scroll_hint_vertical->get_height();
491+
if ((scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT) && v_scroll_value > 1) {
492+
draw_texture_rect(theme_cache.scroll_hint_vertical, Rect2(Point2(), Size2(size.width, hint_height)), tile_scroll_hint);
493+
}
494+
if ((scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT) && v_scroll_below_max) {
495+
draw_texture_rect(theme_cache.scroll_hint_vertical, Rect2(Point2(0, size.height - hint_height), Size2(size.width, -hint_height)), tile_scroll_hint);
496+
}
497+
} else if (show_horizontal_hints && !show_vertical_hints) {
498+
int hint_width = theme_cache.scroll_hint_horizontal->get_width();
499+
if ((scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_TOP_AND_LEFT) && h_scroll_value > 1) {
500+
draw_texture_rect(theme_cache.scroll_hint_horizontal, Rect2(Point2(), Size2(hint_width, size.height)), tile_scroll_hint);
501+
}
502+
if ((scroll_hint_mode == SCROLL_HINT_MODE_ALL || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM_AND_RIGHT) && h_scroll_below_max) {
503+
draw_texture_rect(theme_cache.scroll_hint_horizontal, Rect2(Point2(size.width - hint_width, 0), Size2(-hint_width, size.height)), tile_scroll_hint);
504+
}
505+
}
506+
}
475507
} break;
476508

477509
case NOTIFICATION_DRAG_BEGIN: {
@@ -676,6 +708,32 @@ void ScrollContainer::set_deadzone(int p_deadzone) {
676708
deadzone = p_deadzone;
677709
}
678710

711+
void ScrollContainer::set_scroll_hint_mode(ScrollHintMode p_mode) {
712+
ScrollHintMode prev_mode = scroll_hint_mode;
713+
scroll_hint_mode = p_mode;
714+
715+
if (scroll_hint_mode != prev_mode) {
716+
queue_redraw();
717+
}
718+
}
719+
720+
ScrollContainer::ScrollHintMode ScrollContainer::get_scroll_hint_mode() const {
721+
return scroll_hint_mode;
722+
}
723+
724+
void ScrollContainer::set_tile_scroll_hint(bool p_enable) {
725+
bool prev_tile = tile_scroll_hint;
726+
tile_scroll_hint = p_enable;
727+
728+
if (tile_scroll_hint != prev_tile) {
729+
queue_redraw();
730+
}
731+
}
732+
733+
bool ScrollContainer::is_scroll_hint_tiled() {
734+
return tile_scroll_hint;
735+
}
736+
679737
bool ScrollContainer::is_following_focus() const {
680738
return follow_focus;
681739
}
@@ -742,6 +800,12 @@ void ScrollContainer::_bind_methods() {
742800
ClassDB::bind_method(D_METHOD("set_deadzone", "deadzone"), &ScrollContainer::set_deadzone);
743801
ClassDB::bind_method(D_METHOD("get_deadzone"), &ScrollContainer::get_deadzone);
744802

803+
ClassDB::bind_method(D_METHOD("set_scroll_hint_mode", "scroll_hint_mode"), &ScrollContainer::set_scroll_hint_mode);
804+
ClassDB::bind_method(D_METHOD("get_scroll_hint_mode"), &ScrollContainer::get_scroll_hint_mode);
805+
806+
ClassDB::bind_method(D_METHOD("set_tile_scroll_hint", "tile_scroll_hint"), &ScrollContainer::set_tile_scroll_hint);
807+
ClassDB::bind_method(D_METHOD("is_scroll_hint_tiled"), &ScrollContainer::is_scroll_hint_tiled);
808+
745809
ClassDB::bind_method(D_METHOD("set_follow_focus", "enabled"), &ScrollContainer::set_follow_focus);
746810
ClassDB::bind_method(D_METHOD("is_following_focus"), &ScrollContainer::is_following_focus);
747811

@@ -758,7 +822,7 @@ void ScrollContainer::_bind_methods() {
758822
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_focus"), "set_follow_focus", "is_following_focus");
759823
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_focus_border"), "set_draw_focus_border", "get_draw_focus_border");
760824

761-
ADD_GROUP("Scroll", "scroll_");
825+
ADD_GROUP("Scrollbar", "");
762826
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal", PROPERTY_HINT_NONE, "suffix:px"), "set_h_scroll", "get_h_scroll");
763827
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_vertical", PROPERTY_HINT_NONE, "suffix:px"), "set_v_scroll", "get_v_scroll");
764828
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 +831,30 @@ void ScrollContainer::_bind_methods() {
767831
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");
768832
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_deadzone"), "set_deadzone", "get_deadzone");
769833

834+
ADD_GROUP("Scroll Hint", "");
835+
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");
836+
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tile_scroll_hint"), "set_tile_scroll_hint", "is_scroll_hint_tiled");
837+
770838
BIND_ENUM_CONSTANT(SCROLL_MODE_DISABLED);
771839
BIND_ENUM_CONSTANT(SCROLL_MODE_AUTO);
772840
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_ALWAYS);
773841
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_NEVER);
774842
BIND_ENUM_CONSTANT(SCROLL_MODE_RESERVE);
775843

844+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_DISABLED);
845+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_ALL);
846+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP_AND_LEFT);
847+
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTTOM_AND_RIGHT);
848+
776849
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_h_separation);
777850
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ScrollContainer, scrollbar_v_separation);
778851

779852
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, panel_style, "panel");
780853
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, focus_style, "focus");
781854

855+
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ScrollContainer, scroll_hint_vertical);
856+
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ScrollContainer, scroll_hint_horizontal);
857+
782858
GLOBAL_DEF("gui/common/default_scroll_deadzone", 0);
783859
}
784860

scene/gui/scroll_container.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ class ScrollContainer : public Container {
4848
SCROLL_MODE_RESERVE,
4949
};
5050

51+
enum ScrollHintMode {
52+
SCROLL_HINT_MODE_DISABLED,
53+
SCROLL_HINT_MODE_ALL,
54+
SCROLL_HINT_MODE_TOP_AND_LEFT,
55+
SCROLL_HINT_MODE_BOTTOM_AND_RIGHT,
56+
};
57+
5158
private:
5259
HScrollBar *h_scroll = nullptr;
5360
VScrollBar *v_scroll = nullptr;
@@ -75,10 +82,16 @@ class ScrollContainer : public Container {
7582
int scroll_border = 20;
7683
int scroll_speed = 12;
7784

85+
ScrollHintMode scroll_hint_mode = SCROLL_HINT_MODE_DISABLED;
86+
bool tile_scroll_hint = false;
87+
7888
struct ThemeCache {
7989
Ref<StyleBox> panel_style;
8090
Ref<StyleBox> focus_style;
8191

92+
Ref<Texture2D> scroll_hint_vertical;
93+
Ref<Texture2D> scroll_hint_horizontal;
94+
8295
int scrollbar_h_separation = 0;
8396
int scrollbar_v_separation = 0;
8497
} theme_cache;
@@ -134,8 +147,14 @@ class ScrollContainer : public Container {
134147
void set_vertical_scroll_mode(ScrollMode p_mode);
135148
ScrollMode get_vertical_scroll_mode() const;
136149

137-
int get_deadzone() const;
138150
void set_deadzone(int p_deadzone);
151+
int get_deadzone() const;
152+
153+
void set_scroll_hint_mode(ScrollHintMode p_mode);
154+
ScrollHintMode get_scroll_hint_mode() const;
155+
156+
void set_tile_scroll_hint(bool p_enable);
157+
bool is_scroll_hint_tiled();
139158

140159
bool is_following_focus() const;
141160
void set_follow_focus(bool p_follow);
@@ -155,3 +174,4 @@ class ScrollContainer : public Container {
155174
};
156175

157176
VARIANT_ENUM_CAST(ScrollContainer::ScrollMode);
177+
VARIANT_ENUM_CAST(ScrollContainer::ScrollHintMode);

0 commit comments

Comments
 (0)