tab_container.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /*************************************************************************/
  2. /* tab_container.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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 "core/object/message_queue.h"
  32. #include "core/string/translation.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/label.h"
  35. #include "scene/gui/texture_rect.h"
  36. int TabContainer::_get_top_margin() const {
  37. if (!tabs_visible) {
  38. return 0;
  39. }
  40. // Respect the minimum tab height.
  41. Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
  42. Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
  43. Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
  44. int tab_height = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height);
  45. // Font height or higher icon wins.
  46. int content_height = 0;
  47. Vector<Control *> tabs = _get_tabs();
  48. for (int i = 0; i < tabs.size(); i++) {
  49. content_height = MAX(content_height, text_buf[i]->get_size().y);
  50. Control *c = tabs[i];
  51. if (!c->has_meta("_tab_icon")) {
  52. continue;
  53. }
  54. Ref<Texture2D> tex = c->get_meta("_tab_icon");
  55. if (!tex.is_valid()) {
  56. continue;
  57. }
  58. content_height = MAX(content_height, tex->get_size().height);
  59. }
  60. return tab_height + content_height;
  61. }
  62. void TabContainer::gui_input(const Ref<InputEvent> &p_event) {
  63. ERR_FAIL_COND(p_event.is_null());
  64. Ref<InputEventMouseButton> mb = p_event;
  65. Popup *popup = get_popup();
  66. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) {
  67. Point2 pos = mb->get_position();
  68. Size2 size = get_size();
  69. // Click must be on tabs in the tab header area.
  70. if (pos.y > _get_top_margin()) {
  71. return;
  72. }
  73. // Handle menu button.
  74. Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
  75. if (is_layout_rtl()) {
  76. if (popup && pos.x < menu->get_width()) {
  77. emit_signal(SNAME("pre_popup_pressed"));
  78. Vector2 popup_pos = get_screen_position();
  79. popup_pos.y += menu->get_height();
  80. popup->set_position(popup_pos);
  81. popup->popup();
  82. return;
  83. }
  84. } else {
  85. if (popup && pos.x > size.width - menu->get_width()) {
  86. emit_signal(SNAME("pre_popup_pressed"));
  87. Vector2 popup_pos = get_screen_position();
  88. popup_pos.x += size.width - popup->get_size().width;
  89. popup_pos.y += menu->get_height();
  90. popup->set_position(popup_pos);
  91. popup->popup();
  92. return;
  93. }
  94. }
  95. // Do not activate tabs when tabs is empty.
  96. if (get_tab_count() == 0) {
  97. return;
  98. }
  99. Vector<Control *> tabs = _get_tabs();
  100. // Handle navigation buttons.
  101. if (buttons_visible_cache) {
  102. int popup_ofs = 0;
  103. if (popup) {
  104. popup_ofs = menu->get_width();
  105. }
  106. Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
  107. Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
  108. if (is_layout_rtl()) {
  109. if (pos.x < popup_ofs + decrement->get_width()) {
  110. if (last_tab_cache < tabs.size() - 1) {
  111. first_tab_cache += 1;
  112. update();
  113. }
  114. return;
  115. } else if (pos.x < popup_ofs + increment->get_width() + decrement->get_width()) {
  116. if (first_tab_cache > 0) {
  117. first_tab_cache -= 1;
  118. update();
  119. }
  120. return;
  121. }
  122. } else {
  123. if (pos.x > size.width - increment->get_width() - popup_ofs && pos.x) {
  124. if (last_tab_cache < tabs.size() - 1) {
  125. first_tab_cache += 1;
  126. update();
  127. }
  128. return;
  129. } else if (pos.x > size.width - increment->get_width() - decrement->get_width() - popup_ofs) {
  130. if (first_tab_cache > 0) {
  131. first_tab_cache -= 1;
  132. update();
  133. }
  134. return;
  135. }
  136. }
  137. }
  138. // Activate the clicked tab.
  139. if (is_layout_rtl()) {
  140. pos.x = size.width - pos.x;
  141. }
  142. if (pos.x < tabs_ofs_cache) {
  143. return;
  144. }
  145. pos.x -= tabs_ofs_cache;
  146. for (int i = first_tab_cache; i <= last_tab_cache; i++) {
  147. if (get_tab_hidden(i)) {
  148. continue;
  149. }
  150. int tab_width = _get_tab_width(i);
  151. if (pos.x < tab_width) {
  152. if (!get_tab_disabled(i)) {
  153. set_current_tab(i);
  154. }
  155. break;
  156. }
  157. pos.x -= tab_width;
  158. }
  159. }
  160. Ref<InputEventMouseMotion> mm = p_event;
  161. if (mm.is_valid()) {
  162. Point2 pos = mm->get_position();
  163. Size2 size = get_size();
  164. // Mouse must be on tabs in the tab header area.
  165. if (pos.y > _get_top_margin()) {
  166. if (menu_hovered || highlight_arrow > -1) {
  167. menu_hovered = false;
  168. highlight_arrow = -1;
  169. update();
  170. }
  171. return;
  172. }
  173. Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
  174. if (popup) {
  175. if (is_layout_rtl()) {
  176. if (pos.x <= menu->get_width()) {
  177. if (!menu_hovered) {
  178. menu_hovered = true;
  179. highlight_arrow = -1;
  180. update();
  181. return;
  182. }
  183. } else if (menu_hovered) {
  184. menu_hovered = false;
  185. update();
  186. }
  187. } else {
  188. if (pos.x >= size.width - menu->get_width()) {
  189. if (!menu_hovered) {
  190. menu_hovered = true;
  191. highlight_arrow = -1;
  192. update();
  193. return;
  194. }
  195. } else if (menu_hovered) {
  196. menu_hovered = false;
  197. update();
  198. }
  199. }
  200. if (menu_hovered) {
  201. return;
  202. }
  203. }
  204. // Do not activate tabs when tabs is empty.
  205. if ((get_tab_count() == 0 || !buttons_visible_cache) && menu_hovered) {
  206. highlight_arrow = -1;
  207. update();
  208. return;
  209. }
  210. int popup_ofs = 0;
  211. if (popup) {
  212. popup_ofs = menu->get_width();
  213. }
  214. Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
  215. Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
  216. if (is_layout_rtl()) {
  217. if (pos.x <= popup_ofs + decrement->get_width()) {
  218. if (highlight_arrow != 1) {
  219. highlight_arrow = 1;
  220. update();
  221. }
  222. } else if (pos.x <= popup_ofs + increment->get_width() + decrement->get_width()) {
  223. if (highlight_arrow != 0) {
  224. highlight_arrow = 0;
  225. update();
  226. }
  227. } else if (highlight_arrow > -1) {
  228. highlight_arrow = -1;
  229. update();
  230. }
  231. } else {
  232. if (pos.x >= size.width - increment->get_width() - popup_ofs) {
  233. if (highlight_arrow != 1) {
  234. highlight_arrow = 1;
  235. update();
  236. }
  237. } else if (pos.x >= size.width - increment->get_width() - decrement->get_width() - popup_ofs) {
  238. if (highlight_arrow != 0) {
  239. highlight_arrow = 0;
  240. update();
  241. }
  242. } else if (highlight_arrow > -1) {
  243. highlight_arrow = -1;
  244. update();
  245. }
  246. }
  247. }
  248. }
  249. void TabContainer::_notification(int p_what) {
  250. switch (p_what) {
  251. case NOTIFICATION_RESIZED: {
  252. Vector<Control *> tabs = _get_tabs();
  253. int side_margin = get_theme_constant(SNAME("side_margin"));
  254. Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
  255. Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
  256. Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
  257. int header_width = get_size().width - side_margin * 2;
  258. // Find the width of the header area.
  259. Popup *popup = get_popup();
  260. if (popup) {
  261. header_width -= menu->get_width();
  262. }
  263. if (buttons_visible_cache) {
  264. header_width -= increment->get_width() + decrement->get_width();
  265. }
  266. if (popup || buttons_visible_cache) {
  267. header_width += side_margin;
  268. }
  269. // Find the width of all tabs after first_tab_cache.
  270. int all_tabs_width = 0;
  271. for (int i = first_tab_cache; i < tabs.size(); i++) {
  272. int tab_width = _get_tab_width(i);
  273. all_tabs_width += tab_width;
  274. }
  275. // Check if tabs before first_tab_cache would fit into the header area.
  276. for (int i = first_tab_cache - 1; i >= 0; i--) {
  277. int tab_width = _get_tab_width(i);
  278. if (all_tabs_width + tab_width > header_width) {
  279. break;
  280. }
  281. all_tabs_width += tab_width;
  282. first_tab_cache--;
  283. }
  284. } break;
  285. case NOTIFICATION_DRAW: {
  286. RID canvas = get_canvas_item();
  287. Size2 size = get_size();
  288. bool rtl = is_layout_rtl();
  289. // Draw only the tab area if the header is hidden.
  290. Ref<StyleBox> panel = get_theme_stylebox(SNAME("panel"));
  291. if (!tabs_visible) {
  292. panel->draw(canvas, Rect2(0, 0, size.width, size.height));
  293. return;
  294. }
  295. Vector<Control *> tabs = _get_tabs();
  296. Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
  297. Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
  298. Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
  299. Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
  300. Ref<Texture2D> increment_hl = get_theme_icon(SNAME("increment_highlight"));
  301. Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
  302. Ref<Texture2D> decrement_hl = get_theme_icon(SNAME("decrement_highlight"));
  303. Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
  304. Ref<Texture2D> menu_hl = get_theme_icon(SNAME("menu_highlight"));
  305. Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
  306. Color font_unselected_color = get_theme_color(SNAME("font_unselected_color"));
  307. Color font_disabled_color = get_theme_color(SNAME("font_disabled_color"));
  308. int side_margin = get_theme_constant(SNAME("side_margin"));
  309. // Find out start and width of the header area.
  310. int header_x = side_margin;
  311. int header_width = size.width - side_margin * 2;
  312. int header_height = _get_top_margin();
  313. Popup *popup = get_popup();
  314. if (popup) {
  315. header_width -= menu->get_width();
  316. }
  317. // Check if all tabs would fit into the header area.
  318. int all_tabs_width = 0;
  319. for (int i = 0; i < tabs.size(); i++) {
  320. if (get_tab_hidden(i)) {
  321. continue;
  322. }
  323. int tab_width = _get_tab_width(i);
  324. all_tabs_width += tab_width;
  325. if (all_tabs_width > header_width) {
  326. // Not all tabs are visible at the same time - reserve space for navigation buttons.
  327. buttons_visible_cache = true;
  328. header_width -= decrement->get_width() + increment->get_width();
  329. break;
  330. } else {
  331. buttons_visible_cache = false;
  332. }
  333. }
  334. // With buttons, a right side margin does not need to be respected.
  335. if (popup || buttons_visible_cache) {
  336. header_width += side_margin;
  337. }
  338. if (!buttons_visible_cache) {
  339. first_tab_cache = 0;
  340. }
  341. // Go through the visible tabs to find the width they occupy.
  342. all_tabs_width = 0;
  343. Vector<int> tab_widths;
  344. for (int i = first_tab_cache; i < tabs.size(); i++) {
  345. if (get_tab_hidden(i)) {
  346. tab_widths.push_back(0);
  347. continue;
  348. }
  349. int tab_width = _get_tab_width(i);
  350. if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0) {
  351. break;
  352. }
  353. all_tabs_width += tab_width;
  354. tab_widths.push_back(tab_width);
  355. }
  356. // Find the offset at which to draw tabs, according to the alignment.
  357. switch (align) {
  358. case ALIGN_LEFT:
  359. tabs_ofs_cache = header_x;
  360. break;
  361. case ALIGN_CENTER:
  362. tabs_ofs_cache = header_x + (header_width / 2) - (all_tabs_width / 2);
  363. break;
  364. case ALIGN_RIGHT:
  365. tabs_ofs_cache = header_x + header_width - all_tabs_width;
  366. break;
  367. }
  368. if (all_tabs_in_front) {
  369. // Draw the tab area.
  370. panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
  371. }
  372. // Draw unselected tabs in back
  373. int x = 0;
  374. int x_current = 0;
  375. int index = 0;
  376. for (int i = 0; i < tab_widths.size(); i++) {
  377. index = i + first_tab_cache;
  378. if (get_tab_hidden(index)) {
  379. continue;
  380. }
  381. int tab_width = tab_widths[i];
  382. if (index == current) {
  383. x_current = x;
  384. } else if (get_tab_disabled(index)) {
  385. if (rtl) {
  386. _draw_tab(tab_disabled, font_disabled_color, index, size.width - (tabs_ofs_cache + x) - tab_width);
  387. } else {
  388. _draw_tab(tab_disabled, font_disabled_color, index, tabs_ofs_cache + x);
  389. }
  390. } else {
  391. if (rtl) {
  392. _draw_tab(tab_unselected, font_unselected_color, index, size.width - (tabs_ofs_cache + x) - tab_width);
  393. } else {
  394. _draw_tab(tab_unselected, font_unselected_color, index, tabs_ofs_cache + x);
  395. }
  396. }
  397. x += tab_width;
  398. last_tab_cache = index;
  399. }
  400. if (!all_tabs_in_front) {
  401. // Draw the tab area.
  402. panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
  403. }
  404. // Draw selected tab in front. Only draw selected tab when it's in visible range.
  405. if (tabs.size() > 0 && current - first_tab_cache < tab_widths.size() && current >= first_tab_cache) {
  406. Ref<StyleBox> current_style_box = get_tab_disabled(current) ? tab_disabled : tab_selected;
  407. if (rtl) {
  408. _draw_tab(current_style_box, font_selected_color, current, size.width - (tabs_ofs_cache + x_current) - tab_widths[current]);
  409. } else {
  410. _draw_tab(current_style_box, font_selected_color, current, tabs_ofs_cache + x_current);
  411. }
  412. }
  413. // Draw the popup menu.
  414. if (rtl) {
  415. x = 0;
  416. } else {
  417. x = get_size().width;
  418. }
  419. if (popup) {
  420. if (!rtl) {
  421. x -= menu->get_width();
  422. }
  423. if (menu_hovered) {
  424. menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
  425. } else {
  426. menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
  427. }
  428. if (rtl) {
  429. x += menu->get_width();
  430. }
  431. }
  432. // Draw the navigation buttons.
  433. if (buttons_visible_cache) {
  434. if (rtl) {
  435. if (last_tab_cache < tabs.size() - 1) {
  436. draw_texture(highlight_arrow == 1 ? decrement_hl : decrement, Point2(x, (header_height - increment->get_height()) / 2));
  437. } else {
  438. draw_texture(decrement, Point2(x, (header_height - increment->get_height()) / 2), Color(1, 1, 1, 0.5));
  439. }
  440. x += increment->get_width();
  441. if (first_tab_cache > 0) {
  442. draw_texture(highlight_arrow == 0 ? increment_hl : increment, Point2(x, (header_height - decrement->get_height()) / 2));
  443. } else {
  444. draw_texture(increment, Point2(x, (header_height - decrement->get_height()) / 2), Color(1, 1, 1, 0.5));
  445. }
  446. x += decrement->get_width();
  447. } else {
  448. x -= increment->get_width();
  449. if (last_tab_cache < tabs.size() - 1) {
  450. draw_texture(highlight_arrow == 1 ? increment_hl : increment, Point2(x, (header_height - increment->get_height()) / 2));
  451. } else {
  452. draw_texture(increment, Point2(x, (header_height - increment->get_height()) / 2), Color(1, 1, 1, 0.5));
  453. }
  454. x -= decrement->get_width();
  455. if (first_tab_cache > 0) {
  456. draw_texture(highlight_arrow == 0 ? decrement_hl : decrement, Point2(x, (header_height - decrement->get_height()) / 2));
  457. } else {
  458. draw_texture(decrement, Point2(x, (header_height - decrement->get_height()) / 2), Color(1, 1, 1, 0.5));
  459. }
  460. }
  461. }
  462. } break;
  463. case NOTIFICATION_TRANSLATION_CHANGED:
  464. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
  465. case NOTIFICATION_THEME_CHANGED: {
  466. Vector<Control *> tabs = _get_tabs();
  467. for (int i = 0; i < tabs.size(); i++) {
  468. text_buf.write[i]->clear();
  469. }
  470. _theme_changing = true;
  471. call_deferred(SNAME("_on_theme_changed")); // Wait until all changed theme.
  472. } break;
  473. }
  474. }
  475. void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x) {
  476. Control *control = get_tab_control(p_index);
  477. RID canvas = get_canvas_item();
  478. Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
  479. int outline_size = get_theme_constant(SNAME("outline_size"));
  480. int icon_text_distance = get_theme_constant(SNAME("icon_separation"));
  481. int tab_width = _get_tab_width(p_index);
  482. int header_height = _get_top_margin();
  483. // Draw the tab background.
  484. Rect2 tab_rect(p_x, 0, tab_width, header_height);
  485. p_tab_style->draw(canvas, tab_rect);
  486. // Draw the tab contents.
  487. String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
  488. int x_content = tab_rect.position.x + p_tab_style->get_margin(SIDE_LEFT);
  489. int top_margin = p_tab_style->get_margin(SIDE_TOP);
  490. int y_center = top_margin + (tab_rect.size.y - p_tab_style->get_minimum_size().y) / 2;
  491. // Draw the tab icon.
  492. if (control->has_meta("_tab_icon")) {
  493. Ref<Texture2D> icon = control->get_meta("_tab_icon");
  494. if (icon.is_valid()) {
  495. int y = y_center - (icon->get_height() / 2);
  496. icon->draw(canvas, Point2i(x_content, y));
  497. if (text != "") {
  498. x_content += icon->get_width() + icon_text_distance;
  499. }
  500. }
  501. }
  502. // Draw the tab text.
  503. Point2i text_pos(x_content, y_center - text_buf[p_index]->get_size().y / 2);
  504. if (outline_size > 0 && font_outline_color.a > 0) {
  505. text_buf[p_index]->draw_outline(canvas, text_pos, outline_size, font_outline_color);
  506. }
  507. text_buf[p_index]->draw(canvas, text_pos, p_font_color);
  508. }
  509. void TabContainer::_refresh_texts() {
  510. text_buf.clear();
  511. Vector<Control *> tabs = _get_tabs();
  512. bool rtl = is_layout_rtl();
  513. Ref<Font> font = get_theme_font(SNAME("font"));
  514. int font_size = get_theme_font_size(SNAME("font_size"));
  515. for (int i = 0; i < tabs.size(); i++) {
  516. Control *control = Object::cast_to<Control>(tabs[i]);
  517. String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
  518. Ref<TextLine> name;
  519. name.instantiate();
  520. name->set_direction(rtl ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
  521. name->add_string(text, font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale());
  522. text_buf.push_back(name);
  523. }
  524. }
  525. void TabContainer::_on_theme_changed() {
  526. if (!_theme_changing) {
  527. return;
  528. }
  529. _refresh_texts();
  530. minimum_size_changed();
  531. if (get_tab_count() > 0) {
  532. _repaint();
  533. update();
  534. }
  535. _theme_changing = false;
  536. }
  537. void TabContainer::_repaint() {
  538. Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
  539. Vector<Control *> tabs = _get_tabs();
  540. for (int i = 0; i < tabs.size(); i++) {
  541. Control *c = tabs[i];
  542. if (i == current) {
  543. c->show();
  544. c->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
  545. if (tabs_visible) {
  546. c->set_offset(SIDE_TOP, _get_top_margin());
  547. }
  548. c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + sb->get_margin(SIDE_TOP));
  549. c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + sb->get_margin(SIDE_LEFT));
  550. c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - sb->get_margin(SIDE_RIGHT));
  551. c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - sb->get_margin(SIDE_BOTTOM));
  552. } else {
  553. c->hide();
  554. }
  555. }
  556. }
  557. void TabContainer::_on_mouse_exited() {
  558. if (menu_hovered || highlight_arrow > -1) {
  559. menu_hovered = false;
  560. highlight_arrow = -1;
  561. update();
  562. }
  563. }
  564. int TabContainer::_get_tab_width(int p_index) const {
  565. ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
  566. Control *control = get_tab_control(p_index);
  567. if (!control || get_tab_hidden(p_index)) {
  568. return 0;
  569. }
  570. // Get the width of the text displayed on the tab.
  571. Ref<Font> font = get_theme_font(SNAME("font"));
  572. int font_size = get_theme_font_size(SNAME("font_size"));
  573. String text = control->has_meta("_tab_name") ? String(atr(String(control->get_meta("_tab_name")))) : String(atr(control->get_name()));
  574. int width = font->get_string_size(text, font_size).width;
  575. // Add space for a tab icon.
  576. if (control->has_meta("_tab_icon")) {
  577. Ref<Texture2D> icon = control->get_meta("_tab_icon");
  578. if (icon.is_valid()) {
  579. width += icon->get_width();
  580. if (text != "") {
  581. width += get_theme_constant(SNAME("icon_separation"));
  582. }
  583. }
  584. }
  585. // Respect a minimum size.
  586. Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
  587. Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
  588. Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
  589. if (get_tab_disabled(p_index)) {
  590. width += tab_disabled->get_minimum_size().width;
  591. } else if (p_index == current) {
  592. width += tab_selected->get_minimum_size().width;
  593. } else {
  594. width += tab_unselected->get_minimum_size().width;
  595. }
  596. return width;
  597. }
  598. Vector<Control *> TabContainer::_get_tabs() const {
  599. Vector<Control *> controls;
  600. for (int i = 0; i < get_child_count(); i++) {
  601. Control *control = Object::cast_to<Control>(get_child(i));
  602. if (!control || control->is_set_as_top_level()) {
  603. continue;
  604. }
  605. controls.push_back(control);
  606. }
  607. return controls;
  608. }
  609. void TabContainer::_child_renamed_callback() {
  610. _refresh_texts();
  611. update();
  612. }
  613. void TabContainer::add_child_notify(Node *p_child) {
  614. Container::add_child_notify(p_child);
  615. Control *c = Object::cast_to<Control>(p_child);
  616. if (!c || c->is_set_as_top_level()) {
  617. return;
  618. }
  619. Vector<Control *> tabs = _get_tabs();
  620. _refresh_texts();
  621. bool first = false;
  622. if (tabs.size() != 1) {
  623. c->hide();
  624. } else {
  625. c->show();
  626. //call_deferred(SNAME("set_current_tab"),0);
  627. first = true;
  628. current = 0;
  629. previous = 0;
  630. }
  631. c->set_anchors_and_offsets_preset(Control::PRESET_WIDE);
  632. if (tabs_visible) {
  633. c->set_offset(SIDE_TOP, _get_top_margin());
  634. }
  635. Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
  636. c->set_offset(SIDE_TOP, c->get_offset(SIDE_TOP) + sb->get_margin(SIDE_TOP));
  637. c->set_offset(SIDE_LEFT, c->get_offset(SIDE_LEFT) + sb->get_margin(SIDE_LEFT));
  638. c->set_offset(SIDE_RIGHT, c->get_offset(SIDE_RIGHT) - sb->get_margin(SIDE_RIGHT));
  639. c->set_offset(SIDE_BOTTOM, c->get_offset(SIDE_BOTTOM) - sb->get_margin(SIDE_BOTTOM));
  640. update();
  641. p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
  642. if (first && is_inside_tree()) {
  643. emit_signal(SNAME("tab_changed"), current);
  644. }
  645. }
  646. void TabContainer::move_child_notify(Node *p_child) {
  647. Container::move_child_notify(p_child);
  648. Control *c = Object::cast_to<Control>(p_child);
  649. if (!c || c->is_set_as_top_level()) {
  650. return;
  651. }
  652. _update_current_tab();
  653. update();
  654. }
  655. int TabContainer::get_tab_count() const {
  656. return _get_tabs().size();
  657. }
  658. void TabContainer::set_current_tab(int p_current) {
  659. ERR_FAIL_INDEX(p_current, get_tab_count());
  660. int pending_previous = current;
  661. current = p_current;
  662. _repaint();
  663. if (pending_previous == current) {
  664. emit_signal(SNAME("tab_selected"), current);
  665. } else {
  666. previous = pending_previous;
  667. emit_signal(SNAME("tab_selected"), current);
  668. emit_signal(SNAME("tab_changed"), current);
  669. }
  670. update();
  671. }
  672. int TabContainer::get_current_tab() const {
  673. return current;
  674. }
  675. int TabContainer::get_previous_tab() const {
  676. return previous;
  677. }
  678. Control *TabContainer::get_tab_control(int p_idx) const {
  679. Vector<Control *> tabs = _get_tabs();
  680. if (p_idx >= 0 && p_idx < tabs.size()) {
  681. return tabs[p_idx];
  682. } else {
  683. return nullptr;
  684. }
  685. }
  686. Control *TabContainer::get_current_tab_control() const {
  687. return get_tab_control(current);
  688. }
  689. void TabContainer::remove_child_notify(Node *p_child) {
  690. Container::remove_child_notify(p_child);
  691. Control *c = Object::cast_to<Control>(p_child);
  692. if (!c || c->is_set_as_top_level()) {
  693. return;
  694. }
  695. // Defer the call because tab is not yet removed (remove_child_notify is called right before p_child is actually removed).
  696. call_deferred(SNAME("_update_current_tab"));
  697. p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback));
  698. update();
  699. }
  700. void TabContainer::_update_current_tab() {
  701. _refresh_texts();
  702. int tc = get_tab_count();
  703. if (current >= tc) {
  704. current = tc - 1;
  705. }
  706. if (current < 0) {
  707. current = 0;
  708. } else {
  709. set_current_tab(current);
  710. }
  711. }
  712. Variant TabContainer::get_drag_data(const Point2 &p_point) {
  713. if (!drag_to_rearrange_enabled) {
  714. return Variant();
  715. }
  716. int tab_over = get_tab_idx_at_point(p_point);
  717. if (tab_over < 0) {
  718. return Variant();
  719. }
  720. HBoxContainer *drag_preview = memnew(HBoxContainer);
  721. Ref<Texture2D> icon = get_tab_icon(tab_over);
  722. if (!icon.is_null()) {
  723. TextureRect *tf = memnew(TextureRect);
  724. tf->set_texture(icon);
  725. drag_preview->add_child(tf);
  726. }
  727. Label *label = memnew(Label(get_tab_title(tab_over)));
  728. drag_preview->add_child(label);
  729. set_drag_preview(drag_preview);
  730. Dictionary drag_data;
  731. drag_data["type"] = "tabc_element";
  732. drag_data["tabc_element"] = tab_over;
  733. drag_data["from_path"] = get_path();
  734. return drag_data;
  735. }
  736. bool TabContainer::can_drop_data(const Point2 &p_point, const Variant &p_data) const {
  737. if (!drag_to_rearrange_enabled) {
  738. return false;
  739. }
  740. Dictionary d = p_data;
  741. if (!d.has("type")) {
  742. return false;
  743. }
  744. if (String(d["type"]) == "tabc_element") {
  745. NodePath from_path = d["from_path"];
  746. NodePath to_path = get_path();
  747. if (from_path == to_path) {
  748. return true;
  749. } else if (get_tabs_rearrange_group() != -1) {
  750. // drag and drop between other TabContainers
  751. Node *from_node = get_node(from_path);
  752. TabContainer *from_tabc = Object::cast_to<TabContainer>(from_node);
  753. if (from_tabc && from_tabc->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
  754. return true;
  755. }
  756. }
  757. }
  758. return false;
  759. }
  760. void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) {
  761. if (!drag_to_rearrange_enabled) {
  762. return;
  763. }
  764. int hover_now = get_tab_idx_at_point(p_point);
  765. Dictionary d = p_data;
  766. if (!d.has("type")) {
  767. return;
  768. }
  769. if (String(d["type"]) == "tabc_element") {
  770. int tab_from_id = d["tabc_element"];
  771. NodePath from_path = d["from_path"];
  772. NodePath to_path = get_path();
  773. if (from_path == to_path) {
  774. if (hover_now < 0) {
  775. hover_now = get_tab_count() - 1;
  776. }
  777. move_child(get_tab_control(tab_from_id), get_tab_control(hover_now)->get_index());
  778. set_current_tab(hover_now);
  779. } else if (get_tabs_rearrange_group() != -1) {
  780. // drag and drop between TabContainers
  781. Node *from_node = get_node(from_path);
  782. TabContainer *from_tabc = Object::cast_to<TabContainer>(from_node);
  783. if (from_tabc && from_tabc->get_tabs_rearrange_group() == get_tabs_rearrange_group()) {
  784. Control *moving_tabc = from_tabc->get_tab_control(tab_from_id);
  785. from_tabc->remove_child(moving_tabc);
  786. add_child(moving_tabc, false, INTERNAL_MODE_FRONT);
  787. if (hover_now < 0) {
  788. hover_now = get_tab_count() - 1;
  789. }
  790. move_child(moving_tabc, get_tab_control(hover_now)->get_index());
  791. set_current_tab(hover_now);
  792. emit_signal(SNAME("tab_changed"), hover_now);
  793. }
  794. }
  795. }
  796. update();
  797. }
  798. int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
  799. if (get_tab_count() == 0) {
  800. return -1;
  801. }
  802. // must be on tabs in the tab header area.
  803. if (p_point.y > _get_top_margin()) {
  804. return -1;
  805. }
  806. Size2 size = get_size();
  807. int button_ofs = 0;
  808. int px = p_point.x;
  809. if (is_layout_rtl()) {
  810. px = size.width - px;
  811. }
  812. if (px < tabs_ofs_cache) {
  813. return -1;
  814. }
  815. Popup *popup = get_popup();
  816. if (popup) {
  817. Ref<Texture2D> menu = get_theme_icon(SNAME("menu"));
  818. button_ofs += menu->get_width();
  819. }
  820. if (buttons_visible_cache) {
  821. Ref<Texture2D> increment = get_theme_icon(SNAME("increment"));
  822. Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement"));
  823. button_ofs += increment->get_width() + decrement->get_width();
  824. }
  825. if (px > size.width - button_ofs) {
  826. return -1;
  827. }
  828. // get the tab at the point
  829. Vector<Control *> tabs = _get_tabs();
  830. px -= tabs_ofs_cache;
  831. for (int i = first_tab_cache; i <= last_tab_cache; i++) {
  832. int tab_width = _get_tab_width(i);
  833. if (px < tab_width) {
  834. return i;
  835. }
  836. px -= tab_width;
  837. }
  838. return -1;
  839. }
  840. void TabContainer::set_tab_align(TabAlign p_align) {
  841. ERR_FAIL_INDEX(p_align, 3);
  842. align = p_align;
  843. update();
  844. }
  845. TabContainer::TabAlign TabContainer::get_tab_align() const {
  846. return align;
  847. }
  848. void TabContainer::set_tabs_visible(bool p_visible) {
  849. if (p_visible == tabs_visible) {
  850. return;
  851. }
  852. tabs_visible = p_visible;
  853. Vector<Control *> tabs = _get_tabs();
  854. for (int i = 0; i < tabs.size(); i++) {
  855. Control *c = tabs[i];
  856. if (p_visible) {
  857. c->set_offset(SIDE_TOP, _get_top_margin());
  858. } else {
  859. c->set_offset(SIDE_TOP, 0);
  860. }
  861. }
  862. update();
  863. minimum_size_changed();
  864. }
  865. bool TabContainer::are_tabs_visible() const {
  866. return tabs_visible;
  867. }
  868. void TabContainer::set_all_tabs_in_front(bool p_in_front) {
  869. if (p_in_front == all_tabs_in_front) {
  870. return;
  871. }
  872. all_tabs_in_front = p_in_front;
  873. update();
  874. }
  875. bool TabContainer::is_all_tabs_in_front() const {
  876. return all_tabs_in_front;
  877. }
  878. void TabContainer::set_tab_title(int p_tab, const String &p_title) {
  879. Control *child = get_tab_control(p_tab);
  880. ERR_FAIL_COND(!child);
  881. child->set_meta("_tab_name", p_title);
  882. _refresh_texts();
  883. update();
  884. }
  885. String TabContainer::get_tab_title(int p_tab) const {
  886. Control *child = get_tab_control(p_tab);
  887. ERR_FAIL_COND_V(!child, "");
  888. if (child->has_meta("_tab_name")) {
  889. return child->get_meta("_tab_name");
  890. } else {
  891. return child->get_name();
  892. }
  893. }
  894. void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) {
  895. Control *child = get_tab_control(p_tab);
  896. ERR_FAIL_COND(!child);
  897. child->set_meta("_tab_icon", p_icon);
  898. update();
  899. }
  900. Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
  901. Control *child = get_tab_control(p_tab);
  902. ERR_FAIL_COND_V(!child, Ref<Texture2D>());
  903. if (child->has_meta("_tab_icon")) {
  904. return child->get_meta("_tab_icon");
  905. } else {
  906. return Ref<Texture2D>();
  907. }
  908. }
  909. void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
  910. Control *child = get_tab_control(p_tab);
  911. ERR_FAIL_COND(!child);
  912. child->set_meta("_tab_disabled", p_disabled);
  913. update();
  914. }
  915. bool TabContainer::get_tab_disabled(int p_tab) const {
  916. Control *child = get_tab_control(p_tab);
  917. ERR_FAIL_COND_V(!child, false);
  918. if (child->has_meta("_tab_disabled")) {
  919. return child->get_meta("_tab_disabled");
  920. } else {
  921. return false;
  922. }
  923. }
  924. void TabContainer::set_tab_hidden(int p_tab, bool p_hidden) {
  925. Control *child = get_tab_control(p_tab);
  926. ERR_FAIL_COND(!child);
  927. child->set_meta("_tab_hidden", p_hidden);
  928. update();
  929. for (int i = 0; i < get_tab_count(); i++) {
  930. int try_tab = (p_tab + 1 + i) % get_tab_count();
  931. if (get_tab_disabled(try_tab) || get_tab_hidden(try_tab)) {
  932. continue;
  933. }
  934. set_current_tab(try_tab);
  935. return;
  936. }
  937. //assumed no other tab can be switched to, just hide
  938. child->hide();
  939. }
  940. bool TabContainer::get_tab_hidden(int p_tab) const {
  941. Control *child = get_tab_control(p_tab);
  942. ERR_FAIL_COND_V(!child, false);
  943. if (child->has_meta("_tab_hidden")) {
  944. return child->get_meta("_tab_hidden");
  945. } else {
  946. return false;
  947. }
  948. }
  949. void TabContainer::get_translatable_strings(List<String> *p_strings) const {
  950. Vector<Control *> tabs = _get_tabs();
  951. for (int i = 0; i < tabs.size(); i++) {
  952. Control *c = tabs[i];
  953. if (!c->has_meta("_tab_name")) {
  954. continue;
  955. }
  956. String name = c->get_meta("_tab_name");
  957. if (name != "") {
  958. p_strings->push_back(name);
  959. }
  960. }
  961. }
  962. Size2 TabContainer::get_minimum_size() const {
  963. Size2 ms;
  964. Vector<Control *> tabs = _get_tabs();
  965. for (int i = 0; i < tabs.size(); i++) {
  966. Control *c = tabs[i];
  967. if (!c->is_visible_in_tree() && !use_hidden_tabs_for_min_size) {
  968. continue;
  969. }
  970. Size2 cms = c->get_combined_minimum_size();
  971. ms.x = MAX(ms.x, cms.x);
  972. ms.y = MAX(ms.y, cms.y);
  973. }
  974. Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected"));
  975. Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected"));
  976. Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled"));
  977. if (tabs_visible) {
  978. ms.y += MAX(MAX(tab_unselected->get_minimum_size().y, tab_selected->get_minimum_size().y), tab_disabled->get_minimum_size().y);
  979. ms.y += _get_top_margin();
  980. }
  981. Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"));
  982. ms += sb->get_minimum_size();
  983. return ms;
  984. }
  985. void TabContainer::set_popup(Node *p_popup) {
  986. ERR_FAIL_NULL(p_popup);
  987. Popup *popup = Object::cast_to<Popup>(p_popup);
  988. popup_obj_id = popup ? popup->get_instance_id() : ObjectID();
  989. update();
  990. }
  991. Popup *TabContainer::get_popup() const {
  992. if (popup_obj_id.is_valid()) {
  993. Popup *popup = Object::cast_to<Popup>(ObjectDB::get_instance(popup_obj_id));
  994. if (popup) {
  995. return popup;
  996. } else {
  997. #ifdef DEBUG_ENABLED
  998. ERR_PRINT("Popup assigned to TabContainer is gone!");
  999. #endif
  1000. popup_obj_id = ObjectID();
  1001. }
  1002. }
  1003. return nullptr;
  1004. }
  1005. void TabContainer::set_drag_to_rearrange_enabled(bool p_enabled) {
  1006. drag_to_rearrange_enabled = p_enabled;
  1007. }
  1008. bool TabContainer::get_drag_to_rearrange_enabled() const {
  1009. return drag_to_rearrange_enabled;
  1010. }
  1011. void TabContainer::set_tabs_rearrange_group(int p_group_id) {
  1012. tabs_rearrange_group = p_group_id;
  1013. }
  1014. int TabContainer::get_tabs_rearrange_group() const {
  1015. return tabs_rearrange_group;
  1016. }
  1017. void TabContainer::set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs) {
  1018. use_hidden_tabs_for_min_size = p_use_hidden_tabs;
  1019. }
  1020. bool TabContainer::get_use_hidden_tabs_for_min_size() const {
  1021. return use_hidden_tabs_for_min_size;
  1022. }
  1023. void TabContainer::_bind_methods() {
  1024. ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
  1025. ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
  1026. ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
  1027. ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab);
  1028. ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control);
  1029. ClassDB::bind_method(D_METHOD("get_tab_control", "tab_idx"), &TabContainer::get_tab_control);
  1030. ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &TabContainer::set_tab_align);
  1031. ClassDB::bind_method(D_METHOD("get_tab_align"), &TabContainer::get_tab_align);
  1032. ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
  1033. ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible);
  1034. ClassDB::bind_method(D_METHOD("set_all_tabs_in_front", "is_front"), &TabContainer::set_all_tabs_in_front);
  1035. ClassDB::bind_method(D_METHOD("is_all_tabs_in_front"), &TabContainer::is_all_tabs_in_front);
  1036. ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
  1037. ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
  1038. ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
  1039. ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
  1040. ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
  1041. ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &TabContainer::get_tab_disabled);
  1042. ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden);
  1043. ClassDB::bind_method(D_METHOD("get_tab_hidden", "tab_idx"), &TabContainer::get_tab_hidden);
  1044. ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point);
  1045. ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
  1046. ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);
  1047. ClassDB::bind_method(D_METHOD("set_drag_to_rearrange_enabled", "enabled"), &TabContainer::set_drag_to_rearrange_enabled);
  1048. ClassDB::bind_method(D_METHOD("get_drag_to_rearrange_enabled"), &TabContainer::get_drag_to_rearrange_enabled);
  1049. ClassDB::bind_method(D_METHOD("set_tabs_rearrange_group", "group_id"), &TabContainer::set_tabs_rearrange_group);
  1050. ClassDB::bind_method(D_METHOD("get_tabs_rearrange_group"), &TabContainer::get_tabs_rearrange_group);
  1051. ClassDB::bind_method(D_METHOD("set_use_hidden_tabs_for_min_size", "enabled"), &TabContainer::set_use_hidden_tabs_for_min_size);
  1052. ClassDB::bind_method(D_METHOD("get_use_hidden_tabs_for_min_size"), &TabContainer::get_use_hidden_tabs_for_min_size);
  1053. ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed);
  1054. ClassDB::bind_method(D_METHOD("_update_current_tab"), &TabContainer::_update_current_tab);
  1055. ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
  1056. ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
  1057. ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
  1058. ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_align", "get_tab_align");
  1059. ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
  1060. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
  1061. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
  1062. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled");
  1063. 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");
  1064. BIND_ENUM_CONSTANT(ALIGN_LEFT);
  1065. BIND_ENUM_CONSTANT(ALIGN_CENTER);
  1066. BIND_ENUM_CONSTANT(ALIGN_RIGHT);
  1067. }
  1068. TabContainer::TabContainer() {
  1069. connect("mouse_exited", callable_mp(this, &TabContainer::_on_mouse_exited));
  1070. }