2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* tab_container.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "tab_container.h"
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2023-09-08 21:00:10 +02:00
|
|
|
#include "scene/theme/theme_db.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
int TabContainer::_get_tab_height() const {
|
2022-03-02 15:37:10 +01:00
|
|
|
int height = 0;
|
|
|
|
if (tabs_visible && get_tab_count() > 0) {
|
|
|
|
height = tab_bar->get_minimum_size().height;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-01-21 19:11:33 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
return height;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2021-08-22 17:37:22 +02:00
|
|
|
void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
|
2021-04-05 08:52:21 +02:00
|
|
|
ERR_FAIL_COND(p_event.is_null());
|
|
|
|
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-06-24 19:14:20 +02:00
|
|
|
Popup *popup = get_popup();
|
|
|
|
|
2021-08-13 23:31:57 +02:00
|
|
|
if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
2021-09-25 11:01:45 +02:00
|
|
|
Point2 pos = mb->get_position();
|
2017-01-21 19:11:33 +01:00
|
|
|
Size2 size = get_size();
|
2023-09-27 23:23:22 +02:00
|
|
|
real_t content_height = size.height - _get_tab_height();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-21 19:11:33 +01:00
|
|
|
// Click must be on tabs in the tab header area.
|
2023-09-27 23:23:22 +02:00
|
|
|
if (tabs_position == POSITION_TOP && pos.y > _get_tab_height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tabs_position == POSITION_BOTTOM && pos.y < content_height) {
|
2017-01-21 19:11:33 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-21 19:11:33 +01:00
|
|
|
// Handle menu button.
|
2023-09-27 23:23:22 +02:00
|
|
|
if (popup) {
|
|
|
|
if (is_layout_rtl() ? pos.x < theme_cache.menu_icon->get_width() : pos.x > size.width - theme_cache.menu_icon->get_width()) {
|
2021-07-17 23:22:52 +02:00
|
|
|
emit_signal(SNAME("pre_popup_pressed"));
|
2020-09-03 13:22:16 +02:00
|
|
|
|
|
|
|
Vector2 popup_pos = get_screen_position();
|
2023-09-27 23:23:22 +02:00
|
|
|
if (!is_layout_rtl()) {
|
|
|
|
popup_pos.x += size.width - popup->get_size().width;
|
|
|
|
}
|
|
|
|
popup_pos.y += _get_tab_height() / 2.0;
|
|
|
|
if (tabs_position == POSITION_BOTTOM) {
|
|
|
|
popup_pos.y += content_height;
|
|
|
|
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;
|
|
|
|
}
|
2020-09-03 13:22:16 +02:00
|
|
|
|
|
|
|
popup->set_position(popup_pos);
|
|
|
|
popup->popup();
|
|
|
|
return;
|
|
|
|
}
|
2015-06-14 03:12:53 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2019-09-23 04:07:00 +02:00
|
|
|
|
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
|
|
|
|
|
|
if (mm.is_valid()) {
|
2021-09-25 11:01:45 +02:00
|
|
|
Point2 pos = mm->get_position();
|
2019-09-23 04:07:00 +02:00
|
|
|
Size2 size = get_size();
|
|
|
|
|
|
|
|
// Mouse must be on tabs in the tab header area.
|
2023-09-27 23:23:22 +02:00
|
|
|
if (tabs_position == POSITION_TOP && pos.y > _get_tab_height()) {
|
|
|
|
if (menu_hovered) {
|
|
|
|
menu_hovered = false;
|
|
|
|
queue_redraw();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tabs_position == POSITION_BOTTOM && pos.y < size.height - _get_tab_height()) {
|
2022-03-02 15:37:10 +01:00
|
|
|
if (menu_hovered) {
|
2019-09-23 04:07:00 +02:00
|
|
|
menu_hovered = false;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2019-09-23 04:07:00 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (popup) {
|
2020-09-03 13:22:16 +02:00
|
|
|
if (is_layout_rtl()) {
|
2022-08-31 14:02:40 +02:00
|
|
|
if (pos.x <= theme_cache.menu_icon->get_width()) {
|
2020-09-03 13:22:16 +02:00
|
|
|
if (!menu_hovered) {
|
|
|
|
menu_hovered = true;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-09-03 13:22:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (menu_hovered) {
|
|
|
|
menu_hovered = false;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-09-03 13:22:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
2022-08-31 14:02:40 +02:00
|
|
|
if (pos.x >= size.width - theme_cache.menu_icon->get_width()) {
|
2020-09-03 13:22:16 +02:00
|
|
|
if (!menu_hovered) {
|
|
|
|
menu_hovered = true;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-09-03 13:22:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (menu_hovered) {
|
|
|
|
menu_hovered = false;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2019-09-23 04:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu_hovered) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::_notification(int p_what) {
|
2017-01-21 19:11:33 +01:00
|
|
|
switch (p_what) {
|
2022-03-04 16:09:02 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
|
|
|
// If some nodes happen to be renamed outside the tree, the tab names need to be updated manually.
|
|
|
|
if (get_tab_count() > 0) {
|
|
|
|
_refresh_tab_names();
|
|
|
|
}
|
|
|
|
|
2024-01-15 00:39:47 +01:00
|
|
|
if (setup_current_tab >= -1) {
|
2023-10-24 18:00:54 +02:00
|
|
|
set_current_tab(setup_current_tab);
|
2024-01-15 00:39:47 +01:00
|
|
|
setup_current_tab = -2;
|
2023-10-24 18:00:54 +02:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
case NOTIFICATION_READY:
|
2018-06-12 19:22:41 +02:00
|
|
|
case NOTIFICATION_RESIZED: {
|
2022-03-02 15:37:10 +01:00
|
|
|
_update_margins();
|
2018-06-12 19:22:41 +02:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
case NOTIFICATION_DRAW: {
|
2017-01-21 19:11:33 +01:00
|
|
|
RID canvas = get_canvas_item();
|
2014-02-10 02:10:30 +01:00
|
|
|
Size2 size = get_size();
|
|
|
|
|
2017-01-21 19:11:33 +01:00
|
|
|
// Draw only the tab area if the header is hidden.
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!tabs_visible) {
|
2022-08-31 14:02:40 +02:00
|
|
|
theme_cache.panel_style->draw(canvas, Rect2(0, 0, size.width, size.height));
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
int header_height = _get_tab_height();
|
|
|
|
int header_voffset = int(tabs_position == POSITION_BOTTOM) * (size.height - header_height);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-08-29 16:40:17 +02:00
|
|
|
// Draw background for the tabbar.
|
2023-09-27 23:23:22 +02:00
|
|
|
theme_cache.tabbar_style->draw(canvas, Rect2(0, header_voffset, size.width, header_height));
|
2022-08-29 16:40:17 +02:00
|
|
|
// Draw the background for the tab's content.
|
2023-09-27 23:23:22 +02:00
|
|
|
theme_cache.panel_style->draw(canvas, Rect2(0, int(tabs_position == POSITION_TOP) * header_height, size.width, size.height - header_height));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
// Draw the popup menu.
|
|
|
|
if (get_popup()) {
|
2022-08-31 14:02:40 +02:00
|
|
|
int x = is_layout_rtl() ? 0 : get_size().width - theme_cache.menu_icon->get_width();
|
2020-10-13 15:05:26 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (menu_hovered) {
|
2023-09-27 23:23:22 +02:00
|
|
|
theme_cache.menu_hl_icon->draw(get_canvas_item(), Point2(x, header_voffset + (header_height - theme_cache.menu_hl_icon->get_height()) / 2));
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2023-09-27 23:23:22 +02:00
|
|
|
theme_cache.menu_icon->draw(get_canvas_item(), Point2(x, header_voffset + (header_height - theme_cache.menu_icon->get_height()) / 2));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-14 03:12:53 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2024-04-26 00:07:58 +02:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED: {
|
|
|
|
if (!is_visible() || setup_current_tab > -2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updating_visibility = true;
|
|
|
|
|
|
|
|
// As the visibility change notification will be triggered for all children soon after,
|
|
|
|
// beat it to the punch and make sure that the correct node is the only one visible first.
|
|
|
|
// Otherwise, it can prevent a tab change done right before this container was made visible.
|
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
|
|
|
int current = get_current_tab();
|
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
controls[i]->set_visible(i == current);
|
|
|
|
}
|
|
|
|
|
|
|
|
updating_visibility = false;
|
|
|
|
} break;
|
|
|
|
|
2020-09-03 13:22:16 +02:00
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED:
|
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
|
2016-05-30 05:28:29 +02:00
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2022-03-02 15:37:10 +01:00
|
|
|
theme_changing = true;
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_on_theme_changed).call_deferred(); // Wait until all changed theme.
|
2016-05-30 05:28:29 +02:00
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-12 17:41:51 +01:00
|
|
|
void TabContainer::_on_theme_changed() {
|
2022-03-02 15:37:10 +01:00
|
|
|
if (!theme_changing) {
|
2020-12-12 17:41:51 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-19 18:05:19 +02:00
|
|
|
tab_bar->begin_bulk_theme_override();
|
|
|
|
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->add_theme_style_override(SNAME("tab_unselected"), theme_cache.tab_unselected_style);
|
2023-03-09 03:52:57 +01:00
|
|
|
tab_bar->add_theme_style_override(SNAME("tab_hovered"), theme_cache.tab_hovered_style);
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->add_theme_style_override(SNAME("tab_selected"), theme_cache.tab_selected_style);
|
|
|
|
tab_bar->add_theme_style_override(SNAME("tab_disabled"), theme_cache.tab_disabled_style);
|
2023-06-25 17:56:52 +02:00
|
|
|
tab_bar->add_theme_style_override(SNAME("tab_focus"), theme_cache.tab_focus_style);
|
2022-08-31 14:02:40 +02:00
|
|
|
|
|
|
|
tab_bar->add_theme_icon_override(SNAME("increment"), theme_cache.increment_icon);
|
|
|
|
tab_bar->add_theme_icon_override(SNAME("increment_highlight"), theme_cache.increment_hl_icon);
|
|
|
|
tab_bar->add_theme_icon_override(SNAME("decrement"), theme_cache.decrement_icon);
|
|
|
|
tab_bar->add_theme_icon_override(SNAME("decrement_highlight"), theme_cache.decrement_hl_icon);
|
|
|
|
tab_bar->add_theme_icon_override(SNAME("drop_mark"), theme_cache.drop_mark_icon);
|
|
|
|
tab_bar->add_theme_color_override(SNAME("drop_mark_color"), theme_cache.drop_mark_color);
|
|
|
|
|
|
|
|
tab_bar->add_theme_color_override(SNAME("font_selected_color"), theme_cache.font_selected_color);
|
2023-08-27 14:28:24 +02:00
|
|
|
tab_bar->add_theme_color_override(SNAME("font_hovered_color"), theme_cache.font_hovered_color);
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->add_theme_color_override(SNAME("font_unselected_color"), theme_cache.font_unselected_color);
|
|
|
|
tab_bar->add_theme_color_override(SNAME("font_disabled_color"), theme_cache.font_disabled_color);
|
|
|
|
tab_bar->add_theme_color_override(SNAME("font_outline_color"), theme_cache.font_outline_color);
|
|
|
|
|
|
|
|
tab_bar->add_theme_font_override(SNAME("font"), theme_cache.tab_font);
|
|
|
|
tab_bar->add_theme_font_size_override(SNAME("font_size"), theme_cache.tab_font_size);
|
|
|
|
|
|
|
|
tab_bar->add_theme_constant_override(SNAME("h_separation"), theme_cache.icon_separation);
|
2023-03-31 21:17:59 +02:00
|
|
|
tab_bar->add_theme_constant_override(SNAME("icon_max_width"), theme_cache.icon_max_width);
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->add_theme_constant_override(SNAME("outline_size"), theme_cache.outline_size);
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2023-10-19 18:05:19 +02:00
|
|
|
tab_bar->end_bulk_theme_override();
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
_update_margins();
|
2017-12-11 12:46:33 +01:00
|
|
|
if (get_tab_count() > 0) {
|
2020-06-14 00:15:47 +02:00
|
|
|
_repaint();
|
2022-03-02 15:37:10 +01:00
|
|
|
} else {
|
|
|
|
update_minimum_size();
|
2020-06-14 00:15:47 +02:00
|
|
|
}
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
theme_changing = false;
|
2020-06-14 00:15:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::_repaint() {
|
2022-03-02 15:37:10 +01:00
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
|
|
|
int current = get_current_tab();
|
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
if (tabs_position == POSITION_BOTTOM) {
|
|
|
|
tab_bar->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE);
|
|
|
|
} else {
|
|
|
|
tab_bar->set_anchors_and_offsets_preset(PRESET_TOP_WIDE);
|
|
|
|
}
|
|
|
|
|
2024-01-15 00:39:47 +01:00
|
|
|
updating_visibility = true;
|
2022-03-02 15:37:10 +01:00
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
Control *c = controls[i];
|
|
|
|
|
2020-06-14 00:15:47 +02:00
|
|
|
if (i == current) {
|
|
|
|
c->show();
|
2022-03-19 01:02:57 +01:00
|
|
|
c->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2020-06-14 00:15:47 +02:00
|
|
|
if (tabs_visible) {
|
2023-09-27 23:23:22 +02:00
|
|
|
if (tabs_position == POSITION_BOTTOM) {
|
|
|
|
c->set_offset(SIDE_BOTTOM, -_get_tab_height());
|
|
|
|
} else {
|
|
|
|
c->set_offset(SIDE_TOP, _get_tab_height());
|
|
|
|
}
|
2020-06-14 00:15:47 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2022-08-31 14:02:40 +02:00
|
|
|
c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_TOP));
|
|
|
|
c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_LEFT));
|
|
|
|
c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - theme_cache.panel_style->get_margin(SIDE_RIGHT));
|
|
|
|
c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - theme_cache.panel_style->get_margin(SIDE_BOTTOM));
|
2020-06-14 00:15:47 +02:00
|
|
|
} else {
|
|
|
|
c->hide();
|
|
|
|
}
|
2017-12-11 12:46:33 +01:00
|
|
|
}
|
2024-01-15 00:39:47 +01:00
|
|
|
updating_visibility = false;
|
2017-01-21 19:11:33 +01:00
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
_update_margins();
|
2022-03-02 15:37:10 +01:00
|
|
|
update_minimum_size();
|
2017-01-21 19:11:33 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::_update_margins() {
|
2022-08-31 14:02:40 +02:00
|
|
|
int menu_width = theme_cache.menu_icon->get_width();
|
2017-01-21 19:11:33 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
// Directly check for validity, to avoid errors when quitting.
|
|
|
|
bool has_popup = popup_obj_id.is_valid();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (get_tab_count() == 0) {
|
|
|
|
tab_bar->set_offset(SIDE_LEFT, 0);
|
|
|
|
tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
switch (get_tab_alignment()) {
|
|
|
|
case TabBar::ALIGNMENT_LEFT: {
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->set_offset(SIDE_LEFT, theme_cache.side_margin);
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
|
|
|
|
} break;
|
2021-08-04 20:32:37 +02:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
case TabBar::ALIGNMENT_CENTER: {
|
|
|
|
tab_bar->set_offset(SIDE_LEFT, 0);
|
|
|
|
tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
|
|
|
|
} break;
|
2021-08-04 20:32:37 +02:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
case TabBar::ALIGNMENT_RIGHT: {
|
|
|
|
tab_bar->set_offset(SIDE_LEFT, 0);
|
2020-12-12 17:41:51 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (has_popup) {
|
|
|
|
tab_bar->set_offset(SIDE_RIGHT, -menu_width);
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
int first_tab_pos = tab_bar->get_tab_rect(0).position.x;
|
|
|
|
Rect2 last_tab_rect = tab_bar->get_tab_rect(get_tab_count() - 1);
|
|
|
|
int total_tabs_width = last_tab_rect.position.x - first_tab_pos + last_tab_rect.size.width;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
// Calculate if all the tabs would still fit if the margin was present.
|
2022-08-31 14:02:40 +02:00
|
|
|
if (get_clip_tabs() && (tab_bar->get_offset_buttons_visible() || (get_tab_count() > 1 && (total_tabs_width + theme_cache.side_margin) > get_size().width))) {
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
|
|
|
|
} else {
|
2022-08-31 14:02:40 +02:00
|
|
|
tab_bar->set_offset(SIDE_RIGHT, -theme_cache.side_margin);
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
|
|
|
} break;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
case TabBar::ALIGNMENT_MAX:
|
|
|
|
break; // Can't happen, but silences warning.
|
2017-03-01 18:23:19 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::_on_mouse_exited() {
|
|
|
|
if (menu_hovered) {
|
|
|
|
menu_hovered = false;
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-06-14 03:12:53 +02:00
|
|
|
}
|
2017-03-01 18:23:19 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
Vector<Control *> TabContainer::_get_tab_controls() const {
|
|
|
|
Vector<Control *> controls;
|
|
|
|
for (int i = 0; i < get_child_count(); i++) {
|
|
|
|
Control *control = Object::cast_to<Control>(get_child(i));
|
2022-10-27 06:22:06 +02:00
|
|
|
if (!control || control->is_set_as_top_level() || control == tab_bar || children_removing.has(control)) {
|
2022-03-02 15:37:10 +01:00
|
|
|
continue;
|
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
controls.push_back(control);
|
2021-01-12 10:48:18 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
return controls;
|
2018-02-06 22:32:03 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
Variant TabContainer::_get_drag_data_fw(const Point2 &p_point, Control *p_from_control) {
|
2023-10-25 22:15:56 +02:00
|
|
|
if (!drag_to_rearrange_enabled) {
|
|
|
|
return Variant();
|
|
|
|
}
|
2023-10-19 04:12:50 +02:00
|
|
|
return tab_bar->_handle_get_drag_data("tab_container_tab", p_point);
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
bool TabContainer::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const {
|
2023-10-25 22:15:56 +02:00
|
|
|
if (!drag_to_rearrange_enabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-10-19 04:12:50 +02:00
|
|
|
return tab_bar->_handle_can_drop_data("tab_container_tab", p_point, p_data);
|
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) {
|
2023-10-25 22:15:56 +02:00
|
|
|
if (!drag_to_rearrange_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
2023-10-19 04:12:50 +02:00
|
|
|
return tab_bar->_handle_drop_data("tab_container_tab", p_point, p_data, callable_mp(this, &TabContainer::_drag_move_tab), callable_mp(this, &TabContainer::_drag_move_tab_from));
|
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
void TabContainer::_drag_move_tab(int p_from_index, int p_to_index) {
|
|
|
|
move_child(get_tab_control(p_from_index), get_tab_control(p_to_index)->get_index(false));
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
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();
|
|
|
|
if (!parent) {
|
2018-02-07 14:01:45 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2023-10-19 04:12:50 +02:00
|
|
|
TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent);
|
|
|
|
if (!from_tab_container) {
|
2018-02-07 14:01:45 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2023-10-19 04:12:50 +02:00
|
|
|
move_tab_from_tab_container(from_tab_container, p_from_index, p_to_index);
|
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
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());
|
|
|
|
ERR_FAIL_INDEX(p_to_index, get_tab_count() + 1);
|
2022-03-20 02:24:36 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
// Get the tab properties before they get erased by the child removal.
|
|
|
|
String tab_title = p_from->get_tab_title(p_from_index);
|
2024-03-07 12:18:27 +01:00
|
|
|
String tab_tooltip = p_from->get_tab_tooltip(p_from_index);
|
2023-10-19 04:12:50 +02:00
|
|
|
Ref<Texture2D> tab_icon = p_from->get_tab_icon(p_from_index);
|
2023-10-28 17:08:59 +02:00
|
|
|
Ref<Texture2D> tab_button_icon = p_from->get_tab_button_icon(p_from_index);
|
2023-10-19 04:12:50 +02:00
|
|
|
bool tab_disabled = p_from->is_tab_disabled(p_from_index);
|
2023-10-28 17:08:59 +02:00
|
|
|
bool tab_hidden = p_from->is_tab_hidden(p_from_index);
|
2023-10-19 04:12:50 +02:00
|
|
|
Variant tab_metadata = p_from->get_tab_metadata(p_from_index);
|
2023-10-28 17:08:59 +02:00
|
|
|
int tab_icon_max_width = p_from->get_tab_bar()->get_tab_icon_max_width(p_from_index);
|
2022-03-20 02:24:36 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
Control *moving_tabc = p_from->get_tab_control(p_from_index);
|
|
|
|
p_from->remove_child(moving_tabc);
|
|
|
|
add_child(moving_tabc, true);
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
if (p_to_index < 0 || p_to_index > get_tab_count() - 1) {
|
|
|
|
p_to_index = get_tab_count() - 1;
|
|
|
|
}
|
|
|
|
move_child(moving_tabc, get_tab_control(p_to_index)->get_index(false));
|
2023-10-28 17:08:59 +02:00
|
|
|
|
|
|
|
set_tab_title(p_to_index, tab_title);
|
2024-03-07 12:18:27 +01:00
|
|
|
set_tab_tooltip(p_to_index, tab_tooltip);
|
2023-10-28 17:08:59 +02:00
|
|
|
set_tab_icon(p_to_index, tab_icon);
|
|
|
|
set_tab_button_icon(p_to_index, tab_button_icon);
|
|
|
|
set_tab_disabled(p_to_index, tab_disabled);
|
|
|
|
set_tab_hidden(p_to_index, tab_hidden);
|
|
|
|
set_tab_metadata(p_to_index, tab_metadata);
|
|
|
|
get_tab_bar()->set_tab_icon_max_width(p_to_index, tab_icon_max_width);
|
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
if (!is_tab_disabled(p_to_index)) {
|
|
|
|
set_current_tab(p_to_index);
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-23 17:50:35 +02:00
|
|
|
void TabContainer::_on_tab_clicked(int p_tab) {
|
|
|
|
emit_signal(SNAME("tab_clicked"), p_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::_on_tab_hovered(int p_tab) {
|
|
|
|
emit_signal(SNAME("tab_hovered"), p_tab);
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::_on_tab_changed(int p_tab) {
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2024-01-15 00:39:47 +01:00
|
|
|
queue_redraw();
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
emit_signal(SNAME("tab_changed"), p_tab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::_on_tab_selected(int p_tab) {
|
|
|
|
if (p_tab != get_previous_tab()) {
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
emit_signal(SNAME("tab_selected"), p_tab);
|
|
|
|
}
|
|
|
|
|
2022-03-17 00:24:47 +01:00
|
|
|
void TabContainer::_on_tab_button_pressed(int p_tab) {
|
|
|
|
emit_signal(SNAME("tab_button_pressed"), p_tab);
|
|
|
|
}
|
|
|
|
|
2023-10-19 04:12:50 +02:00
|
|
|
void TabContainer::_on_active_tab_rearranged(int p_tab) {
|
|
|
|
emit_signal(SNAME("active_tab_rearranged"), p_tab);
|
|
|
|
}
|
|
|
|
|
2024-01-15 00:39:47 +01:00
|
|
|
void TabContainer::_on_tab_visibility_changed(Control *p_child) {
|
|
|
|
if (updating_visibility) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int tab_index = get_tab_idx_from_control(p_child);
|
|
|
|
if (tab_index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Only allow one tab to be visible.
|
|
|
|
bool made_visible = p_child->is_visible();
|
|
|
|
updating_visibility = true;
|
|
|
|
|
|
|
|
if (!made_visible && get_current_tab() == tab_index) {
|
|
|
|
if (get_deselect_enabled() || get_tab_count() == 0) {
|
|
|
|
// Deselect.
|
|
|
|
set_current_tab(-1);
|
|
|
|
} else if (get_tab_count() == 1) {
|
|
|
|
// Only tab, cannot deselect.
|
|
|
|
p_child->show();
|
|
|
|
} else {
|
|
|
|
// Set a different tab to be the current tab.
|
|
|
|
bool selected = select_next_available();
|
|
|
|
if (!selected) {
|
|
|
|
selected = select_previous_available();
|
|
|
|
}
|
|
|
|
if (!selected) {
|
|
|
|
// No available tabs, deselect.
|
|
|
|
set_current_tab(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (made_visible && get_current_tab() != tab_index) {
|
|
|
|
set_current_tab(tab_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
updating_visibility = false;
|
|
|
|
}
|
|
|
|
|
2024-04-09 07:02:05 +02:00
|
|
|
void TabContainer::_refresh_tab_indices() {
|
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
controls[i]->set_meta("_tab_index", i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-04 16:09:02 +01:00
|
|
|
void TabContainer::_refresh_tab_names() {
|
2022-03-02 15:37:10 +01:00
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
if (!controls[i]->has_meta("_tab_name") && String(controls[i]->get_name()) != get_tab_title(i)) {
|
|
|
|
tab_bar->set_tab_title(i, controls[i]->get_name());
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::add_child_notify(Node *p_child) {
|
2022-09-18 14:55:04 +02:00
|
|
|
Container::add_child_notify(p_child);
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (p_child == tab_bar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Control *c = Object::cast_to<Control>(p_child);
|
|
|
|
if (!c || c->is_set_as_top_level()) {
|
|
|
|
return;
|
2020-09-03 13:22:16 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
c->hide();
|
|
|
|
|
|
|
|
tab_bar->add_tab(p_child->get_name());
|
2024-04-09 07:02:05 +02:00
|
|
|
c->set_meta("_tab_index", tab_bar->get_tab_count() - 1);
|
2020-09-03 13:22:16 +02:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
_update_margins();
|
2022-03-31 21:34:27 +02:00
|
|
|
if (get_tab_count() == 1) {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2022-03-31 21:34:27 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2022-03-04 16:09:02 +01:00
|
|
|
p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names));
|
2024-05-13 16:56:03 +02:00
|
|
|
p_child->connect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c));
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
// TabBar won't emit the "tab_changed" signal when not inside the tree.
|
|
|
|
if (!is_inside_tree()) {
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2020-09-03 13:22:16 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::move_child_notify(Node *p_child) {
|
2023-04-30 00:11:58 +02:00
|
|
|
Container::move_child_notify(p_child);
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (p_child == tab_bar) {
|
|
|
|
return;
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
Control *c = Object::cast_to<Control>(p_child);
|
|
|
|
if (c && !c->is_set_as_top_level()) {
|
2024-04-09 07:02:05 +02:00
|
|
|
tab_bar->move_tab(c->get_meta("_tab_index"), get_tab_idx_from_control(c));
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
2024-04-09 07:02:05 +02:00
|
|
|
|
|
|
|
_refresh_tab_indices();
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::remove_child_notify(Node *p_child) {
|
2023-04-30 00:11:58 +02:00
|
|
|
Container::remove_child_notify(p_child);
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (p_child == tab_bar) {
|
|
|
|
return;
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
Control *c = Object::cast_to<Control>(p_child);
|
|
|
|
if (!c || c->is_set_as_top_level()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-18 13:56:23 +02:00
|
|
|
int idx = get_tab_idx_from_control(c);
|
|
|
|
|
2022-10-27 06:22:06 +02:00
|
|
|
// As the child hasn't been removed yet, keep track of it so when the "tab_changed" signal is fired it can be ignored.
|
|
|
|
children_removing.push_back(c);
|
2024-04-09 07:02:05 +02:00
|
|
|
|
2022-07-18 13:56:23 +02:00
|
|
|
tab_bar->remove_tab(idx);
|
2024-04-09 07:02:05 +02:00
|
|
|
_refresh_tab_indices();
|
|
|
|
|
2022-10-27 06:22:06 +02:00
|
|
|
children_removing.erase(c);
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
_update_margins();
|
2022-03-31 21:34:27 +02:00
|
|
|
if (get_tab_count() == 0) {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2022-03-31 21:34:27 +02:00
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2024-04-09 07:02:05 +02:00
|
|
|
p_child->remove_meta("_tab_index");
|
2022-04-01 20:30:23 +02:00
|
|
|
p_child->remove_meta("_tab_name");
|
2022-03-04 16:09:02 +01:00
|
|
|
p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names));
|
2024-05-13 16:56:03 +02:00
|
|
|
p_child->disconnect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed));
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
// TabBar won't emit the "tab_changed" signal when not inside the tree.
|
|
|
|
if (!is_inside_tree()) {
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-03 20:53:49 +02:00
|
|
|
TabBar *TabContainer::get_tab_bar() const {
|
|
|
|
return tab_bar;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
int TabContainer::get_tab_count() const {
|
|
|
|
return tab_bar->get_tab_count();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabContainer::set_current_tab(int p_current) {
|
2023-10-24 18:00:54 +02:00
|
|
|
if (!is_inside_tree()) {
|
|
|
|
setup_current_tab = p_current;
|
|
|
|
return;
|
|
|
|
}
|
2024-04-26 00:07:58 +02:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_current_tab(p_current);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabContainer::get_current_tab() const {
|
|
|
|
return tab_bar->get_current_tab();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabContainer::get_previous_tab() const {
|
|
|
|
return tab_bar->get_previous_tab();
|
|
|
|
}
|
|
|
|
|
2023-06-25 17:56:52 +02:00
|
|
|
bool TabContainer::select_previous_available() {
|
|
|
|
return tab_bar->select_previous_available();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::select_next_available() {
|
|
|
|
return tab_bar->select_next_available();
|
|
|
|
}
|
|
|
|
|
2024-01-15 00:39:47 +01:00
|
|
|
void TabContainer::set_deselect_enabled(bool p_enabled) {
|
|
|
|
tab_bar->set_deselect_enabled(p_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::get_deselect_enabled() const {
|
|
|
|
return tab_bar->get_deselect_enabled();
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
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 {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Control *TabContainer::get_current_tab_control() const {
|
|
|
|
return get_tab_control(tab_bar->get_current_tab());
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
|
|
|
|
return tab_bar->get_tab_idx_at_point(p_point);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
if (controls[i] == p_child) {
|
2018-02-07 14:01:45 +01:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2018-02-07 14:01:45 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::set_tab_alignment(TabBar::AlignmentMode p_alignment) {
|
2022-03-16 08:50:48 +01:00
|
|
|
if (tab_bar->get_tab_alignment() == p_alignment) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_tab_alignment(p_alignment);
|
|
|
|
_update_margins();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2018-02-07 14:01:45 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
TabBar::AlignmentMode TabContainer::get_tab_alignment() const {
|
|
|
|
return tab_bar->get_tab_alignment();
|
|
|
|
}
|
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
void TabContainer::set_tabs_position(TabPosition p_tabs_position) {
|
|
|
|
ERR_FAIL_INDEX(p_tabs_position, POSITION_MAX);
|
|
|
|
if (p_tabs_position == tabs_position) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tabs_position = p_tabs_position;
|
|
|
|
|
|
|
|
tab_bar->set_tab_style_v_flip(tabs_position == POSITION_BOTTOM);
|
|
|
|
|
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
|
|
|
queue_redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
TabContainer::TabPosition TabContainer::get_tabs_position() const {
|
|
|
|
return tabs_position;
|
|
|
|
}
|
|
|
|
|
2023-06-25 17:56:52 +02:00
|
|
|
void TabContainer::set_tab_focus_mode(Control::FocusMode p_focus_mode) {
|
|
|
|
tab_bar->set_focus_mode(p_focus_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
Control::FocusMode TabContainer::get_tab_focus_mode() const {
|
|
|
|
return tab_bar->get_focus_mode();
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
void TabContainer::set_clip_tabs(bool p_clip_tabs) {
|
|
|
|
tab_bar->set_clip_tabs(p_clip_tabs);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::get_clip_tabs() const {
|
|
|
|
return tab_bar->get_clip_tabs();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-01-25 01:34:47 +01:00
|
|
|
void TabContainer::set_tabs_visible(bool p_visible) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_visible == tabs_visible) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-01-25 01:34:47 +01:00
|
|
|
tabs_visible = p_visible;
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_visible(tabs_visible);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::are_tabs_visible() const {
|
|
|
|
return tabs_visible;
|
|
|
|
}
|
|
|
|
|
2020-12-05 19:12:24 +01:00
|
|
|
void TabContainer::set_all_tabs_in_front(bool p_in_front) {
|
|
|
|
if (p_in_front == all_tabs_in_front) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
all_tabs_in_front = p_in_front;
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
remove_child(tab_bar);
|
2022-03-08 00:19:21 +01:00
|
|
|
add_child(tab_bar, false, all_tabs_in_front ? INTERNAL_MODE_FRONT : INTERNAL_MODE_BACK);
|
2020-12-05 19:12:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::is_all_tabs_in_front() const {
|
|
|
|
return all_tabs_in_front;
|
|
|
|
}
|
|
|
|
|
2017-01-21 19:11:33 +01:00
|
|
|
void TabContainer::set_tab_title(int p_tab, const String &p_title) {
|
2021-08-04 20:32:37 +02:00
|
|
|
Control *child = get_tab_control(p_tab);
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL(child);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-03-16 08:50:48 +01:00
|
|
|
if (tab_bar->get_tab_title(p_tab) == p_title) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-07 02:17:35 +01:00
|
|
|
tab_bar->set_tab_title(p_tab, p_title);
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2022-03-07 02:17:35 +01:00
|
|
|
if (p_title == child->get_name()) {
|
2022-04-01 20:30:23 +02:00
|
|
|
child->remove_meta("_tab_name");
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2022-03-02 15:37:10 +01:00
|
|
|
child->set_meta("_tab_name", p_title);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2022-03-04 16:09:02 +01:00
|
|
|
|
2024-04-23 03:41:05 +02:00
|
|
|
_repaint();
|
|
|
|
queue_redraw();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
String TabContainer::get_tab_title(int p_tab) const {
|
|
|
|
return tab_bar->get_tab_title(p_tab);
|
|
|
|
}
|
|
|
|
|
2024-03-07 12:18:27 +01:00
|
|
|
void TabContainer::set_tab_tooltip(int p_tab, const String &p_tooltip) {
|
|
|
|
tab_bar->set_tab_tooltip(p_tab, p_tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
String TabContainer::get_tab_tooltip(int p_tab) const {
|
|
|
|
return tab_bar->get_tab_tooltip(p_tab);
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
|
2022-03-16 08:50:48 +01:00
|
|
|
if (tab_bar->get_tab_icon(p_tab) == p_icon) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_tab_icon(p_tab, p_icon);
|
2022-03-04 16:09:02 +01:00
|
|
|
|
|
|
|
_update_margins();
|
|
|
|
_repaint();
|
2024-04-20 15:07:49 +02:00
|
|
|
queue_redraw();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-06-11 20:43:37 +02:00
|
|
|
Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
|
2022-03-02 15:37:10 +01:00
|
|
|
return tab_bar->get_tab_icon(p_tab);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2024-04-26 02:27:27 +02:00
|
|
|
void TabContainer::set_tab_icon_max_width(int p_tab, int p_width) {
|
|
|
|
if (tab_bar->get_tab_icon_max_width(p_tab) == p_width) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tab_bar->set_tab_icon_max_width(p_tab, p_width);
|
|
|
|
|
|
|
|
_update_margins();
|
|
|
|
_repaint();
|
|
|
|
queue_redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TabContainer::get_tab_icon_max_width(int p_tab) const {
|
|
|
|
return tab_bar->get_tab_icon_max_width(p_tab);
|
|
|
|
}
|
|
|
|
|
2017-08-11 21:10:05 +02:00
|
|
|
void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
|
2022-03-16 08:50:48 +01:00
|
|
|
if (tab_bar->is_tab_disabled(p_tab) == p_disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_tab_disabled(p_tab, p_disabled);
|
2022-03-04 16:09:02 +01:00
|
|
|
|
|
|
|
_update_margins();
|
|
|
|
if (!get_clip_tabs()) {
|
|
|
|
update_minimum_size();
|
|
|
|
}
|
2017-02-27 19:07:50 +01:00
|
|
|
}
|
2017-03-01 18:23:19 +01:00
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
bool TabContainer::is_tab_disabled(int p_tab) const {
|
|
|
|
return tab_bar->is_tab_disabled(p_tab);
|
2017-02-27 19:07:50 +01:00
|
|
|
}
|
|
|
|
|
2019-04-09 00:18:03 +02:00
|
|
|
void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
|
2021-08-04 20:32:37 +02:00
|
|
|
Control *child = get_tab_control(p_tab);
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL(child);
|
2019-04-09 00:18:03 +02:00
|
|
|
|
2022-03-16 08:50:48 +01:00
|
|
|
if (tab_bar->is_tab_hidden(p_tab) == p_hidden) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_tab_hidden(p_tab, p_hidden);
|
2019-04-09 00:18:03 +02:00
|
|
|
child->hide();
|
2022-03-04 16:09:02 +01:00
|
|
|
|
|
|
|
_update_margins();
|
|
|
|
if (!get_clip_tabs()) {
|
|
|
|
update_minimum_size();
|
|
|
|
}
|
2023-09-08 21:00:10 +02:00
|
|
|
callable_mp(this, &TabContainer::_repaint).call_deferred();
|
2019-04-09 00:18:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
bool TabContainer::is_tab_hidden(int p_tab) const {
|
|
|
|
return tab_bar->is_tab_hidden(p_tab);
|
2019-04-09 00:18:03 +02:00
|
|
|
}
|
|
|
|
|
2023-04-11 18:48:47 +02:00
|
|
|
void TabContainer::set_tab_metadata(int p_tab, const Variant &p_metadata) {
|
|
|
|
tab_bar->set_tab_metadata(p_tab, p_metadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant TabContainer::get_tab_metadata(int p_tab) const {
|
|
|
|
return tab_bar->get_tab_metadata(p_tab);
|
|
|
|
}
|
|
|
|
|
2022-03-17 00:24:47 +01:00
|
|
|
void TabContainer::set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon) {
|
|
|
|
tab_bar->set_tab_button_icon(p_tab, p_icon);
|
|
|
|
|
|
|
|
_update_margins();
|
|
|
|
_repaint();
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const {
|
|
|
|
return tab_bar->get_tab_button_icon(p_tab);
|
|
|
|
}
|
|
|
|
|
2015-01-03 02:34:22 +01:00
|
|
|
Size2 TabContainer::get_minimum_size() const {
|
|
|
|
Size2 ms;
|
|
|
|
|
2022-03-02 15:37:10 +01:00
|
|
|
if (tabs_visible) {
|
|
|
|
ms = tab_bar->get_minimum_size();
|
|
|
|
|
|
|
|
if (!get_clip_tabs()) {
|
|
|
|
if (get_popup()) {
|
2022-08-31 14:02:40 +02:00
|
|
|
ms.x += theme_cache.menu_icon->get_width();
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
|
|
|
|
2022-08-31 14:02:40 +02:00
|
|
|
if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
|
2022-03-02 15:37:10 +01:00
|
|
|
(get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) {
|
2022-08-31 14:02:40 +02:00
|
|
|
ms.x += theme_cache.side_margin;
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Control *> controls = _get_tab_controls();
|
2022-09-18 00:32:57 +02:00
|
|
|
Size2 largest_child_min_size;
|
2022-03-02 15:37:10 +01:00
|
|
|
for (int i = 0; i < controls.size(); i++) {
|
|
|
|
Control *c = controls[i];
|
2015-01-03 02:34:22 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) {
|
2015-01-03 02:34:22 +01:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-01-03 02:34:22 +01:00
|
|
|
|
2016-06-17 23:38:40 +02:00
|
|
|
Size2 cms = c->get_combined_minimum_size();
|
2024-03-03 12:49:08 +01:00
|
|
|
largest_child_min_size = largest_child_min_size.max(cms);
|
2015-01-03 02:34:22 +01:00
|
|
|
}
|
2022-09-18 00:32:57 +02:00
|
|
|
ms.y += largest_child_min_size.y;
|
2015-01-03 02:34:22 +01:00
|
|
|
|
2022-08-31 14:02:40 +02:00
|
|
|
Size2 panel_ms = theme_cache.panel_style->get_minimum_size();
|
2022-09-18 00:32:57 +02:00
|
|
|
|
|
|
|
ms.x = MAX(ms.x, largest_child_min_size.x + panel_ms.x);
|
2022-03-02 15:37:10 +01:00
|
|
|
ms.y += panel_ms.y;
|
2016-06-17 23:38:40 +02:00
|
|
|
|
2015-01-03 02:34:22 +01:00
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
2015-06-14 03:12:53 +02:00
|
|
|
void TabContainer::set_popup(Node *p_popup) {
|
2022-03-02 15:37:10 +01:00
|
|
|
bool had_popup = get_popup();
|
|
|
|
|
2020-06-24 19:14:20 +02:00
|
|
|
Popup *popup = Object::cast_to<Popup>(p_popup);
|
2022-03-16 08:50:48 +01:00
|
|
|
ObjectID popup_id = popup ? popup->get_instance_id() : ObjectID();
|
|
|
|
if (popup_obj_id == popup_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
popup_obj_id = popup_id;
|
2022-03-02 15:37:10 +01:00
|
|
|
|
|
|
|
if (had_popup != bool(popup)) {
|
2022-08-13 23:21:24 +02:00
|
|
|
queue_redraw();
|
2022-03-02 15:37:10 +01:00
|
|
|
_update_margins();
|
2022-03-04 16:09:02 +01:00
|
|
|
if (!get_clip_tabs()) {
|
|
|
|
update_minimum_size();
|
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
}
|
2015-06-14 03:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Popup *TabContainer::get_popup() const {
|
2020-06-24 19:14:20 +02:00
|
|
|
if (popup_obj_id.is_valid()) {
|
|
|
|
Popup *popup = Object::cast_to<Popup>(ObjectDB::get_instance(popup_obj_id));
|
|
|
|
if (popup) {
|
|
|
|
return popup;
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
ERR_PRINT("Popup assigned to TabContainer is gone!");
|
|
|
|
#endif
|
|
|
|
popup_obj_id = ObjectID();
|
|
|
|
}
|
|
|
|
}
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2020-06-24 19:14:20 +02:00
|
|
|
return nullptr;
|
2015-06-14 03:12:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-07 14:01:45 +01:00
|
|
|
void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) {
|
2023-10-25 22:15:56 +02:00
|
|
|
drag_to_rearrange_enabled = p_enabled;
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::get_drag_to_rearrange_enabled() const {
|
2023-10-25 22:15:56 +02:00
|
|
|
return drag_to_rearrange_enabled;
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-02-07 14:01:45 +01:00
|
|
|
void TabContainer::set_tabs_rearrange_group(int p_group_id) {
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->set_tabs_rearrange_group(p_group_id);
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TabContainer::get_tabs_rearrange_group() const {
|
2022-03-02 15:37:10 +01:00
|
|
|
return tab_bar->get_tabs_rearrange_group();
|
2018-02-07 14:01:45 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:41:36 +01:00
|
|
|
void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) {
|
2022-03-16 08:50:48 +01:00
|
|
|
if (use_hidden_tabs_for_min_size == p_use_hidden_tabs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:41:36 +01:00
|
|
|
use_hidden_tabs_for_min_size = p_use_hidden_tabs;
|
2022-03-02 15:37:10 +01:00
|
|
|
update_minimum_size();
|
2019-01-26 19:41:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TabContainer::get_use_hidden_tabs_for_min_size() const {
|
|
|
|
return use_hidden_tabs_for_min_size;
|
|
|
|
}
|
2019-09-23 04:07:00 +02:00
|
|
|
|
2021-11-08 21:53:41 +01:00
|
|
|
Vector<int> TabContainer::get_allowed_size_flags_horizontal() const {
|
|
|
|
return Vector<int>();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<int> TabContainer::get_allowed_size_flags_vertical() const {
|
|
|
|
return Vector<int>();
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void TabContainer::_bind_methods() {
|
2017-01-21 19:11:33 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
|
2017-03-01 18:23:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab);
|
2023-06-25 17:56:52 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("select_previous_available"), &TabContainer::select_previous_available);
|
|
|
|
ClassDB::bind_method(D_METHOD("select_next_available"), &TabContainer::select_next_available);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control);
|
2023-08-03 20:53:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_bar"), &TabContainer::get_tab_bar);
|
2020-03-14 14:47:36 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control);
|
2021-11-25 03:58:47 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_alignment", "alignment"), &TabContainer::set_tab_alignment);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_alignment"), &TabContainer::get_tab_alignment);
|
2023-09-27 23:23:22 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tabs_position", "tabs_position"), &TabContainer::set_tabs_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tabs_position"), &TabContainer::get_tabs_position);
|
2022-03-02 15:37:10 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_clip_tabs", "clip_tabs"), &TabContainer::set_clip_tabs);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_clip_tabs"), &TabContainer::get_clip_tabs);
|
2017-01-21 19:11:33 +01:00
|
|
|
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);
|
2020-12-05 19:12:24 +01:00
|
|
|
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);
|
2017-01-21 19:11:33 +01:00
|
|
|
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);
|
2024-03-07 12:18:27 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_tooltip", "tab_idx", "tooltip"), &TabContainer::set_tab_tooltip);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_tooltip", "tab_idx"), &TabContainer::get_tab_tooltip);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
|
2024-04-26 02:27:27 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_icon_max_width", "tab_idx", "width"), &TabContainer::set_tab_icon_max_width);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_icon_max_width", "tab_idx"), &TabContainer::get_tab_icon_max_width);
|
2017-02-27 19:07:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
|
2022-03-02 15:37:10 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled);
|
2021-09-24 06:26:59 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden);
|
2022-03-02 15:37:10 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("is_tab_hidden", "tab_idx"), &TabContainer::is_tab_hidden);
|
2023-04-11 18:48:47 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_metadata", "tab_idx", "metadata"), &TabContainer::set_tab_metadata);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_metadata", "tab_idx"), &TabContainer::get_tab_metadata);
|
2022-03-17 00:24:47 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_button_icon", "tab_idx", "icon"), &TabContainer::set_tab_button_icon);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &TabContainer::get_tab_button_icon);
|
2021-08-24 06:14:07 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point);
|
2022-03-02 15:37:10 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_idx_from_control", "control"), &TabContainer::get_tab_idx_from_control);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);
|
2018-02-07 14:01:45 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_drag_to_rearrange_enabled", "enabled"), &TabContainer::set_drag_to_rearrange_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_drag_to_rearrange_enabled"), &TabContainer::get_drag_to_rearrange_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_tabs_rearrange_group", "group_id"), &TabContainer::set_tabs_rearrange_group);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tabs_rearrange_group"), &TabContainer::get_tabs_rearrange_group);
|
2019-01-26 19:41:36 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_use_hidden_tabs_for_min_size", "enabled"), &TabContainer::set_use_hidden_tabs_for_min_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_use_hidden_tabs_for_min_size"), &TabContainer::get_use_hidden_tabs_for_min_size);
|
2023-06-25 17:56:52 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_tab_focus_mode", "focus_mode"), &TabContainer::set_tab_focus_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_tab_focus_mode"), &TabContainer::get_tab_focus_mode);
|
2024-01-15 00:39:47 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_deselect_enabled", "enabled"), &TabContainer::set_deselect_enabled);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_deselect_enabled"), &TabContainer::get_deselect_enabled);
|
2019-01-26 19:41:36 +01:00
|
|
|
|
2023-04-23 17:50:35 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to")));
|
2017-01-21 19:11:33 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
|
2023-04-23 17:50:35 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("tab_clicked", PropertyInfo(Variant::INT, "tab")));
|
|
|
|
ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab")));
|
2017-03-01 18:23:19 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
|
2022-03-17 00:24:47 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab")));
|
2015-06-14 03:12:53 +02:00
|
|
|
ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-11-25 03:58:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment");
|
2023-10-24 18:00:54 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab");
|
2023-09-27 23:23:22 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_position", PROPERTY_HINT_ENUM, "Top,Bottom"), "set_tabs_position", "get_tabs_position");
|
2022-03-02 15:37:10 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs");
|
2017-01-21 19:11:33 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
|
2020-12-05 19:12:24 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
|
2018-02-07 14:01:45 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled");
|
2022-03-05 21:03:01 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_rearrange_group"), "set_tabs_rearrange_group", "get_tabs_rearrange_group");
|
2019-01-26 19:41:36 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_hidden_tabs_for_min_size"), "set_use_hidden_tabs_for_min_size", "get_use_hidden_tabs_for_min_size");
|
2023-06-25 17:56:52 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_tab_focus_mode", "get_tab_focus_mode");
|
2024-01-15 00:39:47 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled");
|
2023-09-08 21:00:10 +02:00
|
|
|
|
2023-09-27 23:23:22 +02:00
|
|
|
BIND_ENUM_CONSTANT(POSITION_TOP);
|
|
|
|
BIND_ENUM_CONSTANT(POSITION_BOTTOM);
|
|
|
|
BIND_ENUM_CONSTANT(POSITION_MAX);
|
|
|
|
|
2023-09-08 21:00:10 +02:00
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, side_margin);
|
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, panel_style, "panel");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tabbar_style, "tabbar_background");
|
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_icon, "menu");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_hl_icon, "menu_highlight");
|
|
|
|
|
|
|
|
// TabBar overrides.
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_separation);
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_max_width);
|
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_unselected_style, "tab_unselected");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_hovered_style, "tab_hovered");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_selected_style, "tab_selected");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_disabled_style, "tab_disabled");
|
2023-06-25 17:56:52 +02:00
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_focus_style, "tab_focus");
|
2023-09-08 21:00:10 +02:00
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_icon, "increment");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_hl_icon, "increment_highlight");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_icon, "decrement");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_hl_icon, "decrement_highlight");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, drop_mark_icon, "drop_mark");
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, drop_mark_color);
|
|
|
|
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_selected_color);
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_hovered_color);
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_unselected_color);
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_disabled_color);
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_outline_color);
|
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT, TabContainer, tab_font, "font");
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT_SIZE, TabContainer, tab_font_size, "font_size");
|
|
|
|
BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, outline_size);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TabContainer::TabContainer() {
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar = memnew(TabBar);
|
2023-01-14 03:37:19 +01:00
|
|
|
SET_DRAG_FORWARDING_GCDU(tab_bar, TabContainer);
|
2022-03-02 15:37:10 +01:00
|
|
|
add_child(tab_bar, false, INTERNAL_MODE_FRONT);
|
|
|
|
tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
|
|
|
|
tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed));
|
2023-04-23 17:50:35 +02:00
|
|
|
tab_bar->connect("tab_clicked", callable_mp(this, &TabContainer::_on_tab_clicked));
|
|
|
|
tab_bar->connect("tab_hovered", callable_mp(this, &TabContainer::_on_tab_hovered));
|
2022-03-02 15:37:10 +01:00
|
|
|
tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected));
|
2022-03-17 00:24:47 +01:00
|
|
|
tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed));
|
2023-10-19 04:12:50 +02:00
|
|
|
tab_bar->connect("active_tab_rearranged", callable_mp(this, &TabContainer::_on_active_tab_rearranged));
|
2022-03-02 15:37:10 +01:00
|
|
|
|
2024-05-13 16:56:03 +02:00
|
|
|
connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_on_mouse_exited));
|
2017-05-20 17:38:03 +02:00
|
|
|
}
|