Merge pull request #113574 from YeldhamDev/take_the_hint
Enable scroll hints for several parts of the editor
This commit is contained in:
@@ -1705,6 +1705,21 @@ void ItemList::_notification(int p_what) {
|
||||
draw_style_box(cursor, cursor_rcache);
|
||||
}
|
||||
|
||||
if (scroll_hint_mode != SCROLL_HINT_MODE_DISABLED) {
|
||||
Size2 control_size = get_size();
|
||||
float v_scroll_value = scroll_bar_v->get_value();
|
||||
bool v_scroll_below_max = v_scroll_value < (scroll_bar_v->get_max() - scroll_bar_v->get_page() - 1);
|
||||
if (v_scroll_value > 1 || v_scroll_below_max) {
|
||||
int hint_height = theme_cache.scroll_hint->get_height();
|
||||
if ((scroll_hint_mode == SCROLL_HINT_MODE_BOTH || scroll_hint_mode == SCROLL_HINT_MODE_TOP) && v_scroll_value > 1) {
|
||||
draw_texture_rect(theme_cache.scroll_hint, Rect2(Point2(), Size2(control_size.width, hint_height)), tile_scroll_hint);
|
||||
}
|
||||
if ((scroll_hint_mode == SCROLL_HINT_MODE_BOTH || scroll_hint_mode == SCROLL_HINT_MODE_BOTTOM) && v_scroll_below_max) {
|
||||
draw_texture_rect(theme_cache.scroll_hint, Rect2(Point2(0, control_size.height - hint_height), Size2(control_size.width, -hint_height)), tile_scroll_hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (has_focus(true)) {
|
||||
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
|
||||
size.x -= (scroll_bar_h->get_max() - scroll_bar_h->get_page());
|
||||
@@ -2193,6 +2208,32 @@ bool ItemList::has_wraparound_items() const {
|
||||
return wraparound_items;
|
||||
}
|
||||
|
||||
void ItemList::set_scroll_hint_mode(ScrollHintMode p_mode) {
|
||||
if (scroll_hint_mode == p_mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
scroll_hint_mode = p_mode;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
ItemList::ScrollHintMode ItemList::get_scroll_hint_mode() const {
|
||||
return scroll_hint_mode;
|
||||
}
|
||||
|
||||
void ItemList::set_tile_scroll_hint(bool p_enable) {
|
||||
if (tile_scroll_hint == p_enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
tile_scroll_hint = p_enable;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool ItemList::is_scroll_hint_tiled() {
|
||||
return tile_scroll_hint;
|
||||
}
|
||||
|
||||
bool ItemList::_set(const StringName &p_name, const Variant &p_value) {
|
||||
if (property_helper.property_set_value(p_name, p_value)) {
|
||||
return true;
|
||||
@@ -2334,6 +2375,12 @@ void ItemList::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_v_scroll_bar"), &ItemList::get_v_scroll_bar);
|
||||
ClassDB::bind_method(D_METHOD("get_h_scroll_bar"), &ItemList::get_h_scroll_bar);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_scroll_hint_mode", "scroll_hint_mode"), &ItemList::set_scroll_hint_mode);
|
||||
ClassDB::bind_method(D_METHOD("get_scroll_hint_mode"), &ItemList::get_scroll_hint_mode);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_tile_scroll_hint", "tile_scroll_hint"), &ItemList::set_tile_scroll_hint);
|
||||
ClassDB::bind_method(D_METHOD("is_scroll_hint_tiled"), &ItemList::is_scroll_hint_tiled);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &ItemList::set_text_overrun_behavior);
|
||||
ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &ItemList::get_text_overrun_behavior);
|
||||
|
||||
@@ -2351,6 +2398,8 @@ void ItemList::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis (6+ Characters),Word Ellipsis (6+ Characters),Ellipsis (Always),Word Ellipsis (Always)"), "set_text_overrun_behavior", "get_text_overrun_behavior");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wraparound_items"), "set_wraparound_items", "has_wraparound_items");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_hint_mode", PROPERTY_HINT_ENUM, "Disabled,Both,Top,Bottom"), "set_scroll_hint_mode", "get_scroll_hint_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tile_scroll_hint"), "set_tile_scroll_hint", "is_scroll_hint_tiled");
|
||||
ADD_ARRAY_COUNT("Items", "item_count", "set_item_count", "get_item_count", "item_");
|
||||
ADD_GROUP("Columns", "");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "max_columns", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), "set_max_columns", "get_max_columns");
|
||||
@@ -2368,6 +2417,11 @@ void ItemList::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(SELECT_MULTI);
|
||||
BIND_ENUM_CONSTANT(SELECT_TOGGLE);
|
||||
|
||||
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_DISABLED);
|
||||
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTH);
|
||||
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_TOP);
|
||||
BIND_ENUM_CONSTANT(SCROLL_HINT_MODE_BOTTOM);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("item_selected", PropertyInfo(Variant::INT, "index")));
|
||||
ADD_SIGNAL(MethodInfo("empty_clicked", PropertyInfo(Variant::VECTOR2, "at_position"), PropertyInfo(Variant::INT, "mouse_button_index")));
|
||||
ADD_SIGNAL(MethodInfo("item_clicked", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::VECTOR2, "at_position"), PropertyInfo(Variant::INT, "mouse_button_index")));
|
||||
@@ -2388,6 +2442,7 @@ void ItemList::_bind_methods() {
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, ItemList, font_selected_color);
|
||||
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_CONSTANT, ItemList, font_outline_size, "outline_size");
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, ItemList, font_outline_color);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_ICON, ItemList, scroll_hint);
|
||||
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ItemList, line_separation);
|
||||
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, ItemList, icon_margin);
|
||||
|
||||
@@ -50,6 +50,13 @@ public:
|
||||
SELECT_TOGGLE,
|
||||
};
|
||||
|
||||
enum ScrollHintMode {
|
||||
SCROLL_HINT_MODE_DISABLED,
|
||||
SCROLL_HINT_MODE_BOTH,
|
||||
SCROLL_HINT_MODE_TOP,
|
||||
SCROLL_HINT_MODE_BOTTOM,
|
||||
};
|
||||
|
||||
private:
|
||||
struct Item {
|
||||
mutable RID accessibility_item_element;
|
||||
@@ -123,6 +130,9 @@ private:
|
||||
HScrollBar *scroll_bar_h = nullptr;
|
||||
TextServer::OverrunBehavior text_overrun_behavior = TextServer::OVERRUN_TRIM_ELLIPSIS;
|
||||
|
||||
ScrollHintMode scroll_hint_mode = SCROLL_HINT_MODE_DISABLED;
|
||||
bool tile_scroll_hint = false;
|
||||
|
||||
uint64_t search_time_msec = 0;
|
||||
String search_string;
|
||||
|
||||
@@ -176,6 +186,8 @@ protected:
|
||||
Ref<StyleBox> cursor_style;
|
||||
Ref<StyleBox> cursor_focus_style;
|
||||
Color guide_color;
|
||||
|
||||
Ref<Texture2D> scroll_hint;
|
||||
} theme_cache;
|
||||
|
||||
void _notification(int p_what);
|
||||
@@ -335,9 +347,16 @@ public:
|
||||
VScrollBar *get_v_scroll_bar() { return scroll_bar_v; }
|
||||
HScrollBar *get_h_scroll_bar() { return scroll_bar_h; }
|
||||
|
||||
void set_scroll_hint_mode(ScrollHintMode p_mode);
|
||||
ScrollHintMode get_scroll_hint_mode() const;
|
||||
|
||||
void set_tile_scroll_hint(bool p_enable);
|
||||
bool is_scroll_hint_tiled();
|
||||
|
||||
ItemList();
|
||||
~ItemList();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(ItemList::SelectMode);
|
||||
VARIANT_ENUM_CAST(ItemList::IconMode);
|
||||
VARIANT_ENUM_CAST(ItemList::ScrollHintMode);
|
||||
|
||||
@@ -43,16 +43,11 @@ Size2 ScrollContainer::get_minimum_size() const {
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);
|
||||
if (!c) {
|
||||
continue;
|
||||
}
|
||||
// Ignore the scroll hints.
|
||||
if (c == h_scroll || c == v_scroll || c == focus_panel) {
|
||||
if (!c || c == h_scroll || c == v_scroll || c == focus_panel || c == scroll_hint_top_left || c == scroll_hint_bottom_right) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Size2 child_min_size = c->get_combined_minimum_size();
|
||||
|
||||
largest_child_min_size = largest_child_min_size.max(child_min_size);
|
||||
}
|
||||
|
||||
|
||||
@@ -4556,6 +4556,7 @@ void Tree::update_scrollbars() {
|
||||
theme_cache.offset.y = v_scroll->get_value();
|
||||
} else {
|
||||
v_scroll->hide();
|
||||
v_scroll->set_value(0);
|
||||
theme_cache.offset.y = 0;
|
||||
}
|
||||
|
||||
@@ -4566,6 +4567,7 @@ void Tree::update_scrollbars() {
|
||||
theme_cache.offset.x = h_scroll->get_value();
|
||||
} else {
|
||||
h_scroll->hide();
|
||||
h_scroll->set_value(0);
|
||||
theme_cache.offset.x = 0;
|
||||
}
|
||||
|
||||
@@ -5131,7 +5133,7 @@ void Tree::_notification(int p_what) {
|
||||
if (scroll_hint_mode != SCROLL_HINT_MODE_DISABLED) {
|
||||
Size2 size = get_size();
|
||||
float v_scroll_value = v_scroll->get_value();
|
||||
bool v_scroll_below_max = v_scroll_value < (get_internal_min_size().height - size.height - 1);
|
||||
bool v_scroll_below_max = v_scroll_value < (get_internal_min_size().height - (content_rect.get_size().height - _get_title_button_height()) - 1);
|
||||
if (v_scroll_value > 1 || v_scroll_below_max) {
|
||||
int hint_height = theme_cache.scroll_hint->get_height();
|
||||
if ((scroll_hint_mode == SCROLL_HINT_MODE_BOTH || scroll_hint_mode == SCROLL_HINT_MODE_TOP) && v_scroll_value > 1) {
|
||||
|
||||
@@ -959,6 +959,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
|
||||
theme->set_stylebox("selected_focus", "ItemList", make_flat_stylebox(style_selected_color));
|
||||
theme->set_stylebox("cursor", "ItemList", focus);
|
||||
theme->set_stylebox("cursor_unfocused", "ItemList", focus);
|
||||
theme->set_icon("scroll_hint", "ItemList", icons["scroll_hint_vertical"]);
|
||||
|
||||
theme->set_constant("outline_size", "ItemList", 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user