Merge pull request #43972 from volzhs/fix-tab-container-3
Fix TabContainer crashes
This commit is contained in:
commit
4f30cdfc33
1 changed files with 12 additions and 10 deletions
|
@ -352,29 +352,31 @@ void TabContainer::_notification(int p_what) {
|
|||
// Draw unselected tabs in back
|
||||
int x = 0;
|
||||
int x_current = 0;
|
||||
int index = 0;
|
||||
for (int i = 0; i < tab_widths.size(); i++) {
|
||||
if (get_tab_hidden(i)) {
|
||||
index = i + first_tab_cache;
|
||||
if (get_tab_hidden(index)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int tab_width = tab_widths[i];
|
||||
if (get_tab_disabled(i + first_tab_cache)) {
|
||||
_draw_tab(tab_disabled, font_color_disabled, i, tabs_ofs_cache + x);
|
||||
} else if (i + first_tab_cache == current) {
|
||||
if (get_tab_disabled(index)) {
|
||||
_draw_tab(tab_disabled, font_color_disabled, index, tabs_ofs_cache + x);
|
||||
} else if (index == current) {
|
||||
x_current = x;
|
||||
} else {
|
||||
_draw_tab(tab_bg, font_color_bg, i, tabs_ofs_cache + x);
|
||||
_draw_tab(tab_bg, font_color_bg, index, tabs_ofs_cache + x);
|
||||
}
|
||||
|
||||
x += tab_width;
|
||||
last_tab_cache = i + first_tab_cache;
|
||||
last_tab_cache = index;
|
||||
}
|
||||
|
||||
// Draw the tab area.
|
||||
panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
|
||||
|
||||
// Draw selected tab in front. Need to check tabs.size() in case of no contents at all.
|
||||
if (tabs.size() > 0) {
|
||||
// Draw selected tab in front. only draw selected tab when it's in visible range.
|
||||
if (tabs.size() > 0 && current - first_tab_cache < tab_widths.size() && current >= first_tab_cache) {
|
||||
_draw_tab(tab_fg, font_color_fg, current, tabs_ofs_cache + x_current);
|
||||
}
|
||||
|
||||
|
@ -418,7 +420,7 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in
|
|||
Vector<Control *> tabs = _get_tabs();
|
||||
RID canvas = get_canvas_item();
|
||||
Ref<Font> font = get_font("font");
|
||||
int icon_text_distance = get_constant("icon_separation");
|
||||
int icon_text_distance = get_constant("hseparation");
|
||||
int tab_width = _get_tab_width(p_index);
|
||||
int header_height = _get_top_margin();
|
||||
|
||||
|
@ -427,7 +429,7 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in
|
|||
p_tab_style->draw(canvas, tab_rect);
|
||||
|
||||
// Draw the tab contents.
|
||||
Control *control = Object::cast_to<Control>(tabs[p_index + first_tab_cache]);
|
||||
Control *control = Object::cast_to<Control>(tabs[p_index]);
|
||||
String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name()));
|
||||
|
||||
int x_content = tab_rect.position.x + p_tab_style->get_margin(MARGIN_LEFT);
|
||||
|
|
Loading…
Reference in a new issue