feat: updated engine
This commit is contained in:
parent
cbe99774ff
commit
f4cf6b3999
6607 changed files with 910135 additions and 430025 deletions
|
|
@ -30,17 +30,13 @@
|
|||
|
||||
#include "tab_container.h"
|
||||
|
||||
#include "core/object/callable_mp.h"
|
||||
#include "core/object/class_db.h"
|
||||
#include "scene/gui/box_container.h"
|
||||
#include "scene/gui/button.h"
|
||||
#include "scene/gui/popup.h"
|
||||
#include "scene/theme/theme_db.h"
|
||||
|
||||
Rect2 TabContainer::_get_tab_rect() const {
|
||||
Rect2 rect;
|
||||
if (tabs_visible && get_tab_count() > 0) {
|
||||
rect = Rect2(theme_cache.tabbar_style->get_offset(), tab_bar->get_size());
|
||||
rect.position.x += is_layout_rtl() ? theme_cache.menu_icon->get_width() : theme_cache.side_margin;
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
#include "servers/display/accessibility_server.h"
|
||||
|
||||
TabContainer::CachedTab &TabContainer::get_pending_tab(int p_idx) const {
|
||||
if (p_idx >= pending_tabs.size()) {
|
||||
|
|
@ -58,86 +54,12 @@ int TabContainer::_get_tab_height() const {
|
|||
return height;
|
||||
}
|
||||
|
||||
void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
|
||||
ERR_FAIL_COND(p_event.is_null());
|
||||
|
||||
Ref<InputEventMouseButton> mb = p_event;
|
||||
|
||||
Popup *popup = get_popup();
|
||||
|
||||
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
||||
Point2 pos = mb->get_position();
|
||||
real_t content_height = get_size().height - _get_tab_height();
|
||||
|
||||
Rect2 popup_rect = _get_tab_rect();
|
||||
popup_rect.position.x += is_layout_rtl() ? -theme_cache.menu_icon->get_width() : popup_rect.size.x;
|
||||
popup_rect.position.y += tabs_position == POSITION_BOTTOM ? content_height : 0;
|
||||
popup_rect.size.x = theme_cache.menu_icon->get_width();
|
||||
|
||||
// Click must be on tabs in the tab header area.
|
||||
if (!tabs_visible || pos.y < popup_rect.position.y || pos.y >= popup_rect.position.y + popup_rect.size.y) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle menu button.
|
||||
if (popup) {
|
||||
if (popup_rect.has_point(pos)) {
|
||||
emit_signal(SNAME("pre_popup_pressed"));
|
||||
|
||||
Vector2 popup_pos = get_screen_position();
|
||||
popup_pos.x += popup_rect.position.x + (is_layout_rtl() ? 0 : popup_rect.size.x - popup->get_size().width);
|
||||
popup_pos.y += popup_rect.position.y + popup_rect.size.y / 2.0;
|
||||
if (tabs_position == POSITION_BOTTOM) {
|
||||
popup_pos.y -= popup->get_size().height;
|
||||
popup_pos.y -= theme_cache.menu_icon->get_height() / 2.0;
|
||||
} else {
|
||||
popup_pos.y += theme_cache.menu_icon->get_height() / 2.0;
|
||||
}
|
||||
|
||||
popup->set_position(popup_pos);
|
||||
popup->popup();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
|
||||
if (mm.is_valid()) {
|
||||
Point2 pos = mm->get_position();
|
||||
real_t content_height = get_size().height - _get_tab_height();
|
||||
|
||||
Rect2 popup_rect = _get_tab_rect();
|
||||
popup_rect.position.x += is_layout_rtl() ? -theme_cache.menu_icon->get_width() : popup_rect.size.x;
|
||||
popup_rect.position.y += tabs_position == POSITION_BOTTOM ? content_height : 0;
|
||||
popup_rect.size.x = theme_cache.menu_icon->get_width();
|
||||
|
||||
// Mouse must be on tabs in the tab header area.
|
||||
if (!tabs_visible || pos.y < popup_rect.position.y || pos.y >= popup_rect.position.y + popup_rect.size.y) {
|
||||
if (menu_hovered) {
|
||||
menu_hovered = false;
|
||||
queue_redraw();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (popup) {
|
||||
if (popup_rect.has_point(pos)) {
|
||||
if (!menu_hovered) {
|
||||
menu_hovered = true;
|
||||
queue_redraw();
|
||||
return;
|
||||
}
|
||||
} else if (menu_hovered) {
|
||||
menu_hovered = false;
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
if (menu_hovered) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Control *TabContainer::_as_tab_control(Node *p_child) const {
|
||||
Control *control = as_sortable_control(p_child, SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == internal_container || children_removing.has(control)) {
|
||||
return nullptr;
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
void TabContainer::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
|
@ -193,20 +115,20 @@ void TabContainer::_notification(int p_what) {
|
|||
if (child_node->is_part_of_edited_scene()) {
|
||||
continue;
|
||||
}
|
||||
Control *control = as_sortable_control(child_node, SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == tab_bar || children_removing.has(control)) {
|
||||
DisplayServer::get_singleton()->accessibility_update_add_child(ae, child_node->get_accessibility_element());
|
||||
Control *control = _as_tab_control(child_node);
|
||||
if (!control) {
|
||||
AccessibilityServer::get_singleton()->update_add_child(ae, child_node->get_accessibility_element());
|
||||
} else {
|
||||
if (!tab_panels.has(child_node)) {
|
||||
tab_panels[child_node] = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TAB_PANEL);
|
||||
tab_panels[child_node] = AccessibilityServer::get_singleton()->create_sub_element(ae, AccessibilityServerEnums::AccessibilityRole::ROLE_TAB_PANEL);
|
||||
}
|
||||
RID panel = tab_panels[child_node];
|
||||
RID tab = tab_bar->get_tab_accessibility_element(tab_index);
|
||||
|
||||
DisplayServer::get_singleton()->accessibility_update_add_related_controls(tab, panel);
|
||||
DisplayServer::get_singleton()->accessibility_update_add_related_labeled_by(panel, tab);
|
||||
DisplayServer::get_singleton()->accessibility_update_set_flag(panel, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, tab_index != tab_cur);
|
||||
DisplayServer::get_singleton()->accessibility_update_add_child(panel, child_node->get_accessibility_element());
|
||||
AccessibilityServer::get_singleton()->update_add_related_controls(tab, panel);
|
||||
AccessibilityServer::get_singleton()->update_add_related_labeled_by(panel, tab);
|
||||
AccessibilityServer::get_singleton()->update_set_flag(panel, AccessibilityServerEnums::AccessibilityFlags::FLAG_HIDDEN, tab_index != tab_cur);
|
||||
AccessibilityServer::get_singleton()->update_add_child(panel, child_node->get_accessibility_element());
|
||||
|
||||
tab_index++;
|
||||
}
|
||||
|
|
@ -225,21 +147,7 @@ void TabContainer::_notification(int p_what) {
|
|||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_READY: {
|
||||
for (int i = 0; i < pending_tabs.size(); i++) {
|
||||
const CachedTab &tab = pending_tabs[i];
|
||||
if (tab.has_title) {
|
||||
set_tab_title(i, tab.title);
|
||||
}
|
||||
set_tab_icon(i, tab.icon);
|
||||
set_tab_disabled(i, tab.disabled);
|
||||
set_tab_hidden(i, tab.hidden);
|
||||
}
|
||||
pending_tabs.clear();
|
||||
|
||||
[[fallthrough]];
|
||||
}
|
||||
|
||||
case NOTIFICATION_READY:
|
||||
case NOTIFICATION_RESIZED: {
|
||||
_update_margins();
|
||||
} break;
|
||||
|
|
@ -247,14 +155,12 @@ void TabContainer::_notification(int p_what) {
|
|||
case NOTIFICATION_DRAW: {
|
||||
RID canvas = get_canvas_item();
|
||||
Size2 size = get_size();
|
||||
Rect2 tabbar_rect = _get_tab_rect();
|
||||
|
||||
// Draw only the tab area if the header is hidden.
|
||||
if (!tabs_visible) {
|
||||
theme_cache.panel_style->draw(canvas, Rect2(0, 0, size.width, size.height));
|
||||
return;
|
||||
}
|
||||
|
||||
int header_height = _get_tab_height();
|
||||
int header_voffset = int(tabs_position == POSITION_BOTTOM) * (size.height - header_height);
|
||||
|
||||
|
|
@ -262,18 +168,6 @@ void TabContainer::_notification(int p_what) {
|
|||
theme_cache.tabbar_style->draw(canvas, Rect2(0, header_voffset, size.width, header_height));
|
||||
// Draw the background for the tab's content.
|
||||
theme_cache.panel_style->draw(canvas, Rect2(0, int(tabs_position == POSITION_TOP) * header_height, size.width, size.height - header_height));
|
||||
|
||||
// Draw the popup menu.
|
||||
if (get_popup()) {
|
||||
int x = is_layout_rtl() ? tabbar_rect.position.x - theme_cache.menu_icon->get_width() : tabbar_rect.position.x + tabbar_rect.size.x;
|
||||
header_voffset += tabbar_rect.position.y;
|
||||
|
||||
if (menu_hovered) {
|
||||
theme_cache.menu_hl_icon->draw(get_canvas_item(), Point2(x, header_voffset + (tabbar_rect.size.y - theme_cache.menu_hl_icon->get_height()) / 2));
|
||||
} else {
|
||||
theme_cache.menu_icon->draw(get_canvas_item(), Point2(x, header_voffset + (tabbar_rect.size.y - theme_cache.menu_icon->get_height()) / 2));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_VISIBILITY_CHANGED: {
|
||||
|
|
@ -293,10 +187,18 @@ void TabContainer::_notification(int p_what) {
|
|||
}
|
||||
|
||||
updating_visibility = false;
|
||||
_maximum_size_changed();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_TRANSLATION_CHANGED:
|
||||
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
|
||||
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
|
||||
if (popup_button) {
|
||||
popup_button->set_button_icon(theme_cache.menu_icon);
|
||||
internal_container->move_child(popup_button, is_layout_rtl() ? 0 : 1);
|
||||
}
|
||||
_update_margins();
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
theme_changing = true;
|
||||
callable_mp(this, &TabContainer::_on_theme_changed).call_deferred(); // Wait until all changed theme.
|
||||
|
|
@ -350,13 +252,24 @@ void TabContainer::_on_theme_changed() {
|
|||
_repaint();
|
||||
} else {
|
||||
update_minimum_size();
|
||||
update_desired_size();
|
||||
}
|
||||
queue_redraw();
|
||||
|
||||
theme_changing = false;
|
||||
}
|
||||
|
||||
void TabContainer::_repaint_call_deferred() {
|
||||
layout_pending_start();
|
||||
callable_mp(this, &TabContainer::_repaint_internal).call_deferred();
|
||||
}
|
||||
|
||||
void TabContainer::_repaint() {
|
||||
layout_pending_start();
|
||||
_repaint_internal();
|
||||
}
|
||||
|
||||
void TabContainer::_repaint_internal() {
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
int current = get_current_tab();
|
||||
|
||||
|
|
@ -366,11 +279,11 @@ void TabContainer::_repaint() {
|
|||
// Move the TabBar to the top or bottom.
|
||||
// Don't change the left and right offsets since the TabBar will resize and may change tab offset.
|
||||
if (tabs_position == POSITION_BOTTOM) {
|
||||
tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 1.0, -bottom_margin);
|
||||
tab_bar->set_anchor_and_offset(SIDE_TOP, 1.0, top_margin - _get_tab_height());
|
||||
internal_container->set_anchor_and_offset(SIDE_BOTTOM, 1.0, -bottom_margin);
|
||||
internal_container->set_anchor_and_offset(SIDE_TOP, 1.0, top_margin - _get_tab_height());
|
||||
} else {
|
||||
tab_bar->set_anchor_and_offset(SIDE_TOP, 0.0, top_margin);
|
||||
tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height() - bottom_margin);
|
||||
internal_container->set_anchor_and_offset(SIDE_TOP, 0.0, top_margin);
|
||||
internal_container->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height() - bottom_margin);
|
||||
}
|
||||
|
||||
updating_visibility = true;
|
||||
|
|
@ -400,6 +313,7 @@ void TabContainer::_repaint() {
|
|||
updating_visibility = false;
|
||||
|
||||
update_minimum_size();
|
||||
layout_pending_finish();
|
||||
}
|
||||
|
||||
void TabContainer::_update_margins() {
|
||||
|
|
@ -413,32 +327,30 @@ void TabContainer::_update_margins() {
|
|||
SWAP(left_margin, right_margin);
|
||||
}
|
||||
|
||||
if (has_popup) {
|
||||
right_margin += theme_cache.menu_icon->get_width();
|
||||
}
|
||||
|
||||
if (get_tab_count() == 0) {
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
_maximum_size_changed();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (get_tab_alignment()) {
|
||||
case TabBar::ALIGNMENT_LEFT: {
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin + theme_cache.side_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin + theme_cache.side_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} break;
|
||||
|
||||
case TabBar::ALIGNMENT_CENTER: {
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} break;
|
||||
|
||||
case TabBar::ALIGNMENT_RIGHT: {
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
|
||||
if (has_popup) {
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
_maximum_size_changed();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -448,35 +360,29 @@ void TabContainer::_update_margins() {
|
|||
|
||||
// Calculate if all the tabs would still fit if the margin was present.
|
||||
if (get_clip_tabs() && (tab_bar->get_offset_buttons_visible() || (get_tab_count() > 1 && (total_tabs_width + theme_cache.side_margin) > get_size().width))) {
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} else {
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin - theme_cache.side_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin - theme_cache.side_margin);
|
||||
}
|
||||
} break;
|
||||
|
||||
case TabBar::ALIGNMENT_MAX:
|
||||
break; // Can't happen, but silences warning.
|
||||
}
|
||||
}
|
||||
|
||||
void TabContainer::_on_mouse_exited() {
|
||||
if (menu_hovered) {
|
||||
menu_hovered = false;
|
||||
queue_redraw();
|
||||
}
|
||||
_maximum_size_changed();
|
||||
}
|
||||
|
||||
Vector<Control *> TabContainer::_get_tab_controls() const {
|
||||
Vector<Control *> controls;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *control = as_sortable_control(get_child(i), SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == tab_bar || children_removing.has(control)) {
|
||||
continue;
|
||||
ERR_THREAD_GUARD_V(controls);
|
||||
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (control) {
|
||||
controls.push_back(control);
|
||||
}
|
||||
|
||||
controls.push_back(control);
|
||||
}
|
||||
|
||||
return controls;
|
||||
}
|
||||
|
||||
|
|
@ -506,17 +412,44 @@ void TabContainer::_drag_move_tab(int p_from_index, int p_to_index) {
|
|||
}
|
||||
|
||||
void TabContainer::_drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index) {
|
||||
Node *parent = p_from_tabbar->get_parent();
|
||||
HBoxContainer *parent = Object::cast_to<HBoxContainer>(p_from_tabbar->get_parent()); // The internal container.
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent);
|
||||
TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent->get_parent());
|
||||
if (!from_tab_container) {
|
||||
return;
|
||||
}
|
||||
move_tab_from_tab_container(from_tab_container, p_from_index, p_to_index);
|
||||
}
|
||||
|
||||
void TabContainer::_popup_button_hovered(bool p_hover) {
|
||||
if (p_hover) {
|
||||
popup_button->set_button_icon(theme_cache.menu_hl_icon);
|
||||
} else {
|
||||
popup_button->set_button_icon(theme_cache.menu_icon);
|
||||
}
|
||||
}
|
||||
|
||||
void TabContainer::_popup_button_pressed() {
|
||||
Popup *popup = get_popup();
|
||||
ERR_FAIL_NULL(popup);
|
||||
|
||||
emit_signal(SNAME("pre_popup_pressed"));
|
||||
|
||||
Vector2 popup_pos = popup_button->get_screen_position();
|
||||
popup_pos.x += (is_layout_rtl() ? 0 : popup_button->get_size().x - popup->get_size().width);
|
||||
if (tabs_position == POSITION_BOTTOM) {
|
||||
popup_pos.y -= popup->get_size().height;
|
||||
} else {
|
||||
popup_pos.y += popup_button->get_size().y;
|
||||
}
|
||||
|
||||
popup->set_position(popup_pos);
|
||||
popup->popup();
|
||||
return;
|
||||
}
|
||||
|
||||
void TabContainer::move_tab_from_tab_container(TabContainer *p_from, int p_from_index, int p_to_index) {
|
||||
ERR_FAIL_NULL(p_from);
|
||||
ERR_FAIL_INDEX(p_from_index, p_from->get_tab_count());
|
||||
|
|
@ -564,15 +497,16 @@ void TabContainer::_on_tab_hovered(int p_tab) {
|
|||
}
|
||||
|
||||
void TabContainer::_on_tab_changed(int p_tab) {
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint();
|
||||
queue_redraw();
|
||||
queue_accessibility_update();
|
||||
|
||||
emit_signal(SNAME("tab_changed"), p_tab);
|
||||
}
|
||||
|
||||
void TabContainer::_on_tab_selected(int p_tab) {
|
||||
if (p_tab != get_previous_tab()) {
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
}
|
||||
|
||||
emit_signal(SNAME("tab_selected"), p_tab);
|
||||
|
|
@ -640,7 +574,7 @@ void TabContainer::_refresh_tab_names() {
|
|||
void TabContainer::add_child_notify(Node *p_child) {
|
||||
Container::add_child_notify(p_child);
|
||||
|
||||
if (p_child == tab_bar) {
|
||||
if (p_child == internal_container) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -651,7 +585,23 @@ void TabContainer::add_child_notify(Node *p_child) {
|
|||
c->hide();
|
||||
|
||||
tab_bar->add_tab(p_child->get_meta("_tab_name", p_child->get_name()));
|
||||
c->set_meta("_tab_index", tab_bar->get_tab_count() - 1);
|
||||
int idx = tab_bar->get_tab_count() - 1;
|
||||
c->set_meta("_tab_index", idx);
|
||||
|
||||
if (idx < pending_tabs.size()) {
|
||||
const CachedTab &tab = pending_tabs[idx];
|
||||
if (tab.has_title) {
|
||||
set_tab_title(idx, tab.title);
|
||||
}
|
||||
set_tab_icon(idx, tab.icon);
|
||||
set_tab_disabled(idx, tab.disabled);
|
||||
set_tab_hidden(idx, tab.hidden);
|
||||
|
||||
if (idx == pending_tabs.size() - 1) {
|
||||
// Last tab was assigned.
|
||||
pending_tabs.clear();
|
||||
}
|
||||
}
|
||||
|
||||
_update_margins();
|
||||
if (get_tab_count() == 1) {
|
||||
|
|
@ -664,7 +614,7 @@ void TabContainer::add_child_notify(Node *p_child) {
|
|||
|
||||
// TabBar won't emit the "tab_changed" signal when not inside the tree.
|
||||
if (!is_inside_tree()) {
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
}
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -672,7 +622,7 @@ void TabContainer::add_child_notify(Node *p_child) {
|
|||
void TabContainer::move_child_notify(Node *p_child) {
|
||||
Container::move_child_notify(p_child);
|
||||
|
||||
if (p_child == tab_bar) {
|
||||
if (p_child == internal_container) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -690,11 +640,11 @@ void TabContainer::remove_child_notify(Node *p_child) {
|
|||
Container::remove_child_notify(p_child);
|
||||
|
||||
if (tab_panels.has(p_child)) {
|
||||
DisplayServer::get_singleton()->accessibility_free_element(tab_panels[p_child]);
|
||||
AccessibilityServer::get_singleton()->free_element(tab_panels[p_child]);
|
||||
tab_panels.erase(p_child);
|
||||
}
|
||||
|
||||
if (p_child == tab_bar) {
|
||||
if (p_child == internal_container) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -726,7 +676,7 @@ void TabContainer::remove_child_notify(Node *p_child) {
|
|||
|
||||
// TabBar won't emit the "tab_changed" signal when not inside the tree.
|
||||
if (!is_inside_tree()) {
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
}
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -773,12 +723,24 @@ bool TabContainer::get_deselect_enabled() const {
|
|||
}
|
||||
|
||||
Control *TabContainer::get_tab_control(int p_idx) const {
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
if (p_idx >= 0 && p_idx < controls.size()) {
|
||||
return controls[p_idx];
|
||||
} else {
|
||||
if (p_idx < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
ERR_THREAD_GUARD_V(nullptr);
|
||||
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (!control) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p_idx > 0) {
|
||||
p_idx--;
|
||||
} else {
|
||||
return control;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Control *TabContainer::get_current_tab_control() const {
|
||||
|
|
@ -792,14 +754,20 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
|
|||
int TabContainer::get_tab_idx_from_control(Control *p_child) const {
|
||||
ERR_FAIL_NULL_V(p_child, -1);
|
||||
ERR_FAIL_COND_V(p_child->get_parent() != this, -1);
|
||||
ERR_THREAD_GUARD_V(-1);
|
||||
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
for (int i = 0; i < controls.size(); i++) {
|
||||
if (controls[i] == p_child) {
|
||||
return i;
|
||||
int idx = 0;
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (!control) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (control == p_child) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -825,7 +793,7 @@ void TabContainer::set_tabs_position(TabPosition p_tabs_position) {
|
|||
|
||||
tab_bar->set_tab_style_v_flip(tabs_position == POSITION_BOTTOM);
|
||||
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
|
@ -857,7 +825,7 @@ void TabContainer::set_tabs_visible(bool p_visible) {
|
|||
tabs_visible = p_visible;
|
||||
tab_bar->set_visible(tabs_visible);
|
||||
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
|
@ -865,20 +833,17 @@ bool TabContainer::are_tabs_visible() const {
|
|||
return tabs_visible;
|
||||
}
|
||||
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
void TabContainer::set_all_tabs_in_front(bool p_in_front) {
|
||||
if (p_in_front == all_tabs_in_front) {
|
||||
return;
|
||||
if (p_in_front) {
|
||||
WARN_PRINT_ONCE("Due to internal changes, `all_tabs_in_front` doesn't do anything anymore, as they're always in front.");
|
||||
}
|
||||
|
||||
all_tabs_in_front = p_in_front;
|
||||
|
||||
remove_child(tab_bar);
|
||||
add_child(tab_bar, false, all_tabs_in_front ? INTERNAL_MODE_FRONT : INTERNAL_MODE_BACK);
|
||||
}
|
||||
|
||||
bool TabContainer::is_all_tabs_in_front() const {
|
||||
return all_tabs_in_front;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void TabContainer::set_tab_title(int p_tab, const String &p_title) {
|
||||
Control *child = get_tab_control(p_tab);
|
||||
|
|
@ -970,6 +935,7 @@ void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
|
|||
tab_bar->set_tab_disabled(p_tab, p_disabled);
|
||||
|
||||
_update_margins();
|
||||
update_desired_size();
|
||||
if (!get_clip_tabs()) {
|
||||
update_minimum_size();
|
||||
}
|
||||
|
|
@ -995,10 +961,11 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
|
|||
child->hide();
|
||||
|
||||
_update_margins();
|
||||
update_desired_size();
|
||||
if (!get_clip_tabs()) {
|
||||
update_minimum_size();
|
||||
}
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
_repaint_call_deferred();
|
||||
}
|
||||
|
||||
bool TabContainer::is_tab_hidden(int p_tab) const {
|
||||
|
|
@ -1024,16 +991,16 @@ Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const {
|
|||
return tab_bar->get_tab_button_icon(p_tab);
|
||||
}
|
||||
|
||||
Size2 TabContainer::get_minimum_size() const {
|
||||
Size2 TabContainer::_get_minimum_size(bool p_use_desired_sizes) const {
|
||||
Size2 ms;
|
||||
|
||||
if (tabs_visible) {
|
||||
ms = tab_bar->get_minimum_size();
|
||||
ms = p_use_desired_sizes ? tab_bar->get_bound_desired_size() : tab_bar->get_minimum_size();
|
||||
ms.width += theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT);
|
||||
ms.height += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
|
||||
|
||||
if (get_popup()) {
|
||||
ms.width += theme_cache.menu_icon->get_width();
|
||||
ms.width += p_use_desired_sizes ? popup_button->get_bound_desired_size().x : popup_button->get_minimum_size().x;
|
||||
}
|
||||
|
||||
if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
|
||||
|
|
@ -1051,7 +1018,7 @@ Size2 TabContainer::get_minimum_size() const {
|
|||
continue;
|
||||
}
|
||||
|
||||
Size2 cms = c->get_combined_minimum_size();
|
||||
Size2 cms = p_use_desired_sizes ? c->get_bound_desired_size() : c->get_bound_minimum_size();
|
||||
largest_child_min_size = largest_child_min_size.max(cms);
|
||||
}
|
||||
ms.height += largest_child_min_size.height;
|
||||
|
|
@ -1064,6 +1031,60 @@ Size2 TabContainer::get_minimum_size() const {
|
|||
return ms;
|
||||
}
|
||||
|
||||
Size2 TabContainer::get_minimum_size() const {
|
||||
return _get_minimum_size(false);
|
||||
}
|
||||
|
||||
Size2 TabContainer::get_desired_size() const {
|
||||
return _get_minimum_size(true);
|
||||
}
|
||||
|
||||
Size2 TabContainer::get_inner_combined_maximum_size() const {
|
||||
Size2 ms = Container::get_inner_combined_maximum_size();
|
||||
|
||||
if (tabs_visible && tab_bar) {
|
||||
Size2 tab_bar_ms = tab_bar->get_minimum_size();
|
||||
ms.height -= tab_bar_ms.height;
|
||||
|
||||
if (theme_cache.tabbar_style.is_valid()) {
|
||||
ms.height -= theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
|
||||
}
|
||||
}
|
||||
|
||||
if (theme_cache.panel_style.is_valid()) {
|
||||
ms -= theme_cache.panel_style->get_minimum_size();
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
void TabContainer::_maximum_size_changed() {
|
||||
if (!tab_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
Size2 ms = get_combined_maximum_size();
|
||||
if (theme_cache.tabbar_style.is_valid()) {
|
||||
if (ms.width >= 0) {
|
||||
ms.width -= theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT);
|
||||
if (get_popup() && popup_button) {
|
||||
ms.width -= popup_button->get_minimum_size().x;
|
||||
}
|
||||
if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
|
||||
(get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) {
|
||||
ms.width -= theme_cache.side_margin;
|
||||
}
|
||||
ms.width = MAX(ms.width, 0);
|
||||
}
|
||||
if (ms.height >= 0) {
|
||||
ms.height -= theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
|
||||
ms.height = MAX(ms.height, 0);
|
||||
}
|
||||
}
|
||||
internal_container->set_parent_maximum_size_cache(Size2(-1, -1));
|
||||
tab_bar->set_custom_maximum_size(ms);
|
||||
}
|
||||
|
||||
void TabContainer::set_popup(Node *p_popup) {
|
||||
bool had_popup = get_popup();
|
||||
|
||||
|
|
@ -1074,10 +1095,29 @@ void TabContainer::set_popup(Node *p_popup) {
|
|||
}
|
||||
popup_obj_id = popup_id;
|
||||
|
||||
if (!popup_button) {
|
||||
popup_button = memnew(Button);
|
||||
popup_button->set_action_mode(BaseButton::ACTION_MODE_BUTTON_PRESS);
|
||||
popup_button->set_flat(true);
|
||||
if (is_inside_tree()) {
|
||||
popup_button->set_button_icon(theme_cache.menu_icon);
|
||||
}
|
||||
popup_button->add_theme_color_override("icon_pressed_color", Color(1, 1, 1));
|
||||
popup_button->add_theme_color_override("icon_hover_pressed_color", Color(1, 1, 1));
|
||||
|
||||
internal_container->add_child(popup_button);
|
||||
internal_container->move_child(popup_button, is_layout_rtl() ? 0 : 1);
|
||||
|
||||
popup_button->connect(SceneStringName(mouse_entered), callable_mp(this, &TabContainer::_popup_button_hovered).bind(true));
|
||||
popup_button->connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_popup_button_hovered).bind(false));
|
||||
popup_button->connect(SceneStringName(pressed), callable_mp(this, &TabContainer::_popup_button_pressed));
|
||||
}
|
||||
|
||||
if (had_popup != bool(popup)) {
|
||||
queue_redraw();
|
||||
popup_button->set_visible(popup != nullptr);
|
||||
_update_margins();
|
||||
update_minimum_size();
|
||||
update_desired_size();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1128,6 +1168,7 @@ void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) {
|
|||
|
||||
use_hidden_tabs_for_min_size = p_use_hidden_tabs;
|
||||
update_minimum_size();
|
||||
update_desired_size();
|
||||
}
|
||||
|
||||
bool TabContainer::get_use_hidden_tabs_for_min_size() const {
|
||||
|
|
@ -1160,8 +1201,10 @@ void TabContainer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("get_clip_tabs"), &TabContainer::get_clip_tabs);
|
||||
ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
|
||||
ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible);
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
ClassDB::bind_method(D_METHOD("set_all_tabs_in_front", "is_front"), &TabContainer::set_all_tabs_in_front);
|
||||
ClassDB::bind_method(D_METHOD("is_all_tabs_in_front"), &TabContainer::is_all_tabs_in_front);
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
|
||||
ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
|
||||
|
|
@ -1210,7 +1253,9 @@ void TabContainer::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_position", PROPERTY_HINT_ENUM, "Top,Bottom"), "set_tabs_position", "get_tabs_position");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
|
||||
#ifndef DISABLE_DEPRECATED
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_all_tabs_in_front", "is_all_tabs_in_front");
|
||||
#endif
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "switch_on_drag_hover"), "set_switch_on_drag_hover", "get_switch_on_drag_hover");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_rearrange_group"), "set_tabs_rearrange_group", "get_tabs_rearrange_group");
|
||||
|
|
@ -1219,6 +1264,7 @@ void TabContainer::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled");
|
||||
|
||||
ADD_CLASS_DEPENDENCY("TabBar");
|
||||
ADD_CLASS_DEPENDENCY("Button");
|
||||
|
||||
BIND_ENUM_CONSTANT(POSITION_TOP);
|
||||
BIND_ENUM_CONSTANT(POSITION_BOTTOM);
|
||||
|
|
@ -1270,25 +1316,33 @@ void TabContainer::_bind_methods() {
|
|||
base_property_helper.set_prefix("tab_");
|
||||
base_property_helper.set_array_length_getter(&TabContainer::get_tab_count);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::STRING, "title"), defaults.title, &TabContainer::set_tab_title, &TabContainer::get_tab_title);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &TabContainer::set_tab_icon, &TabContainer::get_tab_icon);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, Texture2D::get_class_static()), defaults.icon, &TabContainer::set_tab_icon, &TabContainer::get_tab_icon);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "disabled"), defaults.disabled, &TabContainer::set_tab_disabled, &TabContainer::is_tab_disabled);
|
||||
base_property_helper.register_property(PropertyInfo(Variant::BOOL, "hidden"), defaults.hidden, &TabContainer::set_tab_hidden, &TabContainer::is_tab_hidden);
|
||||
PropertyListHelper::register_base_helper(&base_property_helper);
|
||||
PropertyListHelper::register_base_helper(get_class_static(), &base_property_helper);
|
||||
}
|
||||
|
||||
TabContainer::TabContainer() {
|
||||
connect(SceneStringName(maximum_size_changed), callable_mp(this, &TabContainer::_maximum_size_changed));
|
||||
|
||||
internal_container = memnew(HBoxContainer);
|
||||
internal_container->add_theme_constant_override(SNAME("separation"), 0);
|
||||
internal_container->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
|
||||
internal_container->set_use_parent_material(true);
|
||||
add_child(internal_container, false, INTERNAL_MODE_FRONT);
|
||||
|
||||
tab_bar = memnew(TabBar);
|
||||
SET_DRAG_FORWARDING_GCDU(tab_bar, TabContainer);
|
||||
add_child(tab_bar, false, INTERNAL_MODE_FRONT);
|
||||
tab_bar->set_use_parent_material(true);
|
||||
tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
|
||||
|
||||
tab_bar->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||
internal_container->add_child(tab_bar);
|
||||
tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed));
|
||||
tab_bar->connect("tab_clicked", callable_mp(this, &TabContainer::_on_tab_clicked));
|
||||
tab_bar->connect("tab_hovered", callable_mp(this, &TabContainer::_on_tab_hovered));
|
||||
tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected));
|
||||
tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed));
|
||||
tab_bar->connect("active_tab_rearranged", callable_mp(this, &TabContainer::_on_active_tab_rearranged));
|
||||
connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_on_mouse_exited));
|
||||
|
||||
property_helper.setup_for_instance(base_property_helper, this);
|
||||
property_helper.enable_out_of_bounds_assign();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue