tab_container.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. /**************************************************************************/
  2. /* tab_container.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "tab_container.h"
  31. #include "scene/theme/theme_db.h"
  32. int TabContainer::_get_tab_height() const {
  33. int height = 0;
  34. if (tabs_visible && get_tab_count() > 0) {
  35. height = tab_bar->get_minimum_size().height;
  36. }
  37. return height;
  38. }
  39. void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
  40. ERR_FAIL_COND(p_event.is_null());
  41. Ref<InputEventMouseButton> mb = p_event;
  42. Popup *popup = get_popup();
  43. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
  44. Point2 pos = mb->get_position();
  45. Size2 size = get_size();
  46. real_t content_height = size.height - _get_tab_height();
  47. // Click must be on tabs in the tab header area.
  48. if (tabs_position == POSITION_TOP && pos.y > _get_tab_height()) {
  49. return;
  50. }
  51. if (tabs_position == POSITION_BOTTOM && pos.y < content_height) {
  52. return;
  53. }
  54. // Handle menu button.
  55. if (popup) {
  56. if (is_layout_rtl() ? pos.x < theme_cache.menu_icon->get_width() : pos.x > size.width - theme_cache.menu_icon->get_width()) {
  57. emit_signal(SNAME("pre_popup_pressed"));
  58. Vector2 popup_pos = get_screen_position();
  59. if (!is_layout_rtl()) {
  60. popup_pos.x += size.width - popup->get_size().width;
  61. }
  62. popup_pos.y += _get_tab_height() / 2.0;
  63. if (tabs_position == POSITION_BOTTOM) {
  64. popup_pos.y += content_height;
  65. popup_pos.y -= popup->get_size().height;
  66. popup_pos.y -= theme_cache.menu_icon->get_height() / 2.0;
  67. } else {
  68. popup_pos.y += theme_cache.menu_icon->get_height() / 2.0;
  69. }
  70. popup->set_position(popup_pos);
  71. popup->popup();
  72. return;
  73. }
  74. }
  75. }
  76. Ref<InputEventMouseMotion> mm = p_event;
  77. if (mm.is_valid()) {
  78. Point2 pos = mm->get_position();
  79. Size2 size = get_size();
  80. // Mouse must be on tabs in the tab header area.
  81. if (tabs_position == POSITION_TOP && pos.y > _get_tab_height()) {
  82. if (menu_hovered) {
  83. menu_hovered = false;
  84. queue_redraw();
  85. }
  86. return;
  87. }
  88. if (tabs_position == POSITION_BOTTOM && pos.y < size.height - _get_tab_height()) {
  89. if (menu_hovered) {
  90. menu_hovered = false;
  91. queue_redraw();
  92. }
  93. return;
  94. }
  95. if (popup) {
  96. if (is_layout_rtl()) {
  97. if (pos.x <= theme_cache.menu_icon->get_width()) {
  98. if (!menu_hovered) {
  99. menu_hovered = true;
  100. queue_redraw();
  101. return;
  102. }
  103. } else if (menu_hovered) {
  104. menu_hovered = false;
  105. queue_redraw();
  106. }
  107. } else {
  108. if (pos.x >= size.width - theme_cache.menu_icon->get_width()) {
  109. if (!menu_hovered) {
  110. menu_hovered = true;
  111. queue_redraw();
  112. return;
  113. }
  114. } else if (menu_hovered) {
  115. menu_hovered = false;
  116. queue_redraw();
  117. }
  118. }
  119. if (menu_hovered) {
  120. return;
  121. }
  122. }
  123. }
  124. }
  125. void TabContainer::_notification(int p_what) {
  126. switch (p_what) {
  127. case NOTIFICATION_ENTER_TREE: {
  128. // If some nodes happen to be renamed outside the tree, the tab names need to be updated manually.
  129. if (get_tab_count() > 0) {
  130. _refresh_tab_names();
  131. }
  132. if (setup_current_tab >= -1) {
  133. set_current_tab(setup_current_tab);
  134. setup_current_tab = -2;
  135. }
  136. } break;
  137. case NOTIFICATION_READY:
  138. case NOTIFICATION_RESIZED: {
  139. _update_margins();
  140. } break;
  141. case NOTIFICATION_DRAW: {
  142. RID canvas = get_canvas_item();
  143. Size2 size = get_size();
  144. // Draw only the tab area if the header is hidden.
  145. if (!tabs_visible) {
  146. theme_cache.panel_style->draw(canvas, Rect2(0, 0, size.width, size.height));
  147. return;
  148. }
  149. int header_height = _get_tab_height();
  150. int header_voffset = int(tabs_position == POSITION_BOTTOM) * (size.height - header_height);
  151. // Draw background for the tabbar.
  152. theme_cache.tabbar_style->draw(canvas, Rect2(0, header_voffset, size.width, header_height));
  153. // Draw the background for the tab's content.
  154. theme_cache.panel_style->draw(canvas, Rect2(0, int(tabs_position == POSITION_TOP) * header_height, size.width, size.height - header_height));
  155. // Draw the popup menu.
  156. if (get_popup()) {
  157. int x = is_layout_rtl() ? 0 : get_size().width - theme_cache.menu_icon->get_width();
  158. if (menu_hovered) {
  159. theme_cache.menu_hl_icon->draw(get_canvas_item(), Point2(x, header_voffset + (header_height - theme_cache.menu_hl_icon->get_height()) / 2));
  160. } else {
  161. theme_cache.menu_icon->draw(get_canvas_item(), Point2(x, header_voffset + (header_height - theme_cache.menu_icon->get_height()) / 2));
  162. }
  163. }
  164. } break;
  165. case NOTIFICATION_VISIBILITY_CHANGED: {
  166. if (!is_visible()) {
  167. return;
  168. }
  169. updating_visibility = true;
  170. // As the visibility change notification will be triggered for all children soon after,
  171. // beat it to the punch and make sure that the correct node is the only one visible first.
  172. // Otherwise, it can prevent a tab change done right before this container was made visible.
  173. Vector<Control *> controls = _get_tab_controls();
  174. int current = setup_current_tab > -2 ? setup_current_tab : get_current_tab();
  175. for (int i = 0; i < controls.size(); i++) {
  176. controls[i]->set_visible(i == current);
  177. }
  178. updating_visibility = false;
  179. } break;
  180. case NOTIFICATION_TRANSLATION_CHANGED:
  181. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
  182. case NOTIFICATION_THEME_CHANGED: {
  183. theme_changing = true;
  184. callable_mp(this, &TabContainer::_on_theme_changed).call_deferred(); // Wait until all changed theme.
  185. } break;
  186. }
  187. }
  188. void TabContainer::_on_theme_changed() {
  189. if (!theme_changing) {
  190. return;
  191. }
  192. tab_bar->begin_bulk_theme_override();
  193. tab_bar->add_theme_style_override(SNAME("tab_unselected"), theme_cache.tab_unselected_style);
  194. tab_bar->add_theme_style_override(SNAME("tab_hovered"), theme_cache.tab_hovered_style);
  195. tab_bar->add_theme_style_override(SNAME("tab_selected"), theme_cache.tab_selected_style);
  196. tab_bar->add_theme_style_override(SNAME("tab_disabled"), theme_cache.tab_disabled_style);
  197. tab_bar->add_theme_style_override(SNAME("tab_focus"), theme_cache.tab_focus_style);
  198. tab_bar->add_theme_icon_override(SNAME("increment"), theme_cache.increment_icon);
  199. tab_bar->add_theme_icon_override(SNAME("increment_highlight"), theme_cache.increment_hl_icon);
  200. tab_bar->add_theme_icon_override(SNAME("decrement"), theme_cache.decrement_icon);
  201. tab_bar->add_theme_icon_override(SNAME("decrement_highlight"), theme_cache.decrement_hl_icon);
  202. tab_bar->add_theme_icon_override(SNAME("drop_mark"), theme_cache.drop_mark_icon);
  203. tab_bar->add_theme_color_override(SNAME("drop_mark_color"), theme_cache.drop_mark_color);
  204. tab_bar->add_theme_color_override(SNAME("font_selected_color"), theme_cache.font_selected_color);
  205. tab_bar->add_theme_color_override(SNAME("font_hovered_color"), theme_cache.font_hovered_color);
  206. tab_bar->add_theme_color_override(SNAME("font_unselected_color"), theme_cache.font_unselected_color);
  207. tab_bar->add_theme_color_override(SNAME("font_disabled_color"), theme_cache.font_disabled_color);
  208. tab_bar->add_theme_color_override(SNAME("font_outline_color"), theme_cache.font_outline_color);
  209. tab_bar->add_theme_font_override(SceneStringName(font), theme_cache.tab_font);
  210. tab_bar->add_theme_font_size_override(SceneStringName(font_size), theme_cache.tab_font_size);
  211. tab_bar->add_theme_constant_override(SNAME("h_separation"), theme_cache.icon_separation);
  212. tab_bar->add_theme_constant_override(SNAME("icon_max_width"), theme_cache.icon_max_width);
  213. tab_bar->add_theme_constant_override(SNAME("outline_size"), theme_cache.outline_size);
  214. tab_bar->end_bulk_theme_override();
  215. _update_margins();
  216. if (get_tab_count() > 0) {
  217. _repaint();
  218. } else {
  219. update_minimum_size();
  220. }
  221. queue_redraw();
  222. theme_changing = false;
  223. }
  224. void TabContainer::_repaint() {
  225. Vector<Control *> controls = _get_tab_controls();
  226. int current = get_current_tab();
  227. // Move the TabBar to the top or bottom.
  228. // Don't change the left and right offsets since the TabBar will resize and may change tab offset.
  229. if (tabs_position == POSITION_BOTTOM) {
  230. tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 1.0, 0.0);
  231. tab_bar->set_anchor_and_offset(SIDE_TOP, 1.0, -_get_tab_height());
  232. } else {
  233. tab_bar->set_anchor_and_offset(SIDE_BOTTOM, 0.0, _get_tab_height());
  234. tab_bar->set_anchor_and_offset(SIDE_TOP, 0.0, 0.0);
  235. }
  236. updating_visibility = true;
  237. for (int i = 0; i < controls.size(); i++) {
  238. Control *c = controls[i];
  239. if (i == current) {
  240. c->show();
  241. c->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
  242. if (tabs_visible) {
  243. if (tabs_position == POSITION_BOTTOM) {
  244. c->set_offset(SIDE_BOTTOM, -_get_tab_height());
  245. } else {
  246. c->set_offset(SIDE_TOP, _get_tab_height());
  247. }
  248. }
  249. c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + theme_cache.panel_style->get_margin(SIDE_TOP));
  250. c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + theme_cache.panel_style->get_margin(SIDE_LEFT));
  251. c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - theme_cache.panel_style->get_margin(SIDE_RIGHT));
  252. c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - theme_cache.panel_style->get_margin(SIDE_BOTTOM));
  253. } else {
  254. c->hide();
  255. }
  256. }
  257. updating_visibility = false;
  258. update_minimum_size();
  259. }
  260. void TabContainer::_update_margins() {
  261. int menu_width = theme_cache.menu_icon->get_width();
  262. // Directly check for validity, to avoid errors when quitting.
  263. bool has_popup = popup_obj_id.is_valid();
  264. if (get_tab_count() == 0) {
  265. tab_bar->set_offset(SIDE_LEFT, 0);
  266. tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
  267. return;
  268. }
  269. switch (get_tab_alignment()) {
  270. case TabBar::ALIGNMENT_LEFT: {
  271. tab_bar->set_offset(SIDE_LEFT, theme_cache.side_margin);
  272. tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
  273. } break;
  274. case TabBar::ALIGNMENT_CENTER: {
  275. tab_bar->set_offset(SIDE_LEFT, 0);
  276. tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
  277. } break;
  278. case TabBar::ALIGNMENT_RIGHT: {
  279. tab_bar->set_offset(SIDE_LEFT, 0);
  280. if (has_popup) {
  281. tab_bar->set_offset(SIDE_RIGHT, -menu_width);
  282. return;
  283. }
  284. int first_tab_pos = tab_bar->get_tab_rect(0).position.x;
  285. Rect2 last_tab_rect = tab_bar->get_tab_rect(get_tab_count() - 1);
  286. int total_tabs_width = last_tab_rect.position.x - first_tab_pos + last_tab_rect.size.width;
  287. // Calculate if all the tabs would still fit if the margin was present.
  288. if (get_clip_tabs() && (tab_bar->get_offset_buttons_visible() || (get_tab_count() > 1 && (total_tabs_width + theme_cache.side_margin) > get_size().width))) {
  289. tab_bar->set_offset(SIDE_RIGHT, has_popup ? -menu_width : 0);
  290. } else {
  291. tab_bar->set_offset(SIDE_RIGHT, -theme_cache.side_margin);
  292. }
  293. } break;
  294. case TabBar::ALIGNMENT_MAX:
  295. break; // Can't happen, but silences warning.
  296. }
  297. }
  298. void TabContainer::_on_mouse_exited() {
  299. if (menu_hovered) {
  300. menu_hovered = false;
  301. queue_redraw();
  302. }
  303. }
  304. Vector<Control *> TabContainer::_get_tab_controls() const {
  305. Vector<Control *> controls;
  306. for (int i = 0; i < get_child_count(); i++) {
  307. Control *control = as_sortable_control(get_child(i), SortableVisbilityMode::IGNORE);
  308. if (!control || control == tab_bar || children_removing.has(control)) {
  309. continue;
  310. }
  311. controls.push_back(control);
  312. }
  313. return controls;
  314. }
  315. Variant TabContainer::_get_drag_data_fw(const Point2 &p_point, Control *p_from_control) {
  316. if (!drag_to_rearrange_enabled) {
  317. return Variant();
  318. }
  319. return tab_bar->_handle_get_drag_data("tab_container_tab", p_point);
  320. }
  321. bool TabContainer::_can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) const {
  322. if (!drag_to_rearrange_enabled) {
  323. return false;
  324. }
  325. return tab_bar->_handle_can_drop_data("tab_container_tab", p_point, p_data);
  326. }
  327. void TabContainer::_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from_control) {
  328. if (!drag_to_rearrange_enabled) {
  329. return;
  330. }
  331. return tab_bar->_handle_drop_data("tab_container_tab", p_point, p_data, callable_mp(this, &TabContainer::_drag_move_tab), callable_mp(this, &TabContainer::_drag_move_tab_from));
  332. }
  333. void TabContainer::_drag_move_tab(int p_from_index, int p_to_index) {
  334. move_child(get_tab_control(p_from_index), get_tab_control(p_to_index)->get_index(false));
  335. }
  336. void TabContainer::_drag_move_tab_from(TabBar *p_from_tabbar, int p_from_index, int p_to_index) {
  337. Node *parent = p_from_tabbar->get_parent();
  338. if (!parent) {
  339. return;
  340. }
  341. TabContainer *from_tab_container = Object::cast_to<TabContainer>(parent);
  342. if (!from_tab_container) {
  343. return;
  344. }
  345. move_tab_from_tab_container(from_tab_container, p_from_index, p_to_index);
  346. }
  347. void TabContainer::move_tab_from_tab_container(TabContainer *p_from, int p_from_index, int p_to_index) {
  348. ERR_FAIL_NULL(p_from);
  349. ERR_FAIL_INDEX(p_from_index, p_from->get_tab_count());
  350. ERR_FAIL_INDEX(p_to_index, get_tab_count() + 1);
  351. // Get the tab properties before they get erased by the child removal.
  352. String tab_title = p_from->get_tab_title(p_from_index);
  353. String tab_tooltip = p_from->get_tab_tooltip(p_from_index);
  354. Ref<Texture2D> tab_icon = p_from->get_tab_icon(p_from_index);
  355. Ref<Texture2D> tab_button_icon = p_from->get_tab_button_icon(p_from_index);
  356. bool tab_disabled = p_from->is_tab_disabled(p_from_index);
  357. bool tab_hidden = p_from->is_tab_hidden(p_from_index);
  358. Variant tab_metadata = p_from->get_tab_metadata(p_from_index);
  359. int tab_icon_max_width = p_from->get_tab_bar()->get_tab_icon_max_width(p_from_index);
  360. Control *moving_tabc = p_from->get_tab_control(p_from_index);
  361. p_from->remove_child(moving_tabc);
  362. add_child(moving_tabc, true);
  363. if (p_to_index < 0 || p_to_index > get_tab_count() - 1) {
  364. p_to_index = get_tab_count() - 1;
  365. }
  366. move_child(moving_tabc, get_tab_control(p_to_index)->get_index(false));
  367. set_tab_title(p_to_index, tab_title);
  368. set_tab_tooltip(p_to_index, tab_tooltip);
  369. set_tab_icon(p_to_index, tab_icon);
  370. set_tab_button_icon(p_to_index, tab_button_icon);
  371. set_tab_disabled(p_to_index, tab_disabled);
  372. set_tab_hidden(p_to_index, tab_hidden);
  373. set_tab_metadata(p_to_index, tab_metadata);
  374. get_tab_bar()->set_tab_icon_max_width(p_to_index, tab_icon_max_width);
  375. if (!is_tab_disabled(p_to_index)) {
  376. set_current_tab(p_to_index);
  377. }
  378. }
  379. void TabContainer::_on_tab_clicked(int p_tab) {
  380. emit_signal(SNAME("tab_clicked"), p_tab);
  381. }
  382. void TabContainer::_on_tab_hovered(int p_tab) {
  383. emit_signal(SNAME("tab_hovered"), p_tab);
  384. }
  385. void TabContainer::_on_tab_changed(int p_tab) {
  386. callable_mp(this, &TabContainer::_repaint).call_deferred();
  387. queue_redraw();
  388. emit_signal(SNAME("tab_changed"), p_tab);
  389. }
  390. void TabContainer::_on_tab_selected(int p_tab) {
  391. if (p_tab != get_previous_tab()) {
  392. callable_mp(this, &TabContainer::_repaint).call_deferred();
  393. }
  394. emit_signal(SNAME("tab_selected"), p_tab);
  395. }
  396. void TabContainer::_on_tab_button_pressed(int p_tab) {
  397. emit_signal(SNAME("tab_button_pressed"), p_tab);
  398. }
  399. void TabContainer::_on_active_tab_rearranged(int p_tab) {
  400. emit_signal(SNAME("active_tab_rearranged"), p_tab);
  401. }
  402. void TabContainer::_on_tab_visibility_changed(Control *p_child) {
  403. if (updating_visibility) {
  404. return;
  405. }
  406. int tab_index = get_tab_idx_from_control(p_child);
  407. if (tab_index == -1) {
  408. return;
  409. }
  410. // Only allow one tab to be visible.
  411. bool made_visible = p_child->is_visible();
  412. updating_visibility = true;
  413. if (!made_visible && get_current_tab() == tab_index) {
  414. if (get_deselect_enabled() || get_tab_count() == 0) {
  415. // Deselect.
  416. set_current_tab(-1);
  417. } else if (get_tab_count() == 1) {
  418. // Only tab, cannot deselect.
  419. p_child->show();
  420. } else {
  421. // Set a different tab to be the current tab.
  422. bool selected = select_next_available();
  423. if (!selected) {
  424. selected = select_previous_available();
  425. }
  426. if (!selected) {
  427. // No available tabs, deselect.
  428. set_current_tab(-1);
  429. }
  430. }
  431. } else if (made_visible && get_current_tab() != tab_index) {
  432. set_current_tab(tab_index);
  433. }
  434. updating_visibility = false;
  435. }
  436. void TabContainer::_refresh_tab_indices() {
  437. Vector<Control *> controls = _get_tab_controls();
  438. for (int i = 0; i < controls.size(); i++) {
  439. controls[i]->set_meta("_tab_index", i);
  440. }
  441. }
  442. void TabContainer::_refresh_tab_names() {
  443. Vector<Control *> controls = _get_tab_controls();
  444. for (int i = 0; i < controls.size(); i++) {
  445. if (!controls[i]->has_meta("_tab_name") && String(controls[i]->get_name()) != get_tab_title(i)) {
  446. tab_bar->set_tab_title(i, controls[i]->get_name());
  447. }
  448. }
  449. }
  450. void TabContainer::add_child_notify(Node *p_child) {
  451. Container::add_child_notify(p_child);
  452. if (p_child == tab_bar) {
  453. return;
  454. }
  455. Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
  456. if (!c) {
  457. return;
  458. }
  459. c->hide();
  460. tab_bar->add_tab(p_child->get_name());
  461. c->set_meta("_tab_index", tab_bar->get_tab_count() - 1);
  462. _update_margins();
  463. if (get_tab_count() == 1) {
  464. queue_redraw();
  465. }
  466. p_child->connect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names));
  467. p_child->connect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed).bind(c));
  468. // TabBar won't emit the "tab_changed" signal when not inside the tree.
  469. if (!is_inside_tree()) {
  470. callable_mp(this, &TabContainer::_repaint).call_deferred();
  471. }
  472. }
  473. void TabContainer::move_child_notify(Node *p_child) {
  474. Container::move_child_notify(p_child);
  475. if (p_child == tab_bar) {
  476. return;
  477. }
  478. Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
  479. if (c) {
  480. tab_bar->move_tab(c->get_meta("_tab_index"), get_tab_idx_from_control(c));
  481. }
  482. _refresh_tab_indices();
  483. }
  484. void TabContainer::remove_child_notify(Node *p_child) {
  485. Container::remove_child_notify(p_child);
  486. if (p_child == tab_bar) {
  487. return;
  488. }
  489. Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
  490. if (!c) {
  491. return;
  492. }
  493. int idx = get_tab_idx_from_control(c);
  494. // As the child hasn't been removed yet, keep track of it so when the "tab_changed" signal is fired it can be ignored.
  495. children_removing.push_back(c);
  496. tab_bar->remove_tab(idx);
  497. _refresh_tab_indices();
  498. children_removing.erase(c);
  499. _update_margins();
  500. if (get_tab_count() == 0) {
  501. queue_redraw();
  502. }
  503. p_child->remove_meta("_tab_index");
  504. p_child->remove_meta("_tab_name");
  505. p_child->disconnect("renamed", callable_mp(this, &TabContainer::_refresh_tab_names));
  506. p_child->disconnect(SceneStringName(visibility_changed), callable_mp(this, &TabContainer::_on_tab_visibility_changed));
  507. // TabBar won't emit the "tab_changed" signal when not inside the tree.
  508. if (!is_inside_tree()) {
  509. callable_mp(this, &TabContainer::_repaint).call_deferred();
  510. }
  511. }
  512. TabBar *TabContainer::get_tab_bar() const {
  513. return tab_bar;
  514. }
  515. int TabContainer::get_tab_count() const {
  516. return tab_bar->get_tab_count();
  517. }
  518. void TabContainer::set_current_tab(int p_current) {
  519. if (!is_inside_tree()) {
  520. setup_current_tab = p_current;
  521. return;
  522. }
  523. tab_bar->set_current_tab(p_current);
  524. }
  525. int TabContainer::get_current_tab() const {
  526. return tab_bar->get_current_tab();
  527. }
  528. int TabContainer::get_previous_tab() const {
  529. return tab_bar->get_previous_tab();
  530. }
  531. bool TabContainer::select_previous_available() {
  532. return tab_bar->select_previous_available();
  533. }
  534. bool TabContainer::select_next_available() {
  535. return tab_bar->select_next_available();
  536. }
  537. void TabContainer::set_deselect_enabled(bool p_enabled) {
  538. tab_bar->set_deselect_enabled(p_enabled);
  539. }
  540. bool TabContainer::get_deselect_enabled() const {
  541. return tab_bar->get_deselect_enabled();
  542. }
  543. Control *TabContainer::get_tab_control(int p_idx) const {
  544. Vector<Control *> controls = _get_tab_controls();
  545. if (p_idx >= 0 && p_idx < controls.size()) {
  546. return controls[p_idx];
  547. } else {
  548. return nullptr;
  549. }
  550. }
  551. Control *TabContainer::get_current_tab_control() const {
  552. return get_tab_control(tab_bar->get_current_tab());
  553. }
  554. int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
  555. return tab_bar->get_tab_idx_at_point(p_point);
  556. }
  557. int TabContainer::get_tab_idx_from_control(Control *p_child) const {
  558. ERR_FAIL_NULL_V(p_child, -1);
  559. ERR_FAIL_COND_V(p_child->get_parent() != this, -1);
  560. Vector<Control *> controls = _get_tab_controls();
  561. for (int i = 0; i < controls.size(); i++) {
  562. if (controls[i] == p_child) {
  563. return i;
  564. }
  565. }
  566. return -1;
  567. }
  568. void TabContainer::set_tab_alignment(TabBar::AlignmentMode p_alignment) {
  569. if (tab_bar->get_tab_alignment() == p_alignment) {
  570. return;
  571. }
  572. tab_bar->set_tab_alignment(p_alignment);
  573. _update_margins();
  574. }
  575. TabBar::AlignmentMode TabContainer::get_tab_alignment() const {
  576. return tab_bar->get_tab_alignment();
  577. }
  578. void TabContainer::set_tabs_position(TabPosition p_tabs_position) {
  579. ERR_FAIL_INDEX(p_tabs_position, POSITION_MAX);
  580. if (p_tabs_position == tabs_position) {
  581. return;
  582. }
  583. tabs_position = p_tabs_position;
  584. tab_bar->set_tab_style_v_flip(tabs_position == POSITION_BOTTOM);
  585. callable_mp(this, &TabContainer::_repaint).call_deferred();
  586. queue_redraw();
  587. }
  588. TabContainer::TabPosition TabContainer::get_tabs_position() const {
  589. return tabs_position;
  590. }
  591. void TabContainer::set_tab_focus_mode(Control::FocusMode p_focus_mode) {
  592. tab_bar->set_focus_mode(p_focus_mode);
  593. }
  594. Control::FocusMode TabContainer::get_tab_focus_mode() const {
  595. return tab_bar->get_focus_mode();
  596. }
  597. void TabContainer::set_clip_tabs(bool p_clip_tabs) {
  598. tab_bar->set_clip_tabs(p_clip_tabs);
  599. }
  600. bool TabContainer::get_clip_tabs() const {
  601. return tab_bar->get_clip_tabs();
  602. }
  603. void TabContainer::set_tabs_visible(bool p_visible) {
  604. if (p_visible == tabs_visible) {
  605. return;
  606. }
  607. tabs_visible = p_visible;
  608. tab_bar->set_visible(tabs_visible);
  609. callable_mp(this, &TabContainer::_repaint).call_deferred();
  610. queue_redraw();
  611. }
  612. bool TabContainer::are_tabs_visible() const {
  613. return tabs_visible;
  614. }
  615. void TabContainer::set_all_tabs_in_front(bool p_in_front) {
  616. if (p_in_front == all_tabs_in_front) {
  617. return;
  618. }
  619. all_tabs_in_front = p_in_front;
  620. remove_child(tab_bar);
  621. add_child(tab_bar, false, all_tabs_in_front ? INTERNAL_MODE_FRONT : INTERNAL_MODE_BACK);
  622. }
  623. bool TabContainer::is_all_tabs_in_front() const {
  624. return all_tabs_in_front;
  625. }
  626. void TabContainer::set_tab_title(int p_tab, const String &p_title) {
  627. Control *child = get_tab_control(p_tab);
  628. ERR_FAIL_NULL(child);
  629. if (tab_bar->get_tab_title(p_tab) == p_title) {
  630. return;
  631. }
  632. tab_bar->set_tab_title(p_tab, p_title);
  633. if (p_title == child->get_name()) {
  634. child->remove_meta("_tab_name");
  635. } else {
  636. child->set_meta("_tab_name", p_title);
  637. }
  638. _repaint();
  639. queue_redraw();
  640. }
  641. String TabContainer::get_tab_title(int p_tab) const {
  642. return tab_bar->get_tab_title(p_tab);
  643. }
  644. void TabContainer::set_tab_tooltip(int p_tab, const String &p_tooltip) {
  645. tab_bar->set_tab_tooltip(p_tab, p_tooltip);
  646. }
  647. String TabContainer::get_tab_tooltip(int p_tab) const {
  648. return tab_bar->get_tab_tooltip(p_tab);
  649. }
  650. void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
  651. if (tab_bar->get_tab_icon(p_tab) == p_icon) {
  652. return;
  653. }
  654. tab_bar->set_tab_icon(p_tab, p_icon);
  655. _update_margins();
  656. _repaint();
  657. queue_redraw();
  658. }
  659. Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
  660. return tab_bar->get_tab_icon(p_tab);
  661. }
  662. void TabContainer::set_tab_icon_max_width(int p_tab, int p_width) {
  663. if (tab_bar->get_tab_icon_max_width(p_tab) == p_width) {
  664. return;
  665. }
  666. tab_bar->set_tab_icon_max_width(p_tab, p_width);
  667. _update_margins();
  668. _repaint();
  669. queue_redraw();
  670. }
  671. int TabContainer::get_tab_icon_max_width(int p_tab) const {
  672. return tab_bar->get_tab_icon_max_width(p_tab);
  673. }
  674. void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
  675. if (tab_bar->is_tab_disabled(p_tab) == p_disabled) {
  676. return;
  677. }
  678. tab_bar->set_tab_disabled(p_tab, p_disabled);
  679. _update_margins();
  680. if (!get_clip_tabs()) {
  681. update_minimum_size();
  682. }
  683. }
  684. bool TabContainer::is_tab_disabled(int p_tab) const {
  685. return tab_bar->is_tab_disabled(p_tab);
  686. }
  687. void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
  688. Control *child = get_tab_control(p_tab);
  689. ERR_FAIL_NULL(child);
  690. if (tab_bar->is_tab_hidden(p_tab) == p_hidden) {
  691. return;
  692. }
  693. tab_bar->set_tab_hidden(p_tab, p_hidden);
  694. child->hide();
  695. _update_margins();
  696. if (!get_clip_tabs()) {
  697. update_minimum_size();
  698. }
  699. callable_mp(this, &TabContainer::_repaint).call_deferred();
  700. }
  701. bool TabContainer::is_tab_hidden(int p_tab) const {
  702. return tab_bar->is_tab_hidden(p_tab);
  703. }
  704. void TabContainer::set_tab_metadata(int p_tab, const Variant &p_metadata) {
  705. tab_bar->set_tab_metadata(p_tab, p_metadata);
  706. }
  707. Variant TabContainer::get_tab_metadata(int p_tab) const {
  708. return tab_bar->get_tab_metadata(p_tab);
  709. }
  710. void TabContainer::set_tab_button_icon(int p_tab, const Ref<Texture2D> &p_icon) {
  711. tab_bar->set_tab_button_icon(p_tab, p_icon);
  712. _update_margins();
  713. _repaint();
  714. }
  715. Ref<Texture2D> TabContainer::get_tab_button_icon(int p_tab) const {
  716. return tab_bar->get_tab_button_icon(p_tab);
  717. }
  718. Size2 TabContainer::get_minimum_size() const {
  719. Size2 ms;
  720. if (tabs_visible) {
  721. ms = tab_bar->get_minimum_size();
  722. if (!get_clip_tabs()) {
  723. if (get_popup()) {
  724. ms.x += theme_cache.menu_icon->get_width();
  725. }
  726. if (theme_cache.side_margin > 0 && get_tab_alignment() != TabBar::ALIGNMENT_CENTER &&
  727. (get_tab_alignment() != TabBar::ALIGNMENT_RIGHT || !get_popup())) {
  728. ms.x += theme_cache.side_margin;
  729. }
  730. }
  731. }
  732. Vector<Control *> controls = _get_tab_controls();
  733. Size2 largest_child_min_size;
  734. for (int i = 0; i < controls.size(); i++) {
  735. Control *c = controls[i];
  736. if (!c->is_visible() && !use_hidden_tabs_for_min_size) {
  737. continue;
  738. }
  739. Size2 cms = c->get_combined_minimum_size();
  740. largest_child_min_size = largest_child_min_size.max(cms);
  741. }
  742. ms.y += largest_child_min_size.y;
  743. Size2 panel_ms = theme_cache.panel_style->get_minimum_size();
  744. ms.x = MAX(ms.x, largest_child_min_size.x + panel_ms.x);
  745. ms.y += panel_ms.y;
  746. return ms;
  747. }
  748. void TabContainer::set_popup(Node *p_popup) {
  749. bool had_popup = get_popup();
  750. Popup *popup = Object::cast_to<Popup>(p_popup);
  751. ObjectID popup_id = popup ? popup->get_instance_id() : ObjectID();
  752. if (popup_obj_id == popup_id) {
  753. return;
  754. }
  755. popup_obj_id = popup_id;
  756. if (had_popup != bool(popup)) {
  757. queue_redraw();
  758. _update_margins();
  759. if (!get_clip_tabs()) {
  760. update_minimum_size();
  761. }
  762. }
  763. }
  764. Popup *TabContainer::get_popup() const {
  765. if (popup_obj_id.is_valid()) {
  766. Popup *popup = Object::cast_to<Popup>(ObjectDB::get_instance(popup_obj_id));
  767. if (popup) {
  768. return popup;
  769. } else {
  770. #ifdef DEBUG_ENABLED
  771. ERR_PRINT("Popup assigned to TabContainer is gone!");
  772. #endif
  773. popup_obj_id = ObjectID();
  774. }
  775. }
  776. return nullptr;
  777. }
  778. void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) {
  779. drag_to_rearrange_enabled = p_enabled;
  780. }
  781. bool TabContainer::get_drag_to_rearrange_enabled() const {
  782. return drag_to_rearrange_enabled;
  783. }
  784. void TabContainer::set_tabs_rearrange_group(int p_group_id) {
  785. tab_bar->set_tabs_rearrange_group(p_group_id);
  786. }
  787. int TabContainer::get_tabs_rearrange_group() const {
  788. return tab_bar->get_tabs_rearrange_group();
  789. }
  790. void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) {
  791. if (use_hidden_tabs_for_min_size == p_use_hidden_tabs) {
  792. return;
  793. }
  794. use_hidden_tabs_for_min_size = p_use_hidden_tabs;
  795. update_minimum_size();
  796. }
  797. bool TabContainer::get_use_hidden_tabs_for_min_size() const {
  798. return use_hidden_tabs_for_min_size;
  799. }
  800. Vector<int> TabContainer::get_allowed_size_flags_horizontal() const {
  801. return Vector<int>();
  802. }
  803. Vector<int> TabContainer::get_allowed_size_flags_vertical() const {
  804. return Vector<int>();
  805. }
  806. void TabContainer::_bind_methods() {
  807. ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
  808. ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
  809. ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
  810. ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab);
  811. ClassDB::bind_method(D_METHOD("select_previous_available"), &TabContainer::select_previous_available);
  812. ClassDB::bind_method(D_METHOD("select_next_available"), &TabContainer::select_next_available);
  813. ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control);
  814. ClassDB::bind_method(D_METHOD("get_tab_bar"), &TabContainer::get_tab_bar);
  815. ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control);
  816. ClassDB::bind_method(D_METHOD("set_tab_alignment", "alignment"), &TabContainer::set_tab_alignment);
  817. ClassDB::bind_method(D_METHOD("get_tab_alignment"), &TabContainer::get_tab_alignment);
  818. ClassDB::bind_method(D_METHOD("set_tabs_position", "tabs_position"), &TabContainer::set_tabs_position);
  819. ClassDB::bind_method(D_METHOD("get_tabs_position"), &TabContainer::get_tabs_position);
  820. ClassDB::bind_method(D_METHOD("set_clip_tabs", "clip_tabs"), &TabContainer::set_clip_tabs);
  821. ClassDB::bind_method(D_METHOD("get_clip_tabs"), &TabContainer::get_clip_tabs);
  822. ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
  823. ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible);
  824. ClassDB::bind_method(D_METHOD("set_all_tabs_in_front", "is_front"), &TabContainer::set_all_tabs_in_front);
  825. ClassDB::bind_method(D_METHOD("is_all_tabs_in_front"), &TabContainer::is_all_tabs_in_front);
  826. ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
  827. ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
  828. ClassDB::bind_method(D_METHOD("set_tab_tooltip", "tab_idx", "tooltip"), &TabContainer::set_tab_tooltip);
  829. ClassDB::bind_method(D_METHOD("get_tab_tooltip", "tab_idx"), &TabContainer::get_tab_tooltip);
  830. ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
  831. ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
  832. ClassDB::bind_method(D_METHOD("set_tab_icon_max_width", "tab_idx", "width"), &TabContainer::set_tab_icon_max_width);
  833. ClassDB::bind_method(D_METHOD("get_tab_icon_max_width", "tab_idx"), &TabContainer::get_tab_icon_max_width);
  834. ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
  835. ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled);
  836. ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden);
  837. ClassDB::bind_method(D_METHOD("is_tab_hidden", "tab_idx"), &TabContainer::is_tab_hidden);
  838. ClassDB::bind_method(D_METHOD("set_tab_metadata", "tab_idx", "metadata"), &TabContainer::set_tab_metadata);
  839. ClassDB::bind_method(D_METHOD("get_tab_metadata", "tab_idx"), &TabContainer::get_tab_metadata);
  840. ClassDB::bind_method(D_METHOD("set_tab_button_icon", "tab_idx", "icon"), &TabContainer::set_tab_button_icon);
  841. ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &TabContainer::get_tab_button_icon);
  842. ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point);
  843. ClassDB::bind_method(D_METHOD("get_tab_idx_from_control", "control"), &TabContainer::get_tab_idx_from_control);
  844. ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
  845. ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);
  846. ClassDB::bind_method(D_METHOD("set_drag_to_rearrange_enabled", "enabled"), &TabContainer::set_drag_to_rearrange_enabled);
  847. ClassDB::bind_method(D_METHOD("get_drag_to_rearrange_enabled"), &TabContainer::get_drag_to_rearrange_enabled);
  848. ClassDB::bind_method(D_METHOD("set_tabs_rearrange_group", "group_id"), &TabContainer::set_tabs_rearrange_group);
  849. ClassDB::bind_method(D_METHOD("get_tabs_rearrange_group"), &TabContainer::get_tabs_rearrange_group);
  850. ClassDB::bind_method(D_METHOD("set_use_hidden_tabs_for_min_size", "enabled"), &TabContainer::set_use_hidden_tabs_for_min_size);
  851. ClassDB::bind_method(D_METHOD("get_use_hidden_tabs_for_min_size"), &TabContainer::get_use_hidden_tabs_for_min_size);
  852. ClassDB::bind_method(D_METHOD("set_tab_focus_mode", "focus_mode"), &TabContainer::set_tab_focus_mode);
  853. ClassDB::bind_method(D_METHOD("get_tab_focus_mode"), &TabContainer::get_tab_focus_mode);
  854. ClassDB::bind_method(D_METHOD("set_deselect_enabled", "enabled"), &TabContainer::set_deselect_enabled);
  855. ClassDB::bind_method(D_METHOD("get_deselect_enabled"), &TabContainer::get_deselect_enabled);
  856. ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to")));
  857. ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
  858. ADD_SIGNAL(MethodInfo("tab_clicked", PropertyInfo(Variant::INT, "tab")));
  859. ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab")));
  860. ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
  861. ADD_SIGNAL(MethodInfo("tab_button_pressed", PropertyInfo(Variant::INT, "tab")));
  862. ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
  863. ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment");
  864. ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab");
  865. ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_position", PROPERTY_HINT_ENUM, "Top,Bottom"), "set_tabs_position", "get_tabs_position");
  866. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs");
  867. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
  868. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
  869. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled");
  870. ADD_PROPERTY(PropertyInfo(Variant::INT, "tabs_rearrange_group"), "set_tabs_rearrange_group", "get_tabs_rearrange_group");
  871. 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");
  872. ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_focus_mode", PROPERTY_HINT_ENUM, "None,Click,All"), "set_tab_focus_mode", "get_tab_focus_mode");
  873. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled");
  874. BIND_ENUM_CONSTANT(POSITION_TOP);
  875. BIND_ENUM_CONSTANT(POSITION_BOTTOM);
  876. BIND_ENUM_CONSTANT(POSITION_MAX);
  877. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, side_margin);
  878. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, panel_style, "panel");
  879. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tabbar_style, "tabbar_background");
  880. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_icon, "menu");
  881. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, menu_hl_icon, "menu_highlight");
  882. // TabBar overrides.
  883. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_separation);
  884. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, icon_max_width);
  885. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_unselected_style, "tab_unselected");
  886. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_hovered_style, "tab_hovered");
  887. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_selected_style, "tab_selected");
  888. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_disabled_style, "tab_disabled");
  889. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_STYLEBOX, TabContainer, tab_focus_style, "tab_focus");
  890. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_icon, "increment");
  891. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, increment_hl_icon, "increment_highlight");
  892. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_icon, "decrement");
  893. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, decrement_hl_icon, "decrement_highlight");
  894. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, TabContainer, drop_mark_icon, "drop_mark");
  895. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, drop_mark_color);
  896. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_selected_color);
  897. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_hovered_color);
  898. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_unselected_color);
  899. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_disabled_color);
  900. BIND_THEME_ITEM(Theme::DATA_TYPE_COLOR, TabContainer, font_outline_color);
  901. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT, TabContainer, tab_font, "font");
  902. BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_FONT_SIZE, TabContainer, tab_font_size, "font_size");
  903. BIND_THEME_ITEM(Theme::DATA_TYPE_CONSTANT, TabContainer, outline_size);
  904. }
  905. TabContainer::TabContainer() {
  906. tab_bar = memnew(TabBar);
  907. SET_DRAG_FORWARDING_GCDU(tab_bar, TabContainer);
  908. add_child(tab_bar, false, INTERNAL_MODE_FRONT);
  909. tab_bar->set_anchors_and_offsets_preset(Control::PRESET_TOP_WIDE);
  910. tab_bar->connect("tab_changed", callable_mp(this, &TabContainer::_on_tab_changed));
  911. tab_bar->connect("tab_clicked", callable_mp(this, &TabContainer::_on_tab_clicked));
  912. tab_bar->connect("tab_hovered", callable_mp(this, &TabContainer::_on_tab_hovered));
  913. tab_bar->connect("tab_selected", callable_mp(this, &TabContainer::_on_tab_selected));
  914. tab_bar->connect("tab_button_pressed", callable_mp(this, &TabContainer::_on_tab_button_pressed));
  915. tab_bar->connect("active_tab_rearranged", callable_mp(this, &TabContainer::_on_active_tab_rearranged));
  916. connect(SceneStringName(mouse_exited), callable_mp(this, &TabContainer::_on_mouse_exited));
  917. }