| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  tab_container.cpp                                                    */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2022-01-03 21:27:34 +01:00
										 |  |  | /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md).   */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* 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-09 22:10:30 -03:00
										 |  |  | #include "tab_container.h"
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | #include "scene/gui/box_container.h"
 | 
					
						
							|  |  |  | #include "scene/gui/label.h"
 | 
					
						
							|  |  |  | #include "scene/gui/texture_rect.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | int TabContainer::_get_top_margin() const { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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 11:37:10 -03:00
										 |  |  | 	return height; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-22 12:37:22 -03: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 12:38:03 -03:00
										 |  |  | 	Ref<InputEventMouseButton> mb = p_event; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 19:14:20 +02:00
										 |  |  | 	Popup *popup = get_popup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-13 16:31:57 -05:00
										 |  |  | 	if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { | 
					
						
							| 
									
										
										
										
											2021-09-25 14:46:45 +05:45
										 |  |  | 		Point2 pos = mb->get_position(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 		Size2 size = get_size(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 		// Click must be on tabs in the tab header area.
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		if (pos.y > _get_top_margin()) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 		// Handle menu button.
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); | 
					
						
							| 
									
										
										
										
											2020-06-24 19:14:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		if (is_layout_rtl()) { | 
					
						
							|  |  |  | 			if (popup && pos.x < menu->get_width()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				emit_signal(SNAME("pre_popup_pressed")); | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 				Vector2 popup_pos = get_screen_position(); | 
					
						
							|  |  |  | 				popup_pos.y += menu->get_height(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 				popup->set_position(popup_pos); | 
					
						
							|  |  |  | 				popup->popup(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (popup && pos.x > size.width - menu->get_width()) { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 				emit_signal(SNAME("pre_popup_pressed")); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				Vector2 popup_pos = get_screen_position(); | 
					
						
							|  |  |  | 				popup_pos.x += size.width - popup->get_size().width; | 
					
						
							|  |  |  | 				popup_pos.y += menu->get_height(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				popup->set_position(popup_pos); | 
					
						
							|  |  |  | 				popup->popup(); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Ref<InputEventMouseMotion> mm = p_event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (mm.is_valid()) { | 
					
						
							| 
									
										
										
										
											2021-09-25 14:46:45 +05:45
										 |  |  | 		Point2 pos = mm->get_position(); | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 		Size2 size = get_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Mouse must be on tabs in the tab header area.
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		if (pos.y > _get_top_margin()) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			if (menu_hovered) { | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 				menu_hovered = false; | 
					
						
							|  |  |  | 				update(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 		Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 		if (popup) { | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 			if (is_layout_rtl()) { | 
					
						
							|  |  |  | 				if (pos.x <= menu->get_width()) { | 
					
						
							|  |  |  | 					if (!menu_hovered) { | 
					
						
							|  |  |  | 						menu_hovered = true; | 
					
						
							|  |  |  | 						update(); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else if (menu_hovered) { | 
					
						
							|  |  |  | 					menu_hovered = false; | 
					
						
							|  |  |  | 					update(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				if (pos.x >= size.width - menu->get_width()) { | 
					
						
							|  |  |  | 					if (!menu_hovered) { | 
					
						
							|  |  |  | 						menu_hovered = true; | 
					
						
							|  |  |  | 						update(); | 
					
						
							|  |  |  | 						return; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else if (menu_hovered) { | 
					
						
							|  |  |  | 					menu_hovered = false; | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 					update(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (menu_hovered) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TabContainer::_notification(int p_what) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 	switch (p_what) { | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03: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(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 		case NOTIFICATION_READY: | 
					
						
							| 
									
										
										
										
											2018-06-12 14:22:41 -03:00
										 |  |  | 		case NOTIFICATION_RESIZED: { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			_update_margins(); | 
					
						
							| 
									
										
										
										
											2018-06-12 14:22:41 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-15 18:06:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		case NOTIFICATION_DRAW: { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 			RID canvas = get_canvas_item(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			Size2 size = get_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 			// Draw only the tab area if the header is hidden.
 | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			Ref<StyleBox> panel = get_theme_stylebox(SNAME("panel")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			if (!tabs_visible) { | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 				panel->draw(canvas, Rect2(0, 0, size.width, size.height)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 			int header_height = _get_top_margin(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			// Draw the popup menu.
 | 
					
						
							|  |  |  | 			if (get_popup()) { | 
					
						
							|  |  |  | 				Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); | 
					
						
							|  |  |  | 				Ref<Texture2D> menu_hl = get_theme_icon(SNAME("menu_highlight")); | 
					
						
							| 
									
										
										
										
											2020-10-13 22:05:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 				int x = is_layout_rtl() ? 0 : get_size().width - menu->get_width(); | 
					
						
							| 
									
										
										
										
											2020-10-13 22:05:26 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (menu_hovered) { | 
					
						
							| 
									
										
										
										
											2017-09-29 13:23:11 +02:00
										 |  |  | 					menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2)); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-09-29 13:23:11 +02:00
										 |  |  | 					menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2)); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2022-02-15 18:06:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 		case NOTIFICATION_TRANSLATION_CHANGED: | 
					
						
							|  |  |  | 		case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 		case NOTIFICATION_THEME_CHANGED: { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			theme_changing = true; | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 			call_deferred(SNAME("_on_theme_changed")); // Wait until all changed theme.
 | 
					
						
							| 
									
										
										
										
											2016-05-30 00:28:29 -03:00
										 |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-12 23:41:51 +07:00
										 |  |  | void TabContainer::_on_theme_changed() { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	if (!theme_changing) { | 
					
						
							| 
									
										
										
										
											2020-12-12 23:41:51 +07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->add_theme_style_override(SNAME("tab_unselected"), get_theme_stylebox(SNAME("tab_unselected"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_style_override(SNAME("tab_selected"), get_theme_stylebox(SNAME("tab_selected"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_style_override(SNAME("tab_disabled"), get_theme_stylebox(SNAME("tab_disabled"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_icon_override(SNAME("increment"), get_theme_icon(SNAME("increment"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_icon_override(SNAME("increment_highlight"), get_theme_icon(SNAME("increment_highlight"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_icon_override(SNAME("decrement"), get_theme_icon(SNAME("decrement"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_icon_override(SNAME("decrement_highlight"), get_theme_icon(SNAME("decrement_highlight"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_color_override(SNAME("font_selected_color"), get_theme_color(SNAME("font_selected_color"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_color_override(SNAME("font_unselected_color"), get_theme_color(SNAME("font_unselected_color"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_color_override(SNAME("font_disabled_color"), get_theme_color(SNAME("font_disabled_color"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_color_override(SNAME("font_outline_color"), get_theme_color(SNAME("font_outline_color"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_font_override(SNAME("font"), get_theme_font(SNAME("font"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_constant_override(SNAME("font_size"), get_theme_constant(SNAME("font_size"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_constant_override(SNAME("icon_separation"), get_theme_constant(SNAME("icon_separation"))); | 
					
						
							|  |  |  | 	tab_bar->add_theme_constant_override(SNAME("outline_size"), get_theme_constant(SNAME("outline_size"))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							| 
									
										
										
										
											2017-12-11 20:46:33 +09:00
										 |  |  | 	if (get_tab_count() > 0) { | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 		_repaint(); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		update_minimum_size(); | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	theme_changing = false; | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TabContainer::_repaint() { | 
					
						
							| 
									
										
										
										
											2021-07-17 18:22:52 -03:00
										 |  |  | 	Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel")); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Vector<Control *> controls = _get_tab_controls(); | 
					
						
							|  |  |  | 	int current = get_current_tab(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (int i = 0; i < controls.size(); i++) { | 
					
						
							|  |  |  | 		Control *c = controls[i]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 		if (i == current) { | 
					
						
							|  |  |  | 			c->show(); | 
					
						
							| 
									
										
										
										
											2020-12-22 16:24:29 +00:00
										 |  |  | 			c->set_anchors_and_offsets_preset(Control::PRESET_WIDE); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 			if (tabs_visible) { | 
					
						
							| 
									
										
										
										
											2020-12-22 16:24:29 +00:00
										 |  |  | 				c->set_offset(SIDE_TOP, _get_top_margin()); | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-04 20:32:37 +02:00
										 |  |  | 			c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + sb->get_margin(SIDE_TOP)); | 
					
						
							|  |  |  | 			c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + sb->get_margin(SIDE_LEFT)); | 
					
						
							|  |  |  | 			c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - sb->get_margin(SIDE_RIGHT)); | 
					
						
							|  |  |  | 			c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - sb->get_margin(SIDE_BOTTOM)); | 
					
						
							| 
									
										
										
										
											2020-06-13 19:15:47 -03:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			c->hide(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-11 20:46:33 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	update_minimum_size(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::_update_margins() { | 
					
						
							|  |  |  | 	int menu_width = get_theme_icon(SNAME("menu"))->get_width(); | 
					
						
							|  |  |  | 	int side_margin = get_theme_constant(SNAME("side_margin")); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	// Directly check for validity, to avoid errors when quitting.
 | 
					
						
							|  |  |  | 	bool has_popup = popup_obj_id.is_valid(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	switch (get_tab_alignment()) { | 
					
						
							|  |  |  | 		case TabBar::ALIGNMENT_LEFT: { | 
					
						
							|  |  |  | 			tab_bar->set_offset(SIDE_LEFT, side_margin); | 
					
						
							|  |  |  | 			tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0); | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2021-08-04 20:32:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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 11:37:10 -03:00
										 |  |  | 		case TabBar::ALIGNMENT_RIGHT: { | 
					
						
							|  |  |  | 			tab_bar->set_offset(SIDE_LEFT, 0); | 
					
						
							| 
									
										
										
										
											2020-12-12 23:41:51 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			if (has_popup) { | 
					
						
							|  |  |  | 				tab_bar->set_offset(SIDE_RIGHT, -menu_width); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			// Calculate if all the tabs would still fit if the margin was present.
 | 
					
						
							|  |  |  | 			if (get_clip_tabs() && (tab_bar->get_offset_buttons_visible() || (get_tab_count() > 1 && (total_tabs_width + side_margin) > get_size().width))) { | 
					
						
							|  |  |  | 				tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				tab_bar->set_offset(SIDE_RIGHT, -side_margin); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} break; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 		case TabBar::ALIGNMENT_MAX: | 
					
						
							|  |  |  | 			break; // Can't happen, but silences warning.
 | 
					
						
							| 
									
										
										
										
											2017-03-01 11:23:19 -06:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::_on_mouse_exited() { | 
					
						
							|  |  |  | 	if (menu_hovered) { | 
					
						
							|  |  |  | 		menu_hovered = false; | 
					
						
							|  |  |  | 		update(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-01 11:23:19 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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)); | 
					
						
							|  |  |  | 		if (!control || control->is_set_as_top_level() || control == tab_bar) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-08-05 22:46:45 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 		controls.push_back(control); | 
					
						
							| 
									
										
										
										
											2021-01-12 10:48:18 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	return controls; | 
					
						
							| 
									
										
										
										
											2018-02-07 06:32:03 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | Variant TabContainer::_get_drag_data_fw(const Point2 &p_point, Control *p_from_control) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!drag_to_rearrange_enabled) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return Variant(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int tab_over = get_tab_idx_at_point(p_point); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (tab_over < 0) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return Variant(); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	HBoxContainer *drag_preview = memnew(HBoxContainer); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | 	Ref<Texture2D> icon = get_tab_icon(tab_over); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	if (!icon.is_null()) { | 
					
						
							|  |  |  | 		TextureRect *tf = memnew(TextureRect); | 
					
						
							|  |  |  | 		tf->set_texture(icon); | 
					
						
							|  |  |  | 		drag_preview->add_child(tf); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	Label *label = memnew(Label(get_tab_title(tab_over))); | 
					
						
							|  |  |  | 	set_drag_preview(drag_preview); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	drag_preview->add_child(label); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary drag_data; | 
					
						
							|  |  |  | 	drag_data["type"] = "tabc_element"; | 
					
						
							|  |  |  | 	drag_data["tabc_element"] = tab_over; | 
					
						
							|  |  |  | 	drag_data["from_path"] = get_path(); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	return drag_data; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | bool TabContainer::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!drag_to_rearrange_enabled) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!d.has("type")) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (String(d["type"]) == "tabc_element") { | 
					
						
							|  |  |  | 		NodePath from_path = d["from_path"]; | 
					
						
							|  |  |  | 		NodePath to_path = get_path(); | 
					
						
							|  |  |  | 		if (from_path == to_path) { | 
					
						
							|  |  |  | 			return true; | 
					
						
							|  |  |  | 		} else if (get_tabs_rearrange_group() != -1) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			// Drag and drop between other TabContainers.
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 			Node *from_node = get_node(from_path); | 
					
						
							|  |  |  | 			TabContainer *from_tabc = Object::cast_to<TabContainer>(from_node); | 
					
						
							|  |  |  | 			if (from_tabc && from_tabc->get_tabs_rearrange_group() == get_tabs_rearrange_group()) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!drag_to_rearrange_enabled) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	int hover_now = get_tab_idx_at_point(p_point); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Dictionary d = p_data; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (!d.has("type")) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (String(d["type"]) == "tabc_element") { | 
					
						
							|  |  |  | 		int tab_from_id = d["tabc_element"]; | 
					
						
							|  |  |  | 		NodePath from_path = d["from_path"]; | 
					
						
							|  |  |  | 		NodePath to_path = get_path(); | 
					
						
							|  |  |  | 		if (from_path == to_path) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			if (hover_now < 0) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 				hover_now = get_tab_count() - 1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index(false)); | 
					
						
							| 
									
										
										
										
											2022-03-05 21:03:01 +01:00
										 |  |  | 			if (!is_tab_disabled(hover_now)) { | 
					
						
							|  |  |  | 				set_current_tab(hover_now); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 		} else if (get_tabs_rearrange_group() != -1) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 			// Drag and drop between TabContainers.
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 			Node *from_node = get_node(from_path); | 
					
						
							|  |  |  | 			TabContainer *from_tabc = Object::cast_to<TabContainer>(from_node); | 
					
						
							|  |  |  | 			if (from_tabc && from_tabc->get_tabs_rearrange_group() == get_tabs_rearrange_group()) { | 
					
						
							|  |  |  | 				Control *moving_tabc = from_tabc->get_tab_control(tab_from_id); | 
					
						
							|  |  |  | 				from_tabc->remove_child(moving_tabc); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 				add_child(moving_tabc, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				if (hover_now < 0) { | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 					hover_now = get_tab_count() - 1; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				move_child(moving_tabc, get_tab_control(hover_now)->get_index(false)); | 
					
						
							| 
									
										
										
										
											2022-03-05 21:03:01 +01:00
										 |  |  | 				if (!is_tab_disabled(hover_now)) { | 
					
						
							|  |  |  | 					set_current_tab(hover_now); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::_on_tab_changed(int p_tab) { | 
					
						
							|  |  |  | 	call_deferred(SNAME("_repaint")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	emit_signal(SNAME("tab_changed"), p_tab); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TabContainer::_on_tab_selected(int p_tab) { | 
					
						
							|  |  |  | 	if (p_tab != get_previous_tab()) { | 
					
						
							|  |  |  | 		call_deferred(SNAME("_repaint")); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	emit_signal(SNAME("tab_selected"), p_tab); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | void TabContainer::_refresh_tab_names() { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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 11:37:10 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::add_child_notify(Node *p_child) { | 
					
						
							|  |  |  | 	if (p_child == tab_bar) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Container::add_child_notify(p_child); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Control *c = Object::cast_to<Control>(p_child); | 
					
						
							|  |  |  | 	if (!c || c->is_set_as_top_level()) { | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	c->hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tab_bar->add_tab(p_child->get_name()); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 	p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// TabBar won't emit the "tab_changed" signal when not inside the tree.
 | 
					
						
							|  |  |  | 	if (!is_inside_tree()) { | 
					
						
							|  |  |  | 		call_deferred("_repaint"); | 
					
						
							| 
									
										
										
										
											2020-09-03 14:22:16 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::move_child_notify(Node *p_child) { | 
					
						
							|  |  |  | 	if (p_child == tab_bar) { | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Container::move_child_notify(p_child); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Control *c = Object::cast_to<Control>(p_child); | 
					
						
							|  |  |  | 	if (c && !c->is_set_as_top_level()) { | 
					
						
							|  |  |  | 		int old_idx = -1; | 
					
						
							|  |  |  | 		String tab_name = c->has_meta("_tab_name") ? String(c->get_meta("_tab_name")) : String(c->get_name()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// Find the previous tab index of the control.
 | 
					
						
							|  |  |  | 		for (int i = 0; i < get_tab_count(); i++) { | 
					
						
							|  |  |  | 			if (get_tab_title(i) == tab_name) { | 
					
						
							|  |  |  | 				old_idx = i; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tab_bar->move_tab(old_idx, get_tab_idx_from_control(c)); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TabContainer::remove_child_notify(Node *p_child) { | 
					
						
							|  |  |  | 	if (p_child == tab_bar) { | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Container::remove_child_notify(p_child); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Control *c = Object::cast_to<Control>(p_child); | 
					
						
							|  |  |  | 	if (!c || c->is_set_as_top_level()) { | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	tab_bar->remove_tab(get_tab_idx_from_control(c)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (p_child->has_meta("_tab_name")) { | 
					
						
							|  |  |  | 		p_child->remove_meta("_tab_name"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 	p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names)); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// TabBar won't emit the "tab_changed" signal when not inside the tree.
 | 
					
						
							|  |  |  | 	if (!is_inside_tree()) { | 
					
						
							|  |  |  | 		call_deferred("_repaint"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TabContainer::get_tab_count() const { | 
					
						
							|  |  |  | 	return tab_bar->get_tab_count(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TabContainer::set_current_tab(int p_current) { | 
					
						
							|  |  |  | 	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(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 08:01:45 -05:00
										 |  |  | 			return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | void TabContainer::set_tab_alignment(TabBar::AlignmentMode p_alignment) { | 
					
						
							|  |  |  | 	tab_bar->set_tab_alignment(p_alignment); | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | TabBar::AlignmentMode TabContainer::get_tab_alignment() const { | 
					
						
							|  |  |  | 	return tab_bar->get_tab_alignment(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 18:34:47 -06:00
										 |  |  | void TabContainer::set_tabs_visible(bool p_visible) { | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	if (p_visible == tabs_visible) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 18:34:47 -06:00
										 |  |  | 	tabs_visible = p_visible; | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->set_visible(tabs_visible); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Vector<Control *> controls = _get_tab_controls(); | 
					
						
							|  |  |  | 	for (int i = 0; i < controls.size(); i++) { | 
					
						
							|  |  |  | 		Control *c = controls[i]; | 
					
						
							|  |  |  | 		if (tabs_visible) { | 
					
						
							| 
									
										
										
										
											2020-12-22 16:24:29 +00:00
										 |  |  | 			c->set_offset(SIDE_TOP, _get_top_margin()); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-12-22 16:24:29 +00:00
										 |  |  | 			c->set_offset(SIDE_TOP, 0); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-01-24 18:34:47 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2021-12-06 14:02:34 +01:00
										 |  |  | 	update_minimum_size(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TabContainer::are_tabs_visible() const { | 
					
						
							|  |  |  | 	return tabs_visible; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-06 03:12:24 +09: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 11:37:10 -03:00
										 |  |  | 	remove_child(tab_bar); | 
					
						
							|  |  |  | 	add_child(tab_bar, false, all_tabs_in_front ? INTERNAL_MODE_BACK : INTERNAL_MODE_FRONT); | 
					
						
							| 
									
										
										
										
											2020-12-06 03:12:24 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TabContainer::is_all_tabs_in_front() const { | 
					
						
							|  |  |  | 	return all_tabs_in_front; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +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); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	ERR_FAIL_COND(!child); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	if (p_title.is_empty()) { | 
					
						
							|  |  |  | 		tab_bar->set_tab_title(p_tab, String(child->get_name())); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (child->has_meta("_tab_name")) { | 
					
						
							|  |  |  | 			child->remove_meta("_tab_name"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 		tab_bar->set_tab_title(p_tab, p_title); | 
					
						
							|  |  |  | 		child->set_meta("_tab_name", p_title); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 	if (!get_clip_tabs()) { | 
					
						
							|  |  |  | 		update_minimum_size(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | String TabContainer::get_tab_title(int p_tab) const { | 
					
						
							|  |  |  | 	return tab_bar->get_tab_title(p_tab); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->set_tab_icon(p_tab, p_icon); | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 	_repaint(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-11 15:43:37 -03:00
										 |  |  | Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	return tab_bar->get_tab_icon(p_tab); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 15:10:05 -04:00
										 |  |  | void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->set_tab_disabled(p_tab, p_disabled); | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 	if (!get_clip_tabs()) { | 
					
						
							|  |  |  | 		update_minimum_size(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-27 19:07:50 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2017-03-01 11:23:19 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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-08 19:18:03 -03: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); | 
					
						
							| 
									
										
										
										
											2019-04-08 19:18:03 -03:00
										 |  |  | 	ERR_FAIL_COND(!child); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->set_tab_hidden(p_tab, p_hidden); | 
					
						
							| 
									
										
										
										
											2019-04-08 19:18:03 -03:00
										 |  |  | 	child->hide(); | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_update_margins(); | 
					
						
							|  |  |  | 	if (!get_clip_tabs()) { | 
					
						
							|  |  |  | 		update_minimum_size(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-08 19:18:03 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | bool TabContainer::is_tab_hidden(int p_tab) const { | 
					
						
							|  |  |  | 	return tab_bar->is_tab_hidden(p_tab); | 
					
						
							| 
									
										
										
										
											2019-04-08 19:18:03 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void TabContainer::get_translatable_strings(List<String> *p_strings) const { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Vector<Control *> controls = _get_tab_controls(); | 
					
						
							|  |  |  | 	for (int i = 0; i < controls.size(); i++) { | 
					
						
							|  |  |  | 		Control *c = controls[i]; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (!c->has_meta("_tab_name")) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		String name = c->get_meta("_tab_name"); | 
					
						
							| 
									
										
										
										
											2021-12-09 03:42:46 -06:00
										 |  |  | 		if (!name.is_empty()) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 			p_strings->push_back(name); | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | Size2 TabContainer::get_minimum_size() const { | 
					
						
							|  |  |  | 	Size2 ms; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	if (tabs_visible) { | 
					
						
							|  |  |  | 		ms = tab_bar->get_minimum_size(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!get_clip_tabs()) { | 
					
						
							|  |  |  | 			if (get_popup()) { | 
					
						
							|  |  |  | 				ms.x += get_theme_icon(SNAME("menu"))->get_width(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			int side_margin = get_theme_constant(SNAME("side_margin")); | 
					
						
							|  |  |  | 			if (side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER && | 
					
						
							|  |  |  | 					(get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) { | 
					
						
							|  |  |  | 				ms.x += side_margin; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Vector<Control *> controls = _get_tab_controls(); | 
					
						
							|  |  |  | 	int max_control_height = 0; | 
					
						
							|  |  |  | 	for (int i = 0; i < controls.size(); i++) { | 
					
						
							|  |  |  | 		Control *c = controls[i]; | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) { | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2020-05-14 16:41:43 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 18:38:40 -03:00
										 |  |  | 		Size2 cms = c->get_combined_minimum_size(); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 		ms.x = MAX(ms.x, cms.x); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 		max_control_height = MAX(max_control_height, cms.y); | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	ms.y += max_control_height; | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	Size2 panel_ms = get_theme_stylebox(SNAME("panel"))->get_minimum_size(); | 
					
						
							|  |  |  | 	ms.x = MAX(ms.x, panel_ms.x); | 
					
						
							|  |  |  | 	ms.y += panel_ms.y; | 
					
						
							| 
									
										
										
										
											2016-06-17 18:38:40 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 22:34:22 -03:00
										 |  |  | 	return ms; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | void TabContainer::set_popup(Node *p_popup) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	bool had_popup = get_popup(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 19:14:20 +02:00
										 |  |  | 	Popup *popup = Object::cast_to<Popup>(p_popup); | 
					
						
							|  |  |  | 	popup_obj_id = popup ? popup->get_instance_id() : ObjectID(); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (had_popup != bool(popup)) { | 
					
						
							|  |  |  | 		update(); | 
					
						
							|  |  |  | 		_update_margins(); | 
					
						
							| 
									
										
										
										
											2022-03-04 12:09:02 -03:00
										 |  |  | 		if (!get_clip_tabs()) { | 
					
						
							|  |  |  | 			update_minimum_size(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01: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 11:37:10 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 19:14:20 +02:00
										 |  |  | 	return nullptr; | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) { | 
					
						
							|  |  |  | 	drag_to_rearrange_enabled = p_enabled; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TabContainer::get_drag_to_rearrange_enabled() const { | 
					
						
							|  |  |  | 	return drag_to_rearrange_enabled; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2020-05-14 14:29:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | void TabContainer::set_tabs_rearrange_group(int p_group_id) { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar->set_tabs_rearrange_group(p_group_id); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int TabContainer::get_tabs_rearrange_group() const { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	return tab_bar->get_tabs_rearrange_group(); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-26 15:41:36 -03:00
										 |  |  | void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) { | 
					
						
							|  |  |  | 	use_hidden_tabs_for_min_size = p_use_hidden_tabs; | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	update_minimum_size(); | 
					
						
							| 
									
										
										
										
											2019-01-26 15:41:36 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TabContainer::get_use_hidden_tabs_for_min_size() const { | 
					
						
							|  |  |  | 	return use_hidden_tabs_for_min_size; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-09-22 23:07:00 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-08 23:53:41 +03: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-09 22:10:30 -03: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 11:23:19 -06:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab); | 
					
						
							| 
									
										
										
										
											2017-08-09 13:19:41 +02:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control); | 
					
						
							| 
									
										
										
										
											2020-03-14 10:47:36 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control); | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06: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); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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-06 03:12:24 +09: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); | 
					
						
							| 
									
										
										
										
											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); | 
					
						
							| 
									
										
										
										
											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 11:37:10 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled); | 
					
						
							| 
									
										
										
										
											2021-09-24 01:26:59 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("is_tab_hidden", "tab_idx"), &TabContainer::is_tab_hidden); | 
					
						
							| 
									
										
										
										
											2021-08-23 23:14:07 -05:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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 08:01:45 -05: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 15:41:36 -03: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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 23:35:17 +01:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_repaint"), &TabContainer::_repaint); | 
					
						
							| 
									
										
										
										
											2017-12-11 20:46:33 +09:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	ClassDB::bind_method(D_METHOD("_get_drag_data_fw"), &TabContainer::_get_drag_data_fw); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_can_drop_data_fw"), &TabContainer::_can_drop_data_fw); | 
					
						
							|  |  |  | 	ClassDB::bind_method(D_METHOD("_drop_data_fw"), &TabContainer::_drop_data_fw); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); | 
					
						
							| 
									
										
										
										
											2017-03-01 11:23:19 -06:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab"))); | 
					
						
							| 
									
										
										
										
											2015-06-13 22:12:53 -03:00
										 |  |  | 	ADD_SIGNAL(MethodInfo("pre_popup_pressed")); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-24 20:58:47 -06:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment"); | 
					
						
							| 
									
										
										
										
											2017-01-21 19:11:33 +01:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab"); | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03: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-06 03:12:24 +09:00
										 |  |  | 	ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front"); | 
					
						
							| 
									
										
										
										
											2018-02-07 08:01:45 -05: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 15:41:36 -03: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"); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TabContainer::TabContainer() { | 
					
						
							| 
									
										
										
										
											2022-03-02 11:37:10 -03:00
										 |  |  | 	tab_bar = memnew(TabBar); | 
					
						
							|  |  |  | 	tab_bar->set_drag_forwarding(this); | 
					
						
							|  |  |  | 	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)); | 
					
						
							|  |  |  | 	tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-21 18:28:45 +01:00
										 |  |  | 	connect("mouse_exited", callable_mp(this, &TabContainer::_on_mouse_exited)); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | } |