feat: updated godot version
This commit is contained in:
parent
0c508b0831
commit
42b028dbb5
4694 changed files with 236470 additions and 401376 deletions
|
|
@ -30,13 +30,17 @@
|
|||
|
||||
#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"
|
||||
#include "servers/display/accessibility_server.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;
|
||||
}
|
||||
|
||||
TabContainer::CachedTab &TabContainer::get_pending_tab(int p_idx) const {
|
||||
if (p_idx >= pending_tabs.size()) {
|
||||
|
|
@ -54,12 +58,86 @@ int TabContainer::_get_tab_height() const {
|
|||
return height;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
void TabContainer::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
|
|
@ -115,20 +193,20 @@ void TabContainer::_notification(int p_what) {
|
|||
if (child_node->is_part_of_edited_scene()) {
|
||||
continue;
|
||||
}
|
||||
Control *control = _as_tab_control(child_node);
|
||||
if (!control) {
|
||||
AccessibilityServer::get_singleton()->update_add_child(ae, child_node->get_accessibility_element());
|
||||
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());
|
||||
} else {
|
||||
if (!tab_panels.has(child_node)) {
|
||||
tab_panels[child_node] = AccessibilityServer::get_singleton()->create_sub_element(ae, AccessibilityServerEnums::AccessibilityRole::ROLE_TAB_PANEL);
|
||||
tab_panels[child_node] = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TAB_PANEL);
|
||||
}
|
||||
RID panel = tab_panels[child_node];
|
||||
RID tab = tab_bar->get_tab_accessibility_element(tab_index);
|
||||
|
||||
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());
|
||||
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());
|
||||
|
||||
tab_index++;
|
||||
}
|
||||
|
|
@ -169,12 +247,14 @@ 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);
|
||||
|
||||
|
|
@ -182,6 +262,18 @@ 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: {
|
||||
|
|
@ -204,14 +296,7 @@ void TabContainer::_notification(int p_what) {
|
|||
} break;
|
||||
|
||||
case NOTIFICATION_TRANSLATION_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_LAYOUT_DIRECTION_CHANGED:
|
||||
case NOTIFICATION_THEME_CHANGED: {
|
||||
theme_changing = true;
|
||||
callable_mp(this, &TabContainer::_on_theme_changed).call_deferred(); // Wait until all changed theme.
|
||||
|
|
@ -271,17 +356,7 @@ void TabContainer::_on_theme_changed() {
|
|||
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();
|
||||
|
||||
|
|
@ -291,11 +366,11 @@ void TabContainer::_repaint_internal() {
|
|||
// 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) {
|
||||
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());
|
||||
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());
|
||||
} else {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
updating_visibility = true;
|
||||
|
|
@ -325,7 +400,6 @@ void TabContainer::_repaint_internal() {
|
|||
updating_visibility = false;
|
||||
|
||||
update_minimum_size();
|
||||
layout_pending_finish();
|
||||
}
|
||||
|
||||
void TabContainer::_update_margins() {
|
||||
|
|
@ -339,28 +413,32 @@ 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) {
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (get_tab_alignment()) {
|
||||
case TabBar::ALIGNMENT_LEFT: {
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin + theme_cache.side_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin + theme_cache.side_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} break;
|
||||
|
||||
case TabBar::ALIGNMENT_CENTER: {
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} break;
|
||||
|
||||
case TabBar::ALIGNMENT_RIGHT: {
|
||||
internal_container->set_offset(SIDE_LEFT, left_margin);
|
||||
tab_bar->set_offset(SIDE_LEFT, left_margin);
|
||||
|
||||
if (has_popup) {
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -370,9 +448,9 @@ 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))) {
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin);
|
||||
} else {
|
||||
internal_container->set_offset(SIDE_RIGHT, -right_margin - theme_cache.side_margin);
|
||||
tab_bar->set_offset(SIDE_RIGHT, -right_margin - theme_cache.side_margin);
|
||||
}
|
||||
} break;
|
||||
|
||||
|
|
@ -381,16 +459,24 @@ void TabContainer::_update_margins() {
|
|||
}
|
||||
}
|
||||
|
||||
void TabContainer::_on_mouse_exited() {
|
||||
if (menu_hovered) {
|
||||
menu_hovered = false;
|
||||
queue_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
Vector<Control *> TabContainer::_get_tab_controls() const {
|
||||
Vector<Control *> controls;
|
||||
ERR_THREAD_GUARD_V(controls);
|
||||
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (control) {
|
||||
controls.push_back(control);
|
||||
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;
|
||||
}
|
||||
|
||||
controls.push_back(control);
|
||||
}
|
||||
|
||||
return controls;
|
||||
}
|
||||
|
||||
|
|
@ -420,44 +506,17 @@ 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) {
|
||||
HBoxContainer *parent = Object::cast_to<HBoxContainer>(p_from_tabbar->get_parent()); // The internal container.
|
||||
Node *parent = p_from_tabbar->get_parent();
|
||||
if (!parent) {
|
||||
return;
|
||||
}
|
||||
TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent->get_parent());
|
||||
TabContainer *from_tab_container = Object::cast_to<TabContainer>(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());
|
||||
|
|
@ -505,16 +564,15 @@ void TabContainer::_on_tab_hovered(int p_tab) {
|
|||
}
|
||||
|
||||
void TabContainer::_on_tab_changed(int p_tab) {
|
||||
_repaint();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
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()) {
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
}
|
||||
|
||||
emit_signal(SNAME("tab_selected"), p_tab);
|
||||
|
|
@ -582,7 +640,7 @@ void TabContainer::_refresh_tab_names() {
|
|||
void TabContainer::add_child_notify(Node *p_child) {
|
||||
Container::add_child_notify(p_child);
|
||||
|
||||
if (p_child == internal_container) {
|
||||
if (p_child == tab_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -606,7 +664,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()) {
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
}
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -614,7 +672,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 == internal_container) {
|
||||
if (p_child == tab_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -632,11 +690,11 @@ void TabContainer::remove_child_notify(Node *p_child) {
|
|||
Container::remove_child_notify(p_child);
|
||||
|
||||
if (tab_panels.has(p_child)) {
|
||||
AccessibilityServer::get_singleton()->free_element(tab_panels[p_child]);
|
||||
DisplayServer::get_singleton()->accessibility_free_element(tab_panels[p_child]);
|
||||
tab_panels.erase(p_child);
|
||||
}
|
||||
|
||||
if (p_child == internal_container) {
|
||||
if (p_child == tab_bar) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -668,7 +726,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()) {
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
}
|
||||
notify_property_list_changed();
|
||||
}
|
||||
|
|
@ -715,24 +773,12 @@ bool TabContainer::get_deselect_enabled() const {
|
|||
}
|
||||
|
||||
Control *TabContainer::get_tab_control(int p_idx) const {
|
||||
if (p_idx < 0) {
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
if (p_idx >= 0 && p_idx < controls.size()) {
|
||||
return controls[p_idx];
|
||||
} else {
|
||||
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 {
|
||||
|
|
@ -746,20 +792,14 @@ 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);
|
||||
|
||||
int idx = 0;
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (!control) {
|
||||
continue;
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
for (int i = 0; i < controls.size(); i++) {
|
||||
if (controls[i] == p_child) {
|
||||
return i;
|
||||
}
|
||||
|
||||
if (control == p_child) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -785,7 +825,7 @@ void TabContainer::set_tabs_position(TabPosition p_tabs_position) {
|
|||
|
||||
tab_bar->set_tab_style_v_flip(tabs_position == POSITION_BOTTOM);
|
||||
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
|
@ -817,7 +857,7 @@ void TabContainer::set_tabs_visible(bool p_visible) {
|
|||
tabs_visible = p_visible;
|
||||
tab_bar->set_visible(tabs_visible);
|
||||
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
queue_redraw();
|
||||
}
|
||||
|
||||
|
|
@ -958,7 +998,7 @@ void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
|
|||
if (!get_clip_tabs()) {
|
||||
update_minimum_size();
|
||||
}
|
||||
_repaint_call_deferred();
|
||||
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
||||
}
|
||||
|
||||
bool TabContainer::is_tab_hidden(int p_tab) const {
|
||||
|
|
@ -993,7 +1033,7 @@ Size2 TabContainer::get_minimum_size() const {
|
|||
ms.height += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM);
|
||||
|
||||
if (get_popup()) {
|
||||
ms.width += popup_button->get_minimum_size().x;
|
||||
ms.width += theme_cache.menu_icon->get_width();
|
||||
}
|
||||
|
||||
if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
|
||||
|
|
@ -1034,26 +1074,8 @@ 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)) {
|
||||
popup_button->set_visible(popup != nullptr);
|
||||
queue_redraw();
|
||||
_update_margins();
|
||||
update_minimum_size();
|
||||
}
|
||||
|
|
@ -1197,7 +1219,6 @@ 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);
|
||||
|
|
@ -1249,31 +1270,25 @@ 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::get_class_static()), defaults.icon, &TabContainer::set_tab_icon, &TabContainer::get_tab_icon);
|
||||
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::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(get_class_static(), &base_property_helper);
|
||||
PropertyListHelper::register_base_helper(&base_property_helper);
|
||||
}
|
||||
|
||||
TabContainer::TabContainer() {
|
||||
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_h_size_flags(SIZE_EXPAND_FILL);
|
||||
internal_container->add_child(tab_bar);
|
||||
tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
|
||||
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