| 1 | /**************************************************************************/ |
| 2 | /* tab_container.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "tab_container.h" |
| 32 | |
| 33 | #include "scene/theme/theme_db.h" |
| 34 | |
| 35 | Rect2 TabContainer::_get_tab_rect() const { |
| 36 | Rect2 rect; |
| 37 | if (tabs_visible && get_tab_count() > 0) { |
| 38 | rect = Rect2(theme_cache.tabbar_style->get_offset(), tab_bar->get_size()); |
| 39 | rect.position.x += is_layout_rtl() ? theme_cache.menu_icon->get_width() : theme_cache.side_margin; |
| 40 | } |
| 41 | |
| 42 | return rect; |
| 43 | } |
| 44 | |
| 45 | TabContainer::CachedTab &TabContainer::get_pending_tab(int p_idx) const { |
| 46 | if (p_idx >= pending_tabs.size()) { |
| 47 | pending_tabs.resize(p_idx + 1); |
| 48 | } |
| 49 | return pending_tabs.write[p_idx]; |
| 50 | } |
| 51 | |
| 52 | int TabContainer::_get_tab_height() const { |
| 53 | int height = 0; |
| 54 | if (tabs_visible && get_tab_count() > 0) { |
| 55 | height = tab_bar->get_minimum_size().height + theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM); |
| 56 | } |
| 57 | |
| 58 | return height; |
| 59 | } |
| 60 | |
| 61 | void TabContainer::gui_input(const Ref<InputEvent> &p_event) { |
| 62 | ERR_FAIL_COND(p_event.is_null()); |
| 63 | |
| 64 | Ref<InputEventMouseButton> mb = p_event; |
| 65 | |
| 66 | Popup *popup = get_popup(); |
| 67 | |
| 68 | if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { |
| 69 | Point2 pos = mb->get_position(); |
| 70 | real_t content_height = get_size().height - _get_tab_height(); |
| 71 | |
| 72 | Rect2 popup_rect = _get_tab_rect(); |
| 73 | popup_rect.position.x += is_layout_rtl() ? -theme_cache.menu_icon->get_width() : popup_rect.size.x; |
| 74 | popup_rect.position.y += tabs_position == POSITION_BOTTOM ? content_height : 0; |
| 75 | popup_rect.size.x = theme_cache.menu_icon->get_width(); |
| 76 | |
| 77 | // Click must be on tabs in the tab header area. |
| 78 | if (!tabs_visible || pos.y < popup_rect.position.y || pos.y >= popup_rect.position.y + popup_rect.size.y) { |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | // Handle menu button. |
| 83 | if (popup) { |
| 84 | if (popup_rect.has_point(pos)) { |
| 85 | emit_signal(SNAME("pre_popup_pressed")); |
| 86 | |
| 87 | Vector2 popup_pos = get_screen_position(); |
| 88 | popup_pos.x += popup_rect.position.x + (is_layout_rtl() ? 0 : popup_rect.size.x - popup->get_size().width); |
| 89 | popup_pos.y += popup_rect.position.y + popup_rect.size.y / 2.0; |
| 90 | if (tabs_position == POSITION_BOTTOM) { |
| 91 | popup_pos.y -= popup->get_size().height; |
| 92 | popup_pos.y -= theme_cache.menu_icon->get_height() / 2.0; |
| 93 | } else { |
| 94 | popup_pos.y += theme_cache.menu_icon->get_height() / 2.0; |
| 95 | } |
| 96 | |
| 97 | popup->set_position(popup_pos); |
| 98 | popup->popup(); |
| 99 | return; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | Ref<InputEventMouseMotion> mm = p_event; |
| 105 | |
| 106 | if (mm.is_valid()) { |
| 107 | Point2 pos = mm->get_position(); |
| 108 | real_t content_height = get_size().height - _get_tab_height(); |
| 109 | |
| 110 | Rect2 popup_rect = _get_tab_rect(); |
| 111 | popup_rect.position.x += is_layout_rtl() ? -theme_cache.menu_icon->get_width() : popup_rect.size.x; |
| 112 | popup_rect.position.y += tabs_position == POSITION_BOTTOM ? content_height : 0; |
| 113 | popup_rect.size.x = theme_cache.menu_icon->get_width(); |
| 114 | |
| 115 | // Mouse must be on tabs in the tab header area. |
| 116 | if (!tabs_visible || pos.y < popup_rect.position.y || pos.y >= popup_rect.position.y + popup_rect.size.y) { |
| 117 | if (menu_hovered) { |
| 118 | menu_hovered = false; |
| 119 | queue_redraw(); |
| 120 | } |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | if (popup) { |
| 125 | if (popup_rect.has_point(pos)) { |
| 126 | if (!menu_hovered) { |
| 127 | menu_hovered = true; |
| 128 | queue_redraw(); |
| 129 | return; |
| 130 | } |
| 131 | } else if (menu_hovered) { |
| 132 | menu_hovered = false; |
| 133 | queue_redraw(); |
| 134 | } |
| 135 | |
| 136 | if (menu_hovered) { |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | void TabContainer::_get_property_list(List<PropertyInfo> *p_list) const { |
| 144 | List<PropertyInfo> properties; |
| 145 | property_helper.get_property_list(&properties); |
| 146 | |
| 147 | for (PropertyInfo &info : properties) { |
| 148 | int index; |
| 149 | if (info.name.ends_with("title") && property_helper.is_property_valid(info.name, &index)) { |
| 150 | Control *tab_control = get_tab_control(index); |
| 151 | ERR_FAIL_NULL(tab_control); |
| 152 | if (get_tab_title(index) == tab_control->get_name()) { |
| 153 | // Don't store default title. |
| 154 | info.usage &= ~PROPERTY_USAGE_STORAGE; |
| 155 | } |
| 156 | } |
| 157 | p_list->push_back(info); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | bool TabContainer::_property_get_revert(const StringName &p_name, Variant &r_property) const { |
| 162 | const String sname = p_name; |
| 163 | |
| 164 | int index; |
| 165 | if (sname.ends_with("title") && property_helper.is_property_valid(sname, &index)) { |
| 166 | Control *tab_control = get_tab_control(index); |
| 167 | ERR_FAIL_NULL_V(tab_control, false); |
| 168 | r_property = String(tab_control->get_name()); |
| 169 | return true; |
| 170 | } |
| 171 | return property_helper.property_get_revert(p_name, r_property); |
| 172 | } |
| 173 | |
| 174 | void TabContainer::_notification(int p_what) { |
| 175 | switch (p_what) { |
| 176 | case NOTIFICATION_EXIT_TREE: |
| 177 | case NOTIFICATION_ACCESSIBILITY_INVALIDATE: { |
| 178 | tab_panels.clear(); |
| 179 | } break; |
| 180 | |
| 181 | case NOTIFICATION_ACCESSIBILITY_UPDATE: { |
| 182 | RID ae = get_accessibility_element(); |
| 183 | ERR_FAIL_COND(ae.is_null()); |
| 184 | |
| 185 | int tab_index = 0; |
| 186 | int tab_cur = tab_bar->get_current_tab(); |
| 187 | for (int i = 0; i < get_child_count(); i++) { |
| 188 | Node *child_node = get_child(i); |
| 189 | Window *child_wnd = Object::cast_to<Window>(child_node); |
| 190 | if (child_wnd && !child_wnd->is_embedded()) { |
| 191 | continue; |
| 192 | } |
| 193 | if (child_node->is_part_of_edited_scene()) { |
| 194 | continue; |
| 195 | } |
| 196 | Control *control = as_sortable_control(child_node, SortableVisibilityMode::IGNORE); |
| 197 | if (!control || control == tab_bar || children_removing.has(control)) { |
| 198 | DisplayServer::get_singleton()->accessibility_update_add_child(ae, child_node->get_accessibility_element()); |
| 199 | } else { |
| 200 | if (!tab_panels.has(child_node)) { |
| 201 | tab_panels[child_node] = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TAB_PANEL); |
| 202 | } |
| 203 | RID panel = tab_panels[child_node]; |
| 204 | RID tab = tab_bar->get_tab_accessibility_element(tab_index); |
| 205 | |
| 206 | DisplayServer::get_singleton()->accessibility_update_add_related_controls(tab, panel); |
| 207 | DisplayServer::get_singleton()->accessibility_update_add_related_labeled_by(panel, tab); |
| 208 | DisplayServer::get_singleton()->accessibility_update_set_flag(panel, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, tab_index != tab_cur); |
| 209 | DisplayServer::get_singleton()->accessibility_update_add_child(panel, child_node->get_accessibility_element()); |
| 210 | |
| 211 | tab_index++; |
| 212 | } |
| 213 | } |
| 214 | } break; |
| 215 | |
| 216 | case NOTIFICATION_ENTER_TREE: { |
| 217 | // If some nodes happen to be renamed outside the tree, the tab names need to be updated manually. |
| 218 | if (get_tab_count() > 0) { |
| 219 | _refresh_tab_names(); |
| 220 | } |
| 221 | |
| 222 | if (setup_current_tab >= -1) { |
| 223 | set_current_tab(setup_current_tab); |
| 224 | setup_current_tab = -2; |
| 225 | } |
| 226 | } break; |
| 227 | |
| 228 | case NOTIFICATION_READY: { |
| 229 | for (int i = 0; i < pending_tabs.size(); i++) { |
| 230 | const CachedTab &tab = pending_tabs[i]; |
| 231 | if (tab.has_title) { |
| 232 | set_tab_title(i, tab.title); |
| 233 | } |
| 234 | set_tab_icon(i, tab.icon); |
| 235 | set_tab_disabled(i, tab.disabled); |
| 236 | set_tab_hidden(i, tab.hidden); |
| 237 | } |
| 238 | pending_tabs.clear(); |
| 239 | |
| 240 | [[fallthrough]]; |
| 241 | } |
| 242 | |
| 243 | case NOTIFICATION_RESIZED: { |
| 244 | _update_margins(); |
| 245 | } break; |
| 246 | |
| 247 | case NOTIFICATION_DRAW: { |
| 248 | RID canvas = get_canvas_item(); |
| 249 | Size2 size = get_size(); |
| 250 | Rect2 tabbar_rect = _get_tab_rect(); |
| 251 | |
| 252 | // Draw only the tab area if the header is hidden. |
| 253 | if (!tabs_visible) { |
| 254 | theme_cache.panel_style->draw(canvas, Rect2(0, 0, size.width, size.height)); |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | int header_height = _get_tab_height(); |
| 259 | int header_voffset = int(tabs_position == POSITION_BOTTOM) * (size.height - header_height); |
| 260 | |
| 261 | // Draw background for the tabbar. |
| 262 | theme_cache.tabbar_style->draw(canvas, Rect2(0, header_voffset, size.width, header_height)); |
| 263 | // Draw the background for the tab's content. |
| 264 | theme_cache.panel_style->draw(canvas, Rect2(0, int(tabs_position == POSITION_TOP) * header_height, size.width, size.height - header_height)); |
| 265 | |
| 266 | // Draw the popup menu. |
| 267 | if (get_popup()) { |
| 268 | int x = is_layout_rtl() ? tabbar_rect.position.x - theme_cache.menu_icon->get_width() : tabbar_rect.position.x + tabbar_rect.size.x; |
| 269 | header_voffset += tabbar_rect.position.y; |
| 270 | |
| 271 | if (menu_hovered) { |
| 272 | 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)); |
| 273 | } else { |
| 274 | theme_cache.menu_icon->draw(get_canvas_item(), Point2(x, header_voffset + (tabbar_rect.size.y - theme_cache.menu_icon->get_height()) / 2)); |
| 275 | } |
| 276 | } |
| 277 | } break; |
| 278 | |
| 279 | case NOTIFICATION_VISIBILITY_CHANGED: { |
| 280 | if (!is_visible()) { |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | updating_visibility = true; |
| 285 | |
| 286 | // As the visibility change notification will be triggered for all children soon after, |
| 287 | // beat it to the punch and make sure that the correct node is the only one visible first. |
| 288 | // Otherwise, it can prevent a tab change done right before this container was made visible. |
| 289 | Vector<Control *> controls = _get_tab_controls(); |
| 290 | int current = setup_current_tab > -2 ? setup_current_tab : get_current_tab(); |
| 291 | for (int i = 0; i < controls.size(); i++) { |
| 292 | controls[i]->set_visible(i == current); |
| 293 | } |
| 294 | |
| 295 | updating_visibility = false; |
| 296 | } break; |
| 297 | |
| 298 | case NOTIFICATION_TRANSLATION_CHANGED: |
| 299 | case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: |
| 300 | case NOTIFICATION_THEME_CHANGED: { |
| 301 | theme_changing = true; |
| 302 | callable_mp(this, &TabContainer::_on_theme_changed).call_deferred(); // Wait until all changed theme. |
| 303 | } break; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | void TabContainer::_on_theme_changed() { |
| 308 | if (!theme_changing) { |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | tab_bar->begin_bulk_theme_override(); |
| 313 | |
| 314 | tab_bar->add_theme_style_override(SNAME("tab_unselected"), theme_cache.tab_unselected_style); |
| 315 | tab_bar->add_theme_style_override(SNAME("tab_hovered"), theme_cache.tab_hovered_style); |
| 316 | tab_bar->add_theme_style_override(SNAME("tab_selected"), theme_cache.tab_selected_style); |
| 317 | tab_bar->add_theme_style_override(SNAME("tab_disabled"), theme_cache.tab_disabled_style); |
| 318 | tab_bar->add_theme_style_override(SNAME("tab_focus"), theme_cache.tab_focus_style); |
| 319 | |
| 320 | tab_bar->add_theme_icon_override(SNAME("increment"), theme_cache.increment_icon); |
| 321 | tab_bar->add_theme_icon_override(SNAME("increment_highlight"), theme_cache.increment_hl_icon); |
| 322 | tab_bar->add_theme_icon_override(SNAME("decrement"), theme_cache.decrement_icon); |
| 323 | tab_bar->add_theme_icon_override(SNAME("decrement_highlight"), theme_cache.decrement_hl_icon); |
| 324 | tab_bar->add_theme_icon_override(SNAME("drop_mark"), theme_cache.drop_mark_icon); |
| 325 | tab_bar->add_theme_color_override(SNAME("drop_mark_color"), theme_cache.drop_mark_color); |
| 326 | |
| 327 | tab_bar->add_theme_color_override(SNAME("font_selected_color"), theme_cache.font_selected_color); |
| 328 | tab_bar->add_theme_color_override(SNAME("font_hovered_color"), theme_cache.font_hovered_color); |
| 329 | tab_bar->add_theme_color_override(SNAME("font_unselected_color"), theme_cache.font_unselected_color); |
| 330 | tab_bar->add_theme_color_override(SNAME("font_disabled_color"), theme_cache.font_disabled_color); |
| 331 | tab_bar->add_theme_color_override(SNAME("font_outline_color"), theme_cache.font_outline_color); |
| 332 | |
| 333 | tab_bar->add_theme_color_override(SNAME("icon_selected_color"), theme_cache.icon_selected_color); |
| 334 | tab_bar->add_theme_color_override(SNAME("icon_hovered_color"), theme_cache.icon_hovered_color); |
| 335 | tab_bar->add_theme_color_override(SNAME("icon_unselected_color"), theme_cache.icon_unselected_color); |
| 336 | tab_bar->add_theme_color_override(SNAME("icon_disabled_color"), theme_cache.icon_disabled_color); |
| 337 | |
| 338 | tab_bar->add_theme_font_override(SceneStringName(font), theme_cache.tab_font); |
| 339 | tab_bar->add_theme_font_size_override(SceneStringName(font_size), theme_cache.tab_font_size); |
| 340 | |
| 341 | tab_bar->add_theme_constant_override(SNAME("h_separation"), theme_cache.icon_separation); |
| 342 | tab_bar->add_theme_constant_override(SNAME("tab_separation"), theme_cache.tab_separation); |
| 343 | tab_bar->add_theme_constant_override(SNAME("icon_max_width"), theme_cache.icon_max_width); |
| 344 | tab_bar->add_theme_constant_override(SNAME("outline_size"), theme_cache.outline_size); |
| 345 | |
| 346 | tab_bar->end_bulk_theme_override(); |
| 347 | |
| 348 | _update_margins(); |
| 349 | if (get_tab_count() > 0) { |
| 350 | _repaint(); |
| 351 | } else { |
| 352 | update_minimum_size(); |
| 353 | } |
| 354 | queue_redraw(); |
| 355 | |
| 356 | theme_changing = false; |
| 357 | } |
| 358 | |
| 359 | void TabContainer::_repaint() { |
| 360 | Vector<Control *> controls = _get_tab_controls(); |
| 361 | int current = get_current_tab(); |
| 362 | |
| 363 | float top_margin = theme_cache.tabbar_style->get_margin(SIDE_TOP); |
| 364 | float bottom_margin = theme_cache.tabbar_style->get_margin(SIDE_BOTTOM); |
| 365 | |
| 366 | // Move the TabBar to the top or bottom. |
| 367 | // Don't change the left and right offsets since the TabBar will resize and may change tab offset. |
| 368 | if (tabs_position == POSITION_BOTTOM) { |
| 369 | tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 1.0, -bottom_margin); |
| 370 | tab_bar->set_anchor_and_offset(SIDE_TOP, 1.0, top_margin - _get_tab_height()); |
| 371 | } else { |
| 372 | tab_bar->set_anchor_and_offset(SIDE_TOP, 0.0, top_margin); |
| 373 | tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height() - bottom_margin); |
| 374 | } |
| 375 | |
| 376 | updating_visibility = true; |
| 377 | for (int i = 0; i < controls.size(); i++) { |
| 378 | Control *c = controls[i]; |
| 379 | |
| 380 | if (i == current) { |
| 381 | c->show(); |
| 382 | c->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT); |
| 383 | |
| 384 | if (tabs_visible) { |
| 385 | if (tabs_position == POSITION_BOTTOM) { |
| 386 | c->set_offset(SIDE_BOTTOM, -_get_tab_height()); |
| 387 | } else { |
| 388 | c->set_offset(SIDE_TOP, _get_tab_height()); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_TOP)); |
| 393 | c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_LEFT)); |
| 394 | c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - theme_cache.panel_style->get_margin(SIDE_RIGHT)); |
| 395 | c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - theme_cache.panel_style->get_margin(SIDE_BOTTOM)); |
| 396 | } else { |
| 397 | c->hide(); |
| 398 | } |
| 399 | } |
| 400 | updating_visibility = false; |
| 401 | |
| 402 | update_minimum_size(); |
| 403 | } |
| 404 | |
| 405 | void TabContainer::_update_margins() { |
| 406 | // Directly check for validity, to avoid errors when quitting. |
| 407 | bool has_popup = popup_obj_id.is_valid(); |
| 408 | |
| 409 | int left_margin = theme_cache.tabbar_style->get_margin(SIDE_LEFT); |
| 410 | int right_margin = theme_cache.tabbar_style->get_margin(SIDE_RIGHT); |
| 411 | |
| 412 | if (is_layout_rtl()) { |
| 413 | SWAP(left_margin, right_margin); |
| 414 | } |
| 415 | |
| 416 | if (has_popup) { |
| 417 | right_margin += theme_cache.menu_icon->get_width(); |
| 418 | } |
| 419 | |
| 420 | if (get_tab_count() == 0) { |
| 421 | tab_bar->set_offset(SIDE_LEFT, left_margin); |
| 422 | tab_bar->set_offset(SIDE_RIGHT, -right_margin); |
| 423 | return; |
| 424 | } |
| 425 | |
| 426 | switch (get_tab_alignment()) { |
| 427 | case TabBar::ALIGNMENT_LEFT: { |
| 428 | tab_bar->set_offset(SIDE_LEFT, left_margin + theme_cache.side_margin); |
| 429 | tab_bar->set_offset(SIDE_RIGHT, -right_margin); |
| 430 | } break; |
| 431 | |
| 432 | case TabBar::ALIGNMENT_CENTER: { |
| 433 | tab_bar->set_offset(SIDE_LEFT, left_margin); |
| 434 | tab_bar->set_offset(SIDE_RIGHT, -right_margin); |
| 435 | } break; |
| 436 | |
| 437 | case TabBar::ALIGNMENT_RIGHT: { |
| 438 | tab_bar->set_offset(SIDE_LEFT, left_margin); |
| 439 | |
| 440 | if (has_popup) { |
| 441 | tab_bar->set_offset(SIDE_RIGHT, -right_margin); |
| 442 | return; |
| 443 | } |
| 444 | |
| 445 | int first_tab_pos = tab_bar->get_tab_rect(0).position.x; |
| 446 | Rect2 last_tab_rect = tab_bar->get_tab_rect(get_tab_count() - 1); |
| 447 | int total_tabs_width = left_margin + right_margin + last_tab_rect.position.x - first_tab_pos + last_tab_rect.size.width; |
| 448 | |
| 449 | // Calculate if all the tabs would still fit if the margin was present. |
| 450 | if (get_clip_tabs() && (tab_bar->get_offset_buttons_visible() || (get_tab_count() > 1 && (total_tabs_width + theme_cache.side_margin) > get_size().width))) { |
| 451 | tab_bar->set_offset(SIDE_RIGHT, -right_margin); |
| 452 | } else { |
| 453 | tab_bar->set_offset(SIDE_RIGHT, -right_margin - theme_cache.side_margin); |
| 454 | } |
| 455 | } break; |
| 456 | |
| 457 | case TabBar::ALIGNMENT_MAX: |
| 458 | break; // Can't happen, but silences warning. |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | void TabContainer::_on_mouse_exited() { |
| 463 | if (menu_hovered) { |
| 464 | menu_hovered = false; |
| 465 | queue_redraw(); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | Vector<Control *> TabContainer::_get_tab_controls() const { |
| 470 | Vector<Control *> controls; |
| 471 | for (int i = 0; i < get_child_count(); i++) { |
| 472 | Control *control = as_sortable_control(get_child(i), SortableVisibilityMode::IGNORE); |
| 473 | if (!control || control == tab_bar || children_removing.has(control)) { |
| 474 | continue; |
| 475 | } |
| 476 | |
| 477 | controls.push_back(control); |
| 478 | } |
| 479 | |
| 480 | return controls; |
| 481 | } |
| 482 | |
| 483 | Variant TabContainer::_get_drag_data_fw(const Point2 &p_point, Control *p_from_control) { |
| 484 | if (!drag_to_rearrange_enabled) { |
| 485 | return Variant(); |
| 486 | } |
| 487 | return tab_bar->_handle_get_drag_data("tab_container_tab", p_point); |
| 488 | } |
| 489 | |
| 490 | bool TabContainer::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const { |
| 491 | if (!drag_to_rearrange_enabled) { |
| 492 | return false; |
| 493 | } |
| 494 | return tab_bar->_handle_can_drop_data("tab_container_tab", p_point, p_data); |
| 495 | } |
| 496 | |
| 497 | void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) { |
| 498 | if (!drag_to_rearrange_enabled) { |
| 499 | return; |
| 500 | } |
| 501 | 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)); |
| 502 | } |
| 503 | |
| 504 | void TabContainer::_drag_move_tab(int p_from_index, int p_to_index) { |
| 505 | move_child(get_tab_control(p_from_index), get_tab_control(p_to_index)->get_index(false)); |
| 506 | } |
| 507 | |
| 508 | void TabContainer::_drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index) { |
| 509 | Node *parent = p_from_tabbar->get_parent(); |
| 510 | if (!parent) { |
| 511 | return; |
| 512 | } |
| 513 | TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent); |
| 514 | if (!from_tab_container) { |
| 515 | return; |
| 516 | } |
| 517 | move_tab_from_tab_container(from_tab_container, p_from_index, p_to_index); |
| 518 | } |
| 519 | |
| 520 | void TabContainer::move_tab_from_tab_container(TabContainer *p_from, int p_from_index, int p_to_index) { |
| 521 | ERR_FAIL_NULL(p_from); |
| 522 | ERR_FAIL_INDEX(p_from_index, p_from->get_tab_count()); |
| 523 | ERR_FAIL_INDEX(p_to_index, get_tab_count() + 1); |
| 524 | |
| 525 | // Get the tab properties before they get erased by the child removal. |
| 526 | String tab_title = p_from->get_tab_title(p_from_index); |
| 527 | String tab_tooltip = p_from->get_tab_tooltip(p_from_index); |
| 528 | Ref<Texture2D> tab_icon = p_from->get_tab_icon(p_from_index); |
| 529 | Ref<Texture2D> tab_button_icon = p_from->get_tab_button_icon(p_from_index); |
| 530 | bool tab_disabled = p_from->is_tab_disabled(p_from_index); |
| 531 | bool tab_hidden = p_from->is_tab_hidden(p_from_index); |
| 532 | Variant tab_metadata = p_from->get_tab_metadata(p_from_index); |
| 533 | int tab_icon_max_width = p_from->get_tab_bar()->get_tab_icon_max_width(p_from_index); |
| 534 | |
| 535 | Control *moving_tabc = p_from->get_tab_control(p_from_index); |
| 536 | p_from->remove_child(moving_tabc); |
| 537 | add_child(moving_tabc, true); |
| 538 | |
| 539 | if (p_to_index < 0 || p_to_index > get_tab_count() - 1) { |
| 540 | p_to_index = get_tab_count() - 1; |
| 541 | } |
| 542 | move_child(moving_tabc, get_tab_control(p_to_index)->get_index(false)); |
| 543 | |
| 544 | set_tab_title(p_to_index, tab_title); |
| 545 | set_tab_tooltip(p_to_index, tab_tooltip); |
| 546 | set_tab_icon(p_to_index, tab_icon); |
| 547 | set_tab_button_icon(p_to_index, tab_button_icon); |
| 548 | set_tab_disabled(p_to_index, tab_disabled); |
| 549 | set_tab_hidden(p_to_index, tab_hidden); |
| 550 | set_tab_metadata(p_to_index, tab_metadata); |
| 551 | get_tab_bar()->set_tab_icon_max_width(p_to_index, tab_icon_max_width); |
| 552 | |
| 553 | if (!is_tab_disabled(p_to_index)) { |
| 554 | set_current_tab(p_to_index); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | void TabContainer::_on_tab_clicked(int p_tab) { |
| 559 | emit_signal(SNAME("tab_clicked"), p_tab); |
| 560 | } |
| 561 | |
| 562 | void TabContainer::_on_tab_hovered(int p_tab) { |
| 563 | emit_signal(SNAME("tab_hovered"), p_tab); |
| 564 | } |
| 565 | |
| 566 | void TabContainer::_on_tab_changed(int p_tab) { |
| 567 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 568 | queue_redraw(); |
| 569 | |
| 570 | emit_signal(SNAME("tab_changed"), p_tab); |
| 571 | } |
| 572 | |
| 573 | void TabContainer::_on_tab_selected(int p_tab) { |
| 574 | if (p_tab != get_previous_tab()) { |
| 575 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 576 | } |
| 577 | |
| 578 | emit_signal(SNAME("tab_selected"), p_tab); |
| 579 | } |
| 580 | |
| 581 | void TabContainer::_on_tab_button_pressed(int p_tab) { |
| 582 | emit_signal(SNAME("tab_button_pressed"), p_tab); |
| 583 | } |
| 584 | |
| 585 | void TabContainer::_on_active_tab_rearranged(int p_tab) { |
| 586 | emit_signal(SNAME("active_tab_rearranged"), p_tab); |
| 587 | } |
| 588 | |
| 589 | void TabContainer::_on_tab_visibility_changed(Control *p_child) { |
| 590 | if (updating_visibility) { |
| 591 | return; |
| 592 | } |
| 593 | int tab_index = get_tab_idx_from_control(p_child); |
| 594 | if (tab_index == -1) { |
| 595 | return; |
| 596 | } |
| 597 | // Only allow one tab to be visible. |
| 598 | bool made_visible = p_child->is_visible(); |
| 599 | updating_visibility = true; |
| 600 | |
| 601 | if (!made_visible && get_current_tab() == tab_index) { |
| 602 | if (get_deselect_enabled() || get_tab_count() == 0) { |
| 603 | // Deselect. |
| 604 | set_current_tab(-1); |
| 605 | } else if (get_tab_count() == 1) { |
| 606 | // Only tab, cannot deselect. |
| 607 | p_child->show(); |
| 608 | } else { |
| 609 | // Set a different tab to be the current tab. |
| 610 | bool selected = select_next_available(); |
| 611 | if (!selected) { |
| 612 | selected = select_previous_available(); |
| 613 | } |
| 614 | if (!selected) { |
| 615 | // No available tabs, deselect. |
| 616 | set_current_tab(-1); |
| 617 | } |
| 618 | } |
| 619 | } else if (made_visible && get_current_tab() != tab_index) { |
| 620 | set_current_tab(tab_index); |
| 621 | } |
| 622 | |
| 623 | updating_visibility = false; |
| 624 | } |
| 625 | |
| 626 | void TabContainer::_refresh_tab_indices() { |
| 627 | Vector<Control *> controls = _get_tab_controls(); |
| 628 | for (int i = 0; i < controls.size(); i++) { |
| 629 | controls[i]->set_meta("_tab_index", i); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | void TabContainer::_refresh_tab_names() { |
| 634 | Vector<Control *> controls = _get_tab_controls(); |
| 635 | for (int i = 0; i < controls.size(); i++) { |
| 636 | tab_bar->set_tab_title(i, controls[i]->get_meta("_tab_name", controls[i]->get_name())); |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | void TabContainer::add_child_notify(Node *p_child) { |
| 641 | Container::add_child_notify(p_child); |
| 642 | |
| 643 | if (p_child == tab_bar) { |
| 644 | return; |
| 645 | } |
| 646 | |
| 647 | Control *c = as_sortable_control(p_child, SortableVisibilityMode::IGNORE); |
| 648 | if (!c) { |
| 649 | return; |
| 650 | } |
| 651 | c->hide(); |
| 652 | |
| 653 | tab_bar->add_tab(p_child->get_meta("_tab_name", p_child->get_name())); |
| 654 | c->set_meta("_tab_index", tab_bar->get_tab_count() - 1); |
| 655 | |
| 656 | _update_margins(); |
| 657 | if (get_tab_count() == 1) { |
| 658 | queue_redraw(); |
| 659 | } |
| 660 | queue_accessibility_update(); |
| 661 | |
| 662 | p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); |
| 663 | p_child->connect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c)); |
| 664 | |
| 665 | // TabBar won't emit the "tab_changed" signal when not inside the tree. |
| 666 | if (!is_inside_tree()) { |
| 667 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 668 | } |
| 669 | notify_property_list_changed(); |
| 670 | } |
| 671 | |
| 672 | void TabContainer::move_child_notify(Node *p_child) { |
| 673 | Container::move_child_notify(p_child); |
| 674 | |
| 675 | if (p_child == tab_bar) { |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | Control *c = as_sortable_control(p_child, SortableVisibilityMode::IGNORE); |
| 680 | if (c) { |
| 681 | tab_bar->move_tab(c->get_meta("_tab_index"), get_tab_idx_from_control(c)); |
| 682 | } |
| 683 | |
| 684 | _refresh_tab_indices(); |
| 685 | queue_accessibility_update(); |
| 686 | notify_property_list_changed(); |
| 687 | } |
| 688 | |
| 689 | void TabContainer::remove_child_notify(Node *p_child) { |
| 690 | Container::remove_child_notify(p_child); |
| 691 | |
| 692 | if (tab_panels.has(p_child)) { |
| 693 | DisplayServer::get_singleton()->accessibility_free_element(tab_panels[p_child]); |
| 694 | tab_panels.erase(p_child); |
| 695 | } |
| 696 | |
| 697 | if (p_child == tab_bar) { |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | Control *c = as_sortable_control(p_child, SortableVisibilityMode::IGNORE); |
| 702 | if (!c) { |
| 703 | return; |
| 704 | } |
| 705 | |
| 706 | int idx = get_tab_idx_from_control(c); |
| 707 | |
| 708 | // As the child hasn't been removed yet, keep track of it so when the "tab_changed" signal is fired it can be ignored. |
| 709 | children_removing.push_back(c); |
| 710 | |
| 711 | tab_bar->remove_tab(idx); |
| 712 | _refresh_tab_indices(); |
| 713 | |
| 714 | children_removing.erase(c); |
| 715 | |
| 716 | _update_margins(); |
| 717 | if (get_tab_count() == 0) { |
| 718 | queue_redraw(); |
| 719 | } |
| 720 | queue_accessibility_update(); |
| 721 | |
| 722 | p_child->remove_meta("_tab_index"); |
| 723 | p_child->remove_meta("_tab_name"); |
| 724 | p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); |
| 725 | p_child->disconnect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed)); |
| 726 | |
| 727 | // TabBar won't emit the "tab_changed" signal when not inside the tree. |
| 728 | if (!is_inside_tree()) { |
| 729 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 730 | } |
| 731 | notify_property_list_changed(); |
| 732 | } |
| 733 | |
| 734 | TabBar *TabContainer::get_tab_bar() const { |
| 735 | return tab_bar; |
| 736 | } |
| 737 | |
| 738 | int TabContainer::get_tab_count() const { |
| 739 | return tab_bar->get_tab_count(); |
| 740 | } |
| 741 | |
| 742 | void TabContainer::set_current_tab(int p_current) { |
| 743 | if (!is_inside_tree()) { |
| 744 | setup_current_tab = p_current; |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | tab_bar->set_current_tab(p_current); |
| 749 | } |
| 750 | |
| 751 | int TabContainer::get_current_tab() const { |
| 752 | return tab_bar->get_current_tab(); |
| 753 | } |
| 754 | |
| 755 | int TabContainer::get_previous_tab() const { |
| 756 | return tab_bar->get_previous_tab(); |
| 757 | } |
| 758 | |
| 759 | bool TabContainer::select_previous_available() { |
| 760 | return tab_bar->select_previous_available(); |
| 761 | } |
| 762 | |
| 763 | bool TabContainer::select_next_available() { |
| 764 | return tab_bar->select_next_available(); |
| 765 | } |
| 766 | |
| 767 | void TabContainer::set_deselect_enabled(bool p_enabled) { |
| 768 | tab_bar->set_deselect_enabled(p_enabled); |
| 769 | } |
| 770 | |
| 771 | bool TabContainer::get_deselect_enabled() const { |
| 772 | return tab_bar->get_deselect_enabled(); |
| 773 | } |
| 774 | |
| 775 | Control *TabContainer::get_tab_control(int p_idx) const { |
| 776 | Vector<Control *> controls = _get_tab_controls(); |
| 777 | if (p_idx >= 0 && p_idx < controls.size()) { |
| 778 | return controls[p_idx]; |
| 779 | } else { |
| 780 | return nullptr; |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | Control *TabContainer::get_current_tab_control() const { |
| 785 | return get_tab_control(tab_bar->get_current_tab()); |
| 786 | } |
| 787 | |
| 788 | int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const { |
| 789 | return tab_bar->get_tab_idx_at_point(p_point); |
| 790 | } |
| 791 | |
| 792 | int TabContainer::get_tab_idx_from_control(Control *p_child) const { |
| 793 | ERR_FAIL_NULL_V(p_child, -1); |
| 794 | ERR_FAIL_COND_V(p_child->get_parent() != this, -1); |
| 795 | |
| 796 | Vector<Control *> controls = _get_tab_controls(); |
| 797 | for (int i = 0; i < controls.size(); i++) { |
| 798 | if (controls[i] == p_child) { |
| 799 | return i; |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | return -1; |
| 804 | } |
| 805 | |
| 806 | void TabContainer::set_tab_alignment(TabBar::AlignmentMode p_alignment) { |
| 807 | if (tab_bar->get_tab_alignment() == p_alignment) { |
| 808 | return; |
| 809 | } |
| 810 | |
| 811 | tab_bar->set_tab_alignment(p_alignment); |
| 812 | _update_margins(); |
| 813 | } |
| 814 | |
| 815 | TabBar::AlignmentMode TabContainer::get_tab_alignment() const { |
| 816 | return tab_bar->get_tab_alignment(); |
| 817 | } |
| 818 | |
| 819 | void TabContainer::set_tabs_position(TabPosition p_tabs_position) { |
| 820 | ERR_FAIL_INDEX(p_tabs_position, POSITION_MAX); |
| 821 | if (p_tabs_position == tabs_position) { |
| 822 | return; |
| 823 | } |
| 824 | tabs_position = p_tabs_position; |
| 825 | |
| 826 | tab_bar->set_tab_style_v_flip(tabs_position == POSITION_BOTTOM); |
| 827 | |
| 828 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 829 | queue_redraw(); |
| 830 | } |
| 831 | |
| 832 | TabContainer::TabPosition TabContainer::get_tabs_position() const { |
| 833 | return tabs_position; |
| 834 | } |
| 835 | |
| 836 | void TabContainer::set_tab_focus_mode(Control::FocusMode p_focus_mode) { |
| 837 | tab_bar->set_focus_mode(p_focus_mode); |
| 838 | } |
| 839 | |
| 840 | Control::FocusMode TabContainer::get_tab_focus_mode() const { |
| 841 | return tab_bar->get_focus_mode(); |
| 842 | } |
| 843 | |
| 844 | void TabContainer::set_clip_tabs(bool p_clip_tabs) { |
| 845 | tab_bar->set_clip_tabs(p_clip_tabs); |
| 846 | } |
| 847 | |
| 848 | bool TabContainer::get_clip_tabs() const { |
| 849 | return tab_bar->get_clip_tabs(); |
| 850 | } |
| 851 | |
| 852 | void TabContainer::set_tabs_visible(bool p_visible) { |
| 853 | if (p_visible == tabs_visible) { |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | tabs_visible = p_visible; |
| 858 | tab_bar->set_visible(tabs_visible); |
| 859 | |
| 860 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 861 | queue_redraw(); |
| 862 | } |
| 863 | |
| 864 | bool TabContainer::are_tabs_visible() const { |
| 865 | return tabs_visible; |
| 866 | } |
| 867 | |
| 868 | void TabContainer::set_all_tabs_in_front(bool p_in_front) { |
| 869 | if (p_in_front == all_tabs_in_front) { |
| 870 | return; |
| 871 | } |
| 872 | |
| 873 | all_tabs_in_front = p_in_front; |
| 874 | |
| 875 | remove_child(tab_bar); |
| 876 | add_child(tab_bar, false, all_tabs_in_front ? INTERNAL_MODE_FRONT : INTERNAL_MODE_BACK); |
| 877 | } |
| 878 | |
| 879 | bool TabContainer::is_all_tabs_in_front() const { |
| 880 | return all_tabs_in_front; |
| 881 | } |
| 882 | |
| 883 | void TabContainer::set_tab_title(int p_tab, const String &p_title) { |
| 884 | Control *child = get_tab_control(p_tab); |
| 885 | if (!child && !is_ready()) { |
| 886 | CachedTab &tab = get_pending_tab(p_tab); |
| 887 | tab.title = p_title; |
| 888 | tab.has_title = true; |
| 889 | return; |
| 890 | } |
| 891 | ERR_FAIL_NULL(child); |
| 892 | |
| 893 | if (tab_bar->get_tab_title(p_tab) == p_title) { |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | tab_bar->set_tab_title(p_tab, p_title); |
| 898 | |
| 899 | if (p_title == child->get_name()) { |
| 900 | child->remove_meta("_tab_name"); |
| 901 | } else { |
| 902 | child->set_meta("_tab_name", p_title); |
| 903 | } |
| 904 | |
| 905 | _repaint(); |
| 906 | queue_redraw(); |
| 907 | } |
| 908 | |
| 909 | String TabContainer::get_tab_title(int p_tab) const { |
| 910 | return tab_bar->get_tab_title(p_tab); |
| 911 | } |
| 912 | |
| 913 | void TabContainer::set_tab_tooltip(int p_tab, const String &p_tooltip) { |
| 914 | tab_bar->set_tab_tooltip(p_tab, p_tooltip); |
| 915 | } |
| 916 | |
| 917 | String TabContainer::get_tab_tooltip(int p_tab) const { |
| 918 | return tab_bar->get_tab_tooltip(p_tab); |
| 919 | } |
| 920 | |
| 921 | void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) { |
| 922 | Control *child = get_tab_control(p_tab); |
| 923 | if (!child && !is_ready()) { |
| 924 | get_pending_tab(p_tab).icon = p_icon; |
| 925 | return; |
| 926 | } |
| 927 | |
| 928 | if (tab_bar->get_tab_icon(p_tab) == p_icon) { |
| 929 | return; |
| 930 | } |
| 931 | |
| 932 | tab_bar->set_tab_icon(p_tab, p_icon); |
| 933 | |
| 934 | _update_margins(); |
| 935 | _repaint(); |
| 936 | queue_redraw(); |
| 937 | } |
| 938 | |
| 939 | Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const { |
| 940 | return tab_bar->get_tab_icon(p_tab); |
| 941 | } |
| 942 | |
| 943 | void TabContainer::set_tab_icon_max_width(int p_tab, int p_width) { |
| 944 | if (tab_bar->get_tab_icon_max_width(p_tab) == p_width) { |
| 945 | return; |
| 946 | } |
| 947 | |
| 948 | tab_bar->set_tab_icon_max_width(p_tab, p_width); |
| 949 | |
| 950 | _update_margins(); |
| 951 | _repaint(); |
| 952 | queue_redraw(); |
| 953 | } |
| 954 | |
| 955 | int TabContainer::get_tab_icon_max_width(int p_tab) const { |
| 956 | return tab_bar->get_tab_icon_max_width(p_tab); |
| 957 | } |
| 958 | |
| 959 | void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) { |
| 960 | Control *child = get_tab_control(p_tab); |
| 961 | if (!child && !is_ready()) { |
| 962 | get_pending_tab(p_tab).disabled = p_disabled; |
| 963 | return; |
| 964 | } |
| 965 | |
| 966 | if (tab_bar->is_tab_disabled(p_tab) == p_disabled) { |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | tab_bar->set_tab_disabled(p_tab, p_disabled); |
| 971 | |
| 972 | _update_margins(); |
| 973 | if (!get_clip_tabs()) { |
| 974 | update_minimum_size(); |
| 975 | } |
| 976 | } |
| 977 | |
| 978 | bool TabContainer::is_tab_disabled(int p_tab) const { |
| 979 | return tab_bar->is_tab_disabled(p_tab); |
| 980 | } |
| 981 | |
| 982 | void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) { |
| 983 | Control *child = get_tab_control(p_tab); |
| 984 | if (!child && !is_ready()) { |
| 985 | get_pending_tab(p_tab).hidden = p_hidden; |
| 986 | return; |
| 987 | } |
| 988 | ERR_FAIL_NULL(child); |
| 989 | |
| 990 | if (tab_bar->is_tab_hidden(p_tab) == p_hidden) { |
| 991 | return; |
| 992 | } |
| 993 | |
| 994 | tab_bar->set_tab_hidden(p_tab, p_hidden); |
| 995 | child->hide(); |
| 996 | |
| 997 | _update_margins(); |
| 998 | if (!get_clip_tabs()) { |
| 999 | update_minimum_size(); |
| 1000 | } |
| 1001 | callable_mp(this, &TabContainer::_repaint).call_deferred(); |
| 1002 | } |
| 1003 | |
| 1004 | bool TabContainer::is_tab_hidden(int p_tab) const { |
| 1005 | return tab_bar->is_tab_hidden(p_tab); |
| 1006 | } |
| 1007 | |
| 1008 | void TabContainer::set_tab_metadata(int p_tab, const Variant &p_metadata) { |
| 1009 | tab_bar->set_tab_metadata(p_tab, p_metadata); |
| 1010 | } |
| 1011 | |
| 1012 | Variant TabContainer::get_tab_metadata(int p_tab) const { |
| 1013 | return tab_bar->get_tab_metadata(p_tab); |
| 1014 | } |
| 1015 | |
| 1016 | void TabContainer::set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon) { |
| 1017 | tab_bar->set_tab_button_icon(p_tab, p_icon); |
| 1018 | |
| 1019 | _update_margins(); |
| 1020 | _repaint(); |
| 1021 | } |
| 1022 | |
| 1023 | Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const { |
| 1024 | return tab_bar->get_tab_button_icon(p_tab); |
| 1025 | } |
| 1026 | |
| 1027 | Size2 TabContainer::get_minimum_size() const { |
| 1028 | Size2 ms; |
| 1029 | |
| 1030 | if (tabs_visible) { |
| 1031 | ms = tab_bar->get_minimum_size(); |
| 1032 | ms.width += theme_cache.tabbar_style->get_margin(SIDE_LEFT) + theme_cache.tabbar_style->get_margin(SIDE_RIGHT); |
| 1033 | ms.height += theme_cache.tabbar_style->get_margin(SIDE_TOP) + theme_cache.tabbar_style->get_margin(SIDE_BOTTOM); |
| 1034 | |
| 1035 | if (get_popup()) { |
| 1036 | ms.width += theme_cache.menu_icon->get_width(); |
| 1037 | } |
| 1038 | |
| 1039 | if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER && |
| 1040 | (get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) { |
| 1041 | ms.width += theme_cache.side_margin; |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | Vector<Control *> controls = _get_tab_controls(); |
| 1046 | Size2 largest_child_min_size; |
| 1047 | for (int i = 0; i < controls.size(); i++) { |
| 1048 | Control *c = controls[i]; |
| 1049 | |
| 1050 | if (!c->is_visible() && !use_hidden_tabs_for_min_size) { |
| 1051 | continue; |
| 1052 | } |
| 1053 | |
| 1054 | Size2 cms = c->get_combined_minimum_size(); |
| 1055 | largest_child_min_size = largest_child_min_size.max(cms); |
| 1056 | } |
| 1057 | ms.height += largest_child_min_size.height; |
| 1058 | |
| 1059 | Size2 panel_ms = theme_cache.panel_style->get_minimum_size(); |
| 1060 | |
| 1061 | ms.width = MAX(ms.width, largest_child_min_size.width + panel_ms.width); |
| 1062 | ms.height += panel_ms.height; |
| 1063 | |
| 1064 | return ms; |
| 1065 | } |
| 1066 | |
| 1067 | void TabContainer::set_popup(Node *p_popup) { |
| 1068 | bool had_popup = get_popup(); |
| 1069 | |
| 1070 | Popup *popup = Object::cast_to<Popup>(p_popup); |
| 1071 | ObjectID popup_id = popup ? popup->get_instance_id() : ObjectID(); |
| 1072 | if (popup_obj_id == popup_id) { |
| 1073 | return; |
| 1074 | } |
| 1075 | popup_obj_id = popup_id; |
| 1076 | |
| 1077 | if (had_popup != bool(popup)) { |
| 1078 | queue_redraw(); |
| 1079 | _update_margins(); |
| 1080 | update_minimum_size(); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | Popup *TabContainer::get_popup() const { |
| 1085 | if (popup_obj_id.is_valid()) { |
| 1086 | Popup *popup = ObjectDB::get_instance<Popup>(popup_obj_id); |
| 1087 | if (popup) { |
| 1088 | return popup; |
| 1089 | } else { |
| 1090 | #ifdef DEBUG_ENABLED |
| 1091 | ERR_PRINT("Popup assigned to TabContainer is gone!"); |
| 1092 | #endif |
| 1093 | popup_obj_id = ObjectID(); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | return nullptr; |
| 1098 | } |
| 1099 | |
| 1100 | void TabContainer::set_switch_on_drag_hover(bool p_enabled) { |
| 1101 | tab_bar->set_switch_on_drag_hover(p_enabled); |
| 1102 | } |
| 1103 | |
| 1104 | bool TabContainer::get_switch_on_drag_hover() const { |
| 1105 | return tab_bar->get_switch_on_drag_hover(); |
| 1106 | } |
| 1107 | |
| 1108 | void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) { |
| 1109 | drag_to_rearrange_enabled = p_enabled; |
| 1110 | } |
| 1111 | |
| 1112 | bool TabContainer::get_drag_to_rearrange_enabled() const { |
| 1113 | return drag_to_rearrange_enabled; |
| 1114 | } |
| 1115 | |
| 1116 | void TabContainer::set_tabs_rearrange_group(int p_group_id) { |
| 1117 | tab_bar->set_tabs_rearrange_group(p_group_id); |
| 1118 | } |
| 1119 | |
| 1120 | int TabContainer::get_tabs_rearrange_group() const { |
| 1121 | return tab_bar->get_tabs_rearrange_group(); |
| 1122 | } |
| 1123 | |
| 1124 | void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) { |
| 1125 | if (use_hidden_tabs_for_min_size == p_use_hidden_tabs) { |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| 1129 | use_hidden_tabs_for_min_size = p_use_hidden_tabs; |
| 1130 | update_minimum_size(); |
| 1131 | } |
| 1132 | |
| 1133 | bool TabContainer::get_use_hidden_tabs_for_min_size() const { |
| 1134 | return use_hidden_tabs_for_min_size; |
| 1135 | } |
| 1136 | |
| 1137 | Vector<int> TabContainer::get_allowed_size_flags_horizontal() const { |
| 1138 | return Vector<int>(); |
| 1139 | } |
| 1140 | |
| 1141 | Vector<int> TabContainer::get_allowed_size_flags_vertical() const { |
| 1142 | return Vector<int>(); |
| 1143 | } |
| 1144 | |
| 1145 | void TabContainer::_bind_methods() { |
| 1146 | ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count); |
| 1147 | ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab); |
| 1148 | ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab); |
| 1149 | ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab); |
| 1150 | ClassDB::bind_method(D_METHOD("select_previous_available"), &TabContainer::select_previous_available); |
| 1151 | ClassDB::bind_method(D_METHOD("select_next_available"), &TabContainer::select_next_available); |
| 1152 | ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control); |
| 1153 | ClassDB::bind_method(D_METHOD("get_tab_bar"), &TabContainer::get_tab_bar); |
| 1154 | ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control); |
| 1155 | ClassDB::bind_method(D_METHOD("set_tab_alignment", "alignment"), &TabContainer::set_tab_alignment); |
| 1156 | ClassDB::bind_method(D_METHOD("get_tab_alignment"), &TabContainer::get_tab_alignment); |
| 1157 | ClassDB::bind_method(D_METHOD("set_tabs_position", "tabs_position"), &TabContainer::set_tabs_position); |
| 1158 | ClassDB::bind_method(D_METHOD("get_tabs_position"), &TabContainer::get_tabs_position); |
| 1159 | ClassDB::bind_method(D_METHOD("set_clip_tabs", "clip_tabs"), &TabContainer::set_clip_tabs); |
| 1160 | ClassDB::bind_method(D_METHOD("get_clip_tabs"), &TabContainer::get_clip_tabs); |
| 1161 | ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible); |
| 1162 | ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible); |
| 1163 | ClassDB::bind_method(D_METHOD("set_all_tabs_in_front", "is_front"), &TabContainer::set_all_tabs_in_front); |
| 1164 | ClassDB::bind_method(D_METHOD("is_all_tabs_in_front"), &TabContainer::is_all_tabs_in_front); |
| 1165 | |
| 1166 | ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title); |
| 1167 | ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title); |
| 1168 | ClassDB::bind_method(D_METHOD("set_tab_tooltip", "tab_idx", "tooltip"), &TabContainer::set_tab_tooltip); |
| 1169 | ClassDB::bind_method(D_METHOD("get_tab_tooltip", "tab_idx"), &TabContainer::get_tab_tooltip); |
| 1170 | ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon); |
| 1171 | ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon); |
| 1172 | ClassDB::bind_method(D_METHOD("set_tab_icon_max_width", "tab_idx", "width"), &TabContainer::set_tab_icon_max_width); |
| 1173 | ClassDB::bind_method(D_METHOD("get_tab_icon_max_width", "tab_idx"), &TabContainer::get_tab_icon_max_width); |
| 1174 | ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled); |
| 1175 | ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled); |
| 1176 | ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden); |
| 1177 | ClassDB::bind_method(D_METHOD("is_tab_hidden", "tab_idx"), &TabContainer::is_tab_hidden); |
| 1178 | ClassDB::bind_method(D_METHOD("set_tab_metadata", "tab_idx", "metadata"), &TabContainer::set_tab_metadata); |
| 1179 | ClassDB::bind_method(D_METHOD("get_tab_metadata", "tab_idx"), &TabContainer::get_tab_metadata); |
| 1180 | ClassDB::bind_method(D_METHOD("set_tab_button_icon", "tab_idx", "icon"), &TabContainer::set_tab_button_icon); |
| 1181 | ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &TabContainer::get_tab_button_icon); |
| 1182 | |
| 1183 | ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point); |
| 1184 | ClassDB::bind_method(D_METHOD("get_tab_idx_from_control", "control"), &TabContainer::get_tab_idx_from_control); |
| 1185 | ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup); |
| 1186 | ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup); |
| 1187 | ClassDB::bind_method(D_METHOD("set_switch_on_drag_hover", "enabled"), &TabContainer::set_switch_on_drag_hover); |
| 1188 | ClassDB::bind_method(D_METHOD("get_switch_on_drag_hover"), &TabContainer::get_switch_on_drag_hover); |
| 1189 | ClassDB::bind_method(D_METHOD("set_drag_to_rearrange_enabled", "enabled"), &TabContainer::set_drag_to_rearrange_enabled); |
| 1190 | ClassDB::bind_method(D_METHOD("get_drag_to_rearrange_enabled"), &TabContainer::get_drag_to_rearrange_enabled); |
| 1191 | ClassDB::bind_method(D_METHOD("set_tabs_rearrange_group", "group_id"), &TabContainer::set_tabs_rearrange_group); |
| 1192 | ClassDB::bind_method(D_METHOD("get_tabs_rearrange_group"), &TabContainer::get_tabs_rearrange_group); |
| 1193 | ClassDB::bind_method(D_METHOD("set_use_hidden_tabs_for_min_size", "enabled"), &TabContainer::set_use_hidden_tabs_for_min_size); |
| 1194 | ClassDB::bind_method(D_METHOD("get_use_hidden_tabs_for_min_size"), &TabContainer::get_use_hidden_tabs_for_min_size); |
| 1195 | ClassDB::bind_method(D_METHOD("set_tab_focus_mode", "focus_mode"), &TabContainer::set_tab_focus_mode); |
| 1196 | ClassDB::bind_method(D_METHOD("get_tab_focus_mode"), &TabContainer::get_tab_focus_mode); |
| 1197 | ClassDB::bind_method(D_METHOD("set_deselect_enabled", "enabled"), &TabContainer::set_deselect_enabled); |
| 1198 | ClassDB::bind_method(D_METHOD("get_deselect_enabled"), &TabContainer::get_deselect_enabled); |
| 1199 | |
| 1200 | ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to"))); |
| 1201 | ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); |
| 1202 | ADD_SIGNAL(MethodInfo("tab_clicked", PropertyInfo(Variant::INT, "tab"))); |
| 1203 | ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab"))); |
| 1204 | ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab"))); |
| 1205 | ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab"))); |
| 1206 | ADD_SIGNAL(MethodInfo("pre_popup_pressed")); |
| 1207 | |
| 1208 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment"); |
| 1209 | ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab"); |
| 1210 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_position", PROPERTY_HINT_ENUM, "Top,Bottom"), "set_tabs_position", "get_tabs_position"); |
| 1211 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs"); |
| 1212 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible"); |
| 1213 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front"); |
| 1214 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "switch_on_drag_hover"), "set_switch_on_drag_hover", "get_switch_on_drag_hover"); |
| 1215 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled"); |
| 1216 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_rearrange_group"), "set_tabs_rearrange_group", "get_tabs_rearrange_group"); |
| 1217 | 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"); |
| 1218 | ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_tab_focus_mode", "get_tab_focus_mode"); |
| 1219 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled"); |
| 1220 | |
| 1221 | ADD_CLASS_DEPENDENCY("TabBar"); |
| 1222 | |
| 1223 | BIND_ENUM_CONSTANT(POSITION_TOP); |
| 1224 | BIND_ENUM_CONSTANT(POSITION_BOTTOM); |
| 1225 | BIND_ENUM_CONSTANT(POSITION_MAX); |
| 1226 | |
| 1227 | BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, side_margin); |
| 1228 | BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, tab_separation); |
| 1229 | |
| 1230 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, panel_style, "panel"); |
| 1231 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tabbar_style, "tabbar_background"); |
| 1232 | |
| 1233 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_icon, "menu"); |
| 1234 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_hl_icon, "menu_highlight"); |
| 1235 | |
| 1236 | // TabBar overrides. |
| 1237 | BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_separation); |
| 1238 | BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_max_width); |
| 1239 | |
| 1240 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_unselected_style, "tab_unselected"); |
| 1241 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_hovered_style, "tab_hovered"); |
| 1242 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_selected_style, "tab_selected"); |
| 1243 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_disabled_style, "tab_disabled"); |
| 1244 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_focus_style, "tab_focus"); |
| 1245 | |
| 1246 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_icon, "increment"); |
| 1247 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_hl_icon, "increment_highlight"); |
| 1248 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_icon, "decrement"); |
| 1249 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_hl_icon, "decrement_highlight"); |
| 1250 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, drop_mark_icon, "drop_mark"); |
| 1251 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, drop_mark_color); |
| 1252 | |
| 1253 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_selected_color); |
| 1254 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_hovered_color); |
| 1255 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_unselected_color); |
| 1256 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_disabled_color); |
| 1257 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_outline_color); |
| 1258 | |
| 1259 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, icon_selected_color); |
| 1260 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, icon_hovered_color); |
| 1261 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, icon_unselected_color); |
| 1262 | BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, icon_disabled_color); |
| 1263 | |
| 1264 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT, TabContainer, tab_font, "font"); |
| 1265 | BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT_SIZE, TabContainer, tab_font_size, "font_size"); |
| 1266 | BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, outline_size); |
| 1267 | |
| 1268 | CachedTab defaults; |
| 1269 | |
| 1270 | base_property_helper.set_prefix("tab_"); |
| 1271 | base_property_helper.set_array_length_getter(&TabContainer::get_tab_count); |
| 1272 | base_property_helper.register_property(PropertyInfo(Variant::STRING, "title"), defaults.title, &TabContainer::set_tab_title, &TabContainer::get_tab_title); |
| 1273 | base_property_helper.register_property(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), defaults.icon, &TabContainer::set_tab_icon, &TabContainer::get_tab_icon); |
| 1274 | base_property_helper.register_property(PropertyInfo(Variant::BOOL, "disabled"), defaults.disabled, &TabContainer::set_tab_disabled, &TabContainer::is_tab_disabled); |
| 1275 | base_property_helper.register_property(PropertyInfo(Variant::BOOL, "hidden"), defaults.hidden, &TabContainer::set_tab_hidden, &TabContainer::is_tab_hidden); |
| 1276 | PropertyListHelper::register_base_helper(&base_property_helper); |
| 1277 | } |
| 1278 | |
| 1279 | TabContainer::TabContainer() { |
| 1280 | tab_bar = memnew(TabBar); |
| 1281 | SET_DRAG_FORWARDING_GCDU(tab_bar, TabContainer); |
| 1282 | add_child(tab_bar, false, INTERNAL_MODE_FRONT); |
| 1283 | tab_bar->set_use_parent_material(true); |
| 1284 | tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE); |
| 1285 | tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed)); |
| 1286 | tab_bar->connect("tab_clicked", callable_mp(this, &TabContainer::_on_tab_clicked)); |
| 1287 | tab_bar->connect("tab_hovered", callable_mp(this, &TabContainer::_on_tab_hovered)); |
| 1288 | tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected)); |
| 1289 | tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed)); |
| 1290 | tab_bar->connect("active_tab_rearranged", callable_mp(this, &TabContainer::_on_active_tab_rearranged)); |
| 1291 | connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_on_mouse_exited)); |
| 1292 | |
| 1293 | property_helper.setup_for_instance(base_property_helper, this); |
| 1294 | property_helper.enable_out_of_bounds_assign(); |
| 1295 | } |