feat: updated engine version to 4.4-rc1
This commit is contained in:
parent
ee00efde1f
commit
21ba8e33af
5459 changed files with 1128836 additions and 198305 deletions
|
|
@ -35,14 +35,12 @@
|
|||
#include "scene/theme/theme_db.h"
|
||||
|
||||
Size2 ScrollContainer::get_minimum_size() const {
|
||||
Size2 min_size;
|
||||
|
||||
// Calculated in this function, as it needs to traverse all child controls once to calculate;
|
||||
// and needs to be calculated before being used by update_scrollbars().
|
||||
largest_child_min_size = Size2();
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
|
||||
Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);
|
||||
if (!c) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -55,21 +53,23 @@ Size2 ScrollContainer::get_minimum_size() const {
|
|||
largest_child_min_size = largest_child_min_size.max(child_min_size);
|
||||
}
|
||||
|
||||
Size2 min_size;
|
||||
const Size2 size = get_size();
|
||||
|
||||
if (horizontal_scroll_mode == SCROLL_MODE_DISABLED) {
|
||||
min_size.x = MAX(min_size.x, largest_child_min_size.x);
|
||||
min_size.x = largest_child_min_size.x;
|
||||
bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || vertical_scroll_mode == SCROLL_MODE_RESERVE || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > size.y);
|
||||
if (v_scroll_show && v_scroll->get_parent() == this) {
|
||||
min_size.x += v_scroll->get_minimum_size().x;
|
||||
}
|
||||
}
|
||||
|
||||
if (vertical_scroll_mode == SCROLL_MODE_DISABLED) {
|
||||
min_size.y = MAX(min_size.y, largest_child_min_size.y);
|
||||
}
|
||||
|
||||
bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > min_size.x);
|
||||
bool v_scroll_show = vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.y > min_size.y);
|
||||
|
||||
if (h_scroll_show && h_scroll->get_parent() == this) {
|
||||
min_size.y += h_scroll->get_minimum_size().y;
|
||||
}
|
||||
if (v_scroll_show && v_scroll->get_parent() == this) {
|
||||
min_size.x += v_scroll->get_minimum_size().x;
|
||||
min_size.y = largest_child_min_size.y;
|
||||
bool h_scroll_show = horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || horizontal_scroll_mode == SCROLL_MODE_RESERVE || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.x > size.x);
|
||||
if (h_scroll_show && h_scroll->get_parent() == this) {
|
||||
min_size.y += h_scroll->get_minimum_size().y;
|
||||
}
|
||||
}
|
||||
|
||||
min_size += theme_cache.panel_style->get_minimum_size();
|
||||
|
|
@ -92,6 +92,15 @@ void ScrollContainer::_cancel_drag() {
|
|||
}
|
||||
}
|
||||
|
||||
bool ScrollContainer::_is_h_scroll_visible() const {
|
||||
// Scrolls may have been moved out for reasons.
|
||||
return h_scroll->is_visible() && h_scroll->get_parent() == this;
|
||||
}
|
||||
|
||||
bool ScrollContainer::_is_v_scroll_visible() const {
|
||||
return v_scroll->is_visible() && v_scroll->get_parent() == this;
|
||||
}
|
||||
|
||||
void ScrollContainer::gui_input(const Ref<InputEvent> &p_gui_input) {
|
||||
ERR_FAIL_COND(p_gui_input.is_null());
|
||||
|
||||
|
|
@ -272,21 +281,31 @@ void ScrollContainer::_gui_focus_changed(Control *p_control) {
|
|||
if (follow_focus && is_ancestor_of(p_control)) {
|
||||
ensure_control_visible(p_control);
|
||||
}
|
||||
if (draw_focus_border) {
|
||||
const bool _should_draw_focus_border = has_focus() || child_has_focus();
|
||||
if (focus_border_is_drawn != _should_draw_focus_border) {
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollContainer::ensure_control_visible(Control *p_control) {
|
||||
ERR_FAIL_COND_MSG(!is_ancestor_of(p_control), "Must be an ancestor of the control.");
|
||||
|
||||
Rect2 global_rect = get_global_rect();
|
||||
Rect2 other_rect = p_control->get_global_rect();
|
||||
// Just eliminate the rotation of this ScrollContainer.
|
||||
Transform2D other_in_this = get_global_transform().affine_inverse() * p_control->get_global_transform();
|
||||
|
||||
Size2 size = get_size();
|
||||
Rect2 other_rect = other_in_this.xform(Rect2(Point2(), p_control->get_size()));
|
||||
|
||||
float side_margin = v_scroll->is_visible() ? v_scroll->get_size().x : 0.0f;
|
||||
float bottom_margin = h_scroll->is_visible() ? h_scroll->get_size().y : 0.0f;
|
||||
|
||||
Vector2 diff = Vector2(MAX(MIN(other_rect.position.x - (is_layout_rtl() ? side_margin : 0.0f), global_rect.position.x), other_rect.position.x + other_rect.size.x - global_rect.size.x + (!is_layout_rtl() ? side_margin : 0.0f)),
|
||||
MAX(MIN(other_rect.position.y, global_rect.position.y), other_rect.position.y + other_rect.size.y - global_rect.size.y + bottom_margin));
|
||||
Vector2 diff = Vector2(MAX(MIN(other_rect.position.x - (is_layout_rtl() ? side_margin : 0.0f), 0.0f), other_rect.position.x + other_rect.size.x - size.x + (!is_layout_rtl() ? side_margin : 0.0f)),
|
||||
MAX(MIN(other_rect.position.y, 0.0f), other_rect.position.y + other_rect.size.y - size.y + bottom_margin));
|
||||
|
||||
set_h_scroll(get_h_scroll() + (diff.x - global_rect.position.x));
|
||||
set_v_scroll(get_v_scroll() + (diff.y - global_rect.position.y));
|
||||
set_h_scroll(get_h_scroll() + diff.x);
|
||||
set_v_scroll(get_v_scroll() + diff.y);
|
||||
}
|
||||
|
||||
void ScrollContainer::_reposition_children() {
|
||||
|
|
@ -298,11 +317,11 @@ void ScrollContainer::_reposition_children() {
|
|||
ofs += theme_cache.panel_style->get_offset();
|
||||
bool rtl = is_layout_rtl();
|
||||
|
||||
if (h_scroll->is_visible_in_tree() && h_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
|
||||
if (_is_h_scroll_visible() || horizontal_scroll_mode == SCROLL_MODE_RESERVE) {
|
||||
size.y -= h_scroll->get_minimum_size().y;
|
||||
}
|
||||
|
||||
if (v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) { //scrolls may have been moved out for reasons
|
||||
if (_is_v_scroll_visible() || vertical_scroll_mode == SCROLL_MODE_RESERVE) {
|
||||
size.x -= v_scroll->get_minimum_size().x;
|
||||
}
|
||||
|
||||
|
|
@ -324,7 +343,7 @@ void ScrollContainer::_reposition_children() {
|
|||
r.size.height = MAX(size.height, minsize.height);
|
||||
}
|
||||
r.position += ofs;
|
||||
if (rtl && v_scroll->is_visible_in_tree() && v_scroll->get_parent() == this) {
|
||||
if (rtl && _is_v_scroll_visible()) {
|
||||
r.position.x += v_scroll->get_minimum_size().x;
|
||||
}
|
||||
r.position = r.position.floor();
|
||||
|
|
@ -357,6 +376,15 @@ void ScrollContainer::_notification(int p_what) {
|
|||
|
||||
case NOTIFICATION_DRAW: {
|
||||
draw_style_box(theme_cache.panel_style, Rect2(Vector2(), get_size()));
|
||||
if (draw_focus_border && (has_focus() || child_has_focus())) {
|
||||
RID ci = get_canvas_item();
|
||||
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
|
||||
draw_style_box(theme_cache.focus_style, Rect2(Point2(), get_size()));
|
||||
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
|
||||
focus_border_is_drawn = true;
|
||||
} else {
|
||||
focus_border_is_drawn = false;
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
|
|
@ -436,14 +464,14 @@ void ScrollContainer::update_scrollbars() {
|
|||
Size2 hmin = h_scroll->get_combined_minimum_size();
|
||||
Size2 vmin = v_scroll->get_combined_minimum_size();
|
||||
|
||||
h_scroll->set_visible(horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (horizontal_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.width > size.width));
|
||||
v_scroll->set_visible(vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || (vertical_scroll_mode == SCROLL_MODE_AUTO && largest_child_min_size.height > size.height));
|
||||
h_scroll->set_visible(horizontal_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || ((horizontal_scroll_mode == SCROLL_MODE_AUTO || horizontal_scroll_mode == SCROLL_MODE_RESERVE) && largest_child_min_size.width > size.width));
|
||||
v_scroll->set_visible(vertical_scroll_mode == SCROLL_MODE_SHOW_ALWAYS || ((vertical_scroll_mode == SCROLL_MODE_AUTO || vertical_scroll_mode == SCROLL_MODE_RESERVE) && largest_child_min_size.height > size.height));
|
||||
|
||||
h_scroll->set_max(largest_child_min_size.width);
|
||||
h_scroll->set_page((v_scroll->is_visible() && v_scroll->get_parent() == this) ? size.width - vmin.width : size.width);
|
||||
h_scroll->set_page(_is_v_scroll_visible() ? size.width - vmin.width : size.width);
|
||||
|
||||
v_scroll->set_max(largest_child_min_size.height);
|
||||
v_scroll->set_page((h_scroll->is_visible() && h_scroll->get_parent() == this) ? size.height - hmin.height : size.height);
|
||||
v_scroll->set_page(_is_h_scroll_visible() ? size.height - hmin.height : size.height);
|
||||
|
||||
// Avoid scrollbar overlapping.
|
||||
_updating_scrollbars = true;
|
||||
|
|
@ -452,7 +480,7 @@ void ScrollContainer::update_scrollbars() {
|
|||
|
||||
void ScrollContainer::_scroll_moved(float) {
|
||||
queue_sort();
|
||||
};
|
||||
}
|
||||
|
||||
void ScrollContainer::set_h_scroll(int p_pos) {
|
||||
h_scroll->set_value(p_pos);
|
||||
|
|
@ -538,7 +566,7 @@ PackedStringArray ScrollContainer::get_configuration_warnings() const {
|
|||
int found = 0;
|
||||
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *c = as_sortable_control(get_child(i));
|
||||
Control *c = as_sortable_control(get_child(i), SortableVisibilityMode::VISIBLE);
|
||||
if (!c) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -593,29 +621,52 @@ void ScrollContainer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_v_scroll_bar"), &ScrollContainer::get_v_scroll_bar);
|
||||
ClassDB::bind_method(D_METHOD("ensure_control_visible", "control"), &ScrollContainer::ensure_control_visible);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_draw_focus_border", "draw"), &ScrollContainer::set_draw_focus_border);
|
||||
ClassDB::bind_method(D_METHOD("get_draw_focus_border"), &ScrollContainer::get_draw_focus_border);
|
||||
|
||||
ADD_SIGNAL(MethodInfo("scroll_started"));
|
||||
ADD_SIGNAL(MethodInfo("scroll_ended"));
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "follow_focus"), "set_follow_focus", "is_following_focus");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_focus_border"), "set_draw_focus_border", "get_draw_focus_border");
|
||||
|
||||
ADD_GROUP("Scroll", "scroll_");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal", PROPERTY_HINT_NONE, "suffix:px"), "set_h_scroll", "get_h_scroll");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_vertical", PROPERTY_HINT_NONE, "suffix:px"), "set_v_scroll", "get_v_scroll");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_horizontal_custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_horizontal_custom_step", "get_horizontal_custom_step");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical_custom_step", PROPERTY_HINT_RANGE, "-1,4096,suffix:px"), "set_vertical_custom_step", "get_vertical_custom_step");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show"), "set_horizontal_scroll_mode", "get_horizontal_scroll_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show"), "set_vertical_scroll_mode", "get_vertical_scroll_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_scroll_mode", PROPERTY_HINT_ENUM, "Disabled,Auto,Always Show,Never Show,Reserve"), "set_horizontal_scroll_mode", "get_horizontal_scroll_mode");
|
||||
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");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_deadzone"), "set_deadzone", "get_deadzone");
|
||||
|
||||
BIND_ENUM_CONSTANT(SCROLL_MODE_DISABLED);
|
||||
BIND_ENUM_CONSTANT(SCROLL_MODE_AUTO);
|
||||
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_ALWAYS);
|
||||
BIND_ENUM_CONSTANT(SCROLL_MODE_SHOW_NEVER);
|
||||
BIND_ENUM_CONSTANT(SCROLL_MODE_RESERVE);
|
||||
|
||||
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, panel_style, "panel");
|
||||
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, ScrollContainer, focus_style, "focus");
|
||||
|
||||
GLOBAL_DEF("gui/common/default_scroll_deadzone", 0);
|
||||
};
|
||||
}
|
||||
|
||||
void ScrollContainer::set_draw_focus_border(bool p_draw) {
|
||||
if (draw_focus_border == p_draw) {
|
||||
return;
|
||||
}
|
||||
draw_focus_border = p_draw;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
bool ScrollContainer::get_draw_focus_border() {
|
||||
return draw_focus_border;
|
||||
}
|
||||
|
||||
bool ScrollContainer::child_has_focus() {
|
||||
const Control *focus_owner = get_viewport() ? get_viewport()->gui_get_focus_owner() : nullptr;
|
||||
return focus_owner && is_ancestor_of(focus_owner);
|
||||
}
|
||||
|
||||
ScrollContainer::ScrollContainer() {
|
||||
h_scroll = memnew(HScrollBar);
|
||||
|
|
@ -631,4 +682,4 @@ ScrollContainer::ScrollContainer() {
|
|||
deadzone = GLOBAL_GET("gui/common/default_scroll_deadzone");
|
||||
|
||||
set_clip_contents(true);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue