summaryrefslogtreecommitdiff
path: root/scene/gui/tab_container.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/tab_container.cpp')
-rw-r--r--scene/gui/tab_container.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 98a8db336e..581034ddee 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -90,19 +90,28 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
return;
}
+ // Do not activate tabs when tabs is empty
+ if (get_tab_count() == 0)
+ return;
+
Vector<Control *> tabs = _get_tabs();
// Handle navigation buttons.
if (buttons_visible_cache) {
+ int popup_ofs = 0;
+ if (popup) {
+ popup_ofs = menu->get_width();
+ }
+
Ref<Texture> increment = get_icon("increment");
Ref<Texture> decrement = get_icon("decrement");
- if (pos.x > size.width - increment->get_width()) {
+ if (pos.x > size.width - increment->get_width() - popup_ofs) {
if (last_tab_cache < tabs.size() - 1) {
first_tab_cache += 1;
update();
}
return;
- } else if (pos.x > size.width - increment->get_width() - decrement->get_width()) {
+ } else if (pos.x > size.width - increment->get_width() - decrement->get_width() - popup_ofs) {
if (first_tab_cache > 0) {
first_tab_cache -= 1;
update();
@@ -264,9 +273,9 @@ void TabContainer::_notification(int p_what) {
if (popup) {
x -= menu->get_width();
if (mouse_x_cache > x)
- menu_hl->draw(get_canvas_item(), Size2(x, 0));
+ menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
else
- menu->draw(get_canvas_item(), Size2(x, 0));
+ menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
}
// Draw the navigation buttons.
@@ -293,6 +302,8 @@ void TabContainer::_notification(int p_what) {
}
int TabContainer::_get_tab_width(int p_index) const {
+
+ ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
if (!control || control->is_set_as_toplevel())
return 0;
@@ -367,7 +378,7 @@ void TabContainer::add_child_notify(Node *p_child) {
current = 0;
previous = 0;
}
- c->set_area_as_parent_rect();
+ c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
if (tabs_visible)
c->set_margin(MARGIN_TOP, _get_top_margin());
Ref<StyleBox> sb = get_stylebox("panel");
@@ -401,7 +412,7 @@ void TabContainer::set_current_tab(int p_current) {
Control *c = tabs[i];
if (i == current) {
c->show();
- c->set_area_as_parent_rect();
+ c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
if (tabs_visible)
c->set_margin(MARGIN_TOP, _get_top_margin());
c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
@@ -664,6 +675,7 @@ void TabContainer::_bind_methods() {
TabContainer::TabContainer() {
first_tab_cache = 0;
+ last_tab_cache = 0;
buttons_visible_cache = false;
tabs_ofs_cache = 0;
current = 0;