tab_container.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*************************************************************************/
  2. /* tab_container.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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 "message_queue.h"
  32. int TabContainer::_get_top_margin() const {
  33. if (!tabs_visible)
  34. return 0;
  35. // Respect the minimum tab height.
  36. Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
  37. Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
  38. Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
  39. int tab_height = MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height);
  40. // Font height or higher icon wins.
  41. Ref<Font> font = get_font("font");
  42. int content_height = font->get_height();
  43. Vector<Control *> tabs = _get_tabs();
  44. for (int i = 0; i < tabs.size(); i++) {
  45. Control *c = tabs[i];
  46. if (!c->has_meta("_tab_icon"))
  47. continue;
  48. Ref<Texture> tex = c->get_meta("_tab_icon");
  49. if (!tex.is_valid())
  50. continue;
  51. content_height = MAX(content_height, tex->get_size().height);
  52. }
  53. return tab_height + content_height;
  54. }
  55. void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
  56. Ref<InputEventMouseButton> mb = p_event;
  57. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  58. Point2 pos(mb->get_position().x, mb->get_position().y);
  59. Size2 size = get_size();
  60. // Click must be on tabs in the tab header area.
  61. if (pos.x < tabs_ofs_cache || pos.y > _get_top_margin())
  62. return;
  63. // Handle menu button.
  64. Ref<Texture> menu = get_icon("menu");
  65. if (popup && pos.x > size.width - menu->get_width()) {
  66. emit_signal("pre_popup_pressed");
  67. Vector2 popup_pos = get_global_position();
  68. popup_pos.x += size.width - popup->get_size().width;
  69. popup_pos.y += menu->get_height();
  70. popup->set_global_position(popup_pos);
  71. popup->popup();
  72. return;
  73. }
  74. // Do not activate tabs when tabs is empty
  75. if (get_tab_count() == 0)
  76. return;
  77. Vector<Control *> tabs = _get_tabs();
  78. // Handle navigation buttons.
  79. if (buttons_visible_cache) {
  80. int popup_ofs = 0;
  81. if (popup) {
  82. popup_ofs = menu->get_width();
  83. }
  84. Ref<Texture> increment = get_icon("increment");
  85. Ref<Texture> decrement = get_icon("decrement");
  86. if (pos.x > size.width - increment->get_width() - popup_ofs) {
  87. if (last_tab_cache < tabs.size() - 1) {
  88. first_tab_cache += 1;
  89. update();
  90. }
  91. return;
  92. } else if (pos.x > size.width - increment->get_width() - decrement->get_width() - popup_ofs) {
  93. if (first_tab_cache > 0) {
  94. first_tab_cache -= 1;
  95. update();
  96. }
  97. return;
  98. }
  99. }
  100. // Activate the clicked tab.
  101. pos.x -= tabs_ofs_cache;
  102. for (int i = first_tab_cache; i <= last_tab_cache; i++) {
  103. int tab_width = _get_tab_width(i);
  104. if (pos.x < tab_width) {
  105. if (!get_tab_disabled(i)) {
  106. set_current_tab(i);
  107. }
  108. break;
  109. }
  110. pos.x -= tab_width;
  111. }
  112. }
  113. }
  114. void TabContainer::_notification(int p_what) {
  115. switch (p_what) {
  116. case NOTIFICATION_DRAW: {
  117. RID canvas = get_canvas_item();
  118. Size2 size = get_size();
  119. // Draw only the tab area if the header is hidden.
  120. Ref<StyleBox> panel = get_stylebox("panel");
  121. if (!tabs_visible) {
  122. panel->draw(canvas, Rect2(0, 0, size.width, size.height));
  123. return;
  124. }
  125. Vector<Control *> tabs = _get_tabs();
  126. Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
  127. Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
  128. Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
  129. Ref<Texture> increment = get_icon("increment");
  130. Ref<Texture> decrement = get_icon("decrement");
  131. Ref<Texture> menu = get_icon("menu");
  132. Ref<Texture> menu_hl = get_icon("menu_hl");
  133. Ref<Font> font = get_font("font");
  134. Color font_color_fg = get_color("font_color_fg");
  135. Color font_color_bg = get_color("font_color_bg");
  136. Color font_color_disabled = get_color("font_color_disabled");
  137. int side_margin = get_constant("side_margin");
  138. int icon_text_distance = get_constant("hseparation");
  139. // Find out start and width of the header area.
  140. int header_x = side_margin;
  141. int header_width = size.width - side_margin * 2;
  142. int header_height = _get_top_margin();
  143. if (popup)
  144. header_width -= menu->get_width();
  145. // Check if all tabs would fit into the header area.
  146. int all_tabs_width = 0;
  147. for (int i = 0; i < tabs.size(); i++) {
  148. int tab_width = _get_tab_width(i);
  149. all_tabs_width += tab_width;
  150. if (all_tabs_width > header_width) {
  151. // Not all tabs are visible at the same time - reserve space for navigation buttons.
  152. buttons_visible_cache = true;
  153. header_width -= decrement->get_width() + increment->get_width();
  154. break;
  155. } else {
  156. buttons_visible_cache = false;
  157. }
  158. }
  159. // With buttons, a right side margin does not need to be respected.
  160. if (popup || buttons_visible_cache) {
  161. header_width += side_margin;
  162. }
  163. // Go through the visible tabs to find the width they occupy.
  164. all_tabs_width = 0;
  165. Vector<int> tab_widths;
  166. for (int i = first_tab_cache; i < tabs.size(); i++) {
  167. int tab_width = _get_tab_width(i);
  168. if (all_tabs_width + tab_width > header_width && tab_widths.size() > 0)
  169. break;
  170. all_tabs_width += tab_width;
  171. tab_widths.push_back(tab_width);
  172. }
  173. // Find the offset at which to draw tabs, according to the alignment.
  174. switch (align) {
  175. case ALIGN_LEFT:
  176. tabs_ofs_cache = header_x;
  177. break;
  178. case ALIGN_CENTER:
  179. tabs_ofs_cache = header_x + (header_width / 2) - (all_tabs_width / 2);
  180. break;
  181. case ALIGN_RIGHT:
  182. tabs_ofs_cache = header_x + header_width - all_tabs_width;
  183. break;
  184. }
  185. // Draw the tab area.
  186. panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
  187. // Draw all visible tabs.
  188. int x = 0;
  189. for (int i = 0; i < tab_widths.size(); i++) {
  190. Ref<StyleBox> tab_style;
  191. Color font_color;
  192. if (get_tab_disabled(i + first_tab_cache)) {
  193. tab_style = tab_disabled;
  194. font_color = font_color_disabled;
  195. } else if (i + first_tab_cache == current) {
  196. tab_style = tab_fg;
  197. font_color = font_color_fg;
  198. } else {
  199. tab_style = tab_bg;
  200. font_color = font_color_bg;
  201. }
  202. // Draw the tab background.
  203. int tab_width = tab_widths[i];
  204. Rect2 tab_rect(tabs_ofs_cache + x, 0, tab_width, header_height);
  205. tab_style->draw(canvas, tab_rect);
  206. // Draw the tab contents.
  207. Control *control = Object::cast_to<Control>(tabs[i + first_tab_cache]);
  208. String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name());
  209. int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT);
  210. int top_margin = tab_style->get_margin(MARGIN_TOP);
  211. int y_center = top_margin + (tab_rect.size.y - tab_style->get_minimum_size().y) / 2;
  212. // Draw the tab icon.
  213. if (control->has_meta("_tab_icon")) {
  214. Ref<Texture> icon = control->get_meta("_tab_icon");
  215. if (icon.is_valid()) {
  216. int y = y_center - (icon->get_height() / 2);
  217. icon->draw(canvas, Point2i(x_content, y));
  218. if (text != "")
  219. x_content += icon->get_width() + icon_text_distance;
  220. }
  221. }
  222. // Draw the tab text.
  223. Point2i text_pos(x_content, y_center - (font->get_height() / 2) + font->get_ascent());
  224. font->draw(canvas, text_pos, text, font_color);
  225. x += tab_width;
  226. last_tab_cache = i + first_tab_cache;
  227. }
  228. // Draw the popup menu.
  229. x = get_size().width;
  230. if (popup) {
  231. x -= menu->get_width();
  232. if (mouse_x_cache > x)
  233. menu_hl->draw(get_canvas_item(), Size2(x, (header_height - menu_hl->get_height()) / 2));
  234. else
  235. menu->draw(get_canvas_item(), Size2(x, (header_height - menu->get_height()) / 2));
  236. }
  237. // Draw the navigation buttons.
  238. if (buttons_visible_cache) {
  239. int y_center = header_height / 2;
  240. x -= increment->get_width();
  241. increment->draw(canvas,
  242. Point2(x, y_center - (increment->get_height() / 2)),
  243. Color(1, 1, 1, last_tab_cache < tabs.size() - 1 ? 1.0 : 0.5));
  244. x -= decrement->get_width();
  245. decrement->draw(canvas,
  246. Point2(x, y_center - (decrement->get_height() / 2)),
  247. Color(1, 1, 1, first_tab_cache > 0 ? 1.0 : 0.5));
  248. }
  249. } break;
  250. case NOTIFICATION_THEME_CHANGED: {
  251. if (get_tab_count() > 0) {
  252. call_deferred("set_current_tab", get_current_tab()); //wait until all changed theme
  253. }
  254. } break;
  255. }
  256. }
  257. int TabContainer::_get_tab_width(int p_index) const {
  258. ERR_FAIL_INDEX_V(p_index, get_tab_count(), 0);
  259. Control *control = Object::cast_to<Control>(_get_tabs()[p_index]);
  260. if (!control || control->is_set_as_toplevel())
  261. return 0;
  262. // Get the width of the text displayed on the tab.
  263. Ref<Font> font = get_font("font");
  264. String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name());
  265. int width = font->get_string_size(text).width;
  266. // Add space for a tab icon.
  267. if (control->has_meta("_tab_icon")) {
  268. Ref<Texture> icon = control->get_meta("_tab_icon");
  269. if (icon.is_valid()) {
  270. width += icon->get_width();
  271. if (text != "")
  272. width += get_constant("hseparation");
  273. }
  274. }
  275. // Respect a minimum size.
  276. Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
  277. Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
  278. Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
  279. if (get_tab_disabled(p_index)) {
  280. width += tab_disabled->get_minimum_size().width;
  281. } else if (p_index == current) {
  282. width += tab_fg->get_minimum_size().width;
  283. } else {
  284. width += tab_bg->get_minimum_size().width;
  285. }
  286. return width;
  287. }
  288. Vector<Control *> TabContainer::_get_tabs() const {
  289. Vector<Control *> controls;
  290. for (int i = 0; i < get_child_count(); i++) {
  291. Control *control = Object::cast_to<Control>(get_child(i));
  292. if (!control || control->is_toplevel_control())
  293. continue;
  294. controls.push_back(control);
  295. }
  296. return controls;
  297. }
  298. void TabContainer::_child_renamed_callback() {
  299. update();
  300. }
  301. void TabContainer::add_child_notify(Node *p_child) {
  302. Control::add_child_notify(p_child);
  303. Control *c = Object::cast_to<Control>(p_child);
  304. if (!c)
  305. return;
  306. if (c->is_set_as_toplevel())
  307. return;
  308. bool first = false;
  309. if (get_tab_count() != 1)
  310. c->hide();
  311. else {
  312. c->show();
  313. //call_deferred("set_current_tab",0);
  314. first = true;
  315. current = 0;
  316. previous = 0;
  317. }
  318. c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  319. if (tabs_visible)
  320. c->set_margin(MARGIN_TOP, _get_top_margin());
  321. Ref<StyleBox> sb = get_stylebox("panel");
  322. c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
  323. c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
  324. c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT)));
  325. c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM)));
  326. update();
  327. p_child->connect("renamed", this, "_child_renamed_callback");
  328. if (first)
  329. emit_signal("tab_changed", current);
  330. }
  331. int TabContainer::get_tab_count() const {
  332. return _get_tabs().size();
  333. }
  334. void TabContainer::set_current_tab(int p_current) {
  335. ERR_FAIL_INDEX(p_current, get_tab_count());
  336. int pending_previous = current;
  337. current = p_current;
  338. Ref<StyleBox> sb = get_stylebox("panel");
  339. Vector<Control *> tabs = _get_tabs();
  340. for (int i = 0; i < tabs.size(); i++) {
  341. Control *c = tabs[i];
  342. if (i == current) {
  343. c->show();
  344. c->set_anchors_and_margins_preset(Control::PRESET_WIDE);
  345. if (tabs_visible)
  346. c->set_margin(MARGIN_TOP, _get_top_margin());
  347. c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP)));
  348. c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT)));
  349. c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT)));
  350. c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM)));
  351. } else
  352. c->hide();
  353. }
  354. _change_notify("current_tab");
  355. if (pending_previous == current)
  356. emit_signal("tab_selected", current);
  357. else {
  358. previous = pending_previous;
  359. emit_signal("tab_selected", current);
  360. emit_signal("tab_changed", current);
  361. }
  362. update();
  363. }
  364. int TabContainer::get_current_tab() const {
  365. return current;
  366. }
  367. int TabContainer::get_previous_tab() const {
  368. return previous;
  369. }
  370. Control *TabContainer::get_tab_control(int p_idx) const {
  371. Vector<Control *> tabs = _get_tabs();
  372. if (p_idx >= 0 && p_idx < tabs.size())
  373. return tabs[p_idx];
  374. else
  375. return NULL;
  376. }
  377. Control *TabContainer::get_current_tab_control() const {
  378. Vector<Control *> tabs = _get_tabs();
  379. if (current >= 0 && current < tabs.size())
  380. return tabs[current];
  381. else
  382. return NULL;
  383. }
  384. void TabContainer::remove_child_notify(Node *p_child) {
  385. Control::remove_child_notify(p_child);
  386. int tc = get_tab_count();
  387. if (current == tc - 1) {
  388. current--;
  389. if (current < 0)
  390. current = 0;
  391. else {
  392. call_deferred("set_current_tab", current);
  393. }
  394. }
  395. p_child->disconnect("renamed", this, "_child_renamed_callback");
  396. update();
  397. }
  398. void TabContainer::set_tab_align(TabAlign p_align) {
  399. ERR_FAIL_INDEX(p_align, 3);
  400. align = p_align;
  401. update();
  402. _change_notify("tab_align");
  403. }
  404. TabContainer::TabAlign TabContainer::get_tab_align() const {
  405. return align;
  406. }
  407. void TabContainer::set_tabs_visible(bool p_visibe) {
  408. if (p_visibe == tabs_visible)
  409. return;
  410. tabs_visible = p_visibe;
  411. Vector<Control *> tabs = _get_tabs();
  412. for (int i = 0; i < tabs.size(); i++) {
  413. Control *c = tabs[i];
  414. if (p_visibe)
  415. c->set_margin(MARGIN_TOP, _get_top_margin());
  416. else
  417. c->set_margin(MARGIN_TOP, 0);
  418. }
  419. update();
  420. }
  421. bool TabContainer::are_tabs_visible() const {
  422. return tabs_visible;
  423. }
  424. Control *TabContainer::_get_tab(int p_idx) const {
  425. return get_tab_control(p_idx);
  426. }
  427. void TabContainer::set_tab_title(int p_tab, const String &p_title) {
  428. Control *child = _get_tab(p_tab);
  429. ERR_FAIL_COND(!child);
  430. child->set_meta("_tab_name", p_title);
  431. }
  432. String TabContainer::get_tab_title(int p_tab) const {
  433. Control *child = _get_tab(p_tab);
  434. ERR_FAIL_COND_V(!child, "");
  435. if (child->has_meta("_tab_name"))
  436. return child->get_meta("_tab_name");
  437. else
  438. return child->get_name();
  439. }
  440. void TabContainer::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) {
  441. Control *child = _get_tab(p_tab);
  442. ERR_FAIL_COND(!child);
  443. child->set_meta("_tab_icon", p_icon);
  444. }
  445. Ref<Texture> TabContainer::get_tab_icon(int p_tab) const {
  446. Control *child = _get_tab(p_tab);
  447. ERR_FAIL_COND_V(!child, Ref<Texture>());
  448. if (child->has_meta("_tab_icon"))
  449. return child->get_meta("_tab_icon");
  450. else
  451. return Ref<Texture>();
  452. }
  453. void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
  454. Control *child = _get_tab(p_tab);
  455. ERR_FAIL_COND(!child);
  456. child->set_meta("_tab_disabled", p_disabled);
  457. update();
  458. }
  459. bool TabContainer::get_tab_disabled(int p_tab) const {
  460. Control *child = _get_tab(p_tab);
  461. ERR_FAIL_COND_V(!child, false);
  462. if (child->has_meta("_tab_disabled"))
  463. return child->get_meta("_tab_disabled");
  464. else
  465. return false;
  466. }
  467. void TabContainer::get_translatable_strings(List<String> *p_strings) const {
  468. Vector<Control *> tabs = _get_tabs();
  469. for (int i = 0; i < tabs.size(); i++) {
  470. Control *c = tabs[i];
  471. if (!c->has_meta("_tab_name"))
  472. continue;
  473. String name = c->get_meta("_tab_name");
  474. if (name != "")
  475. p_strings->push_back(name);
  476. }
  477. }
  478. Size2 TabContainer::get_minimum_size() const {
  479. Size2 ms;
  480. Vector<Control *> tabs = _get_tabs();
  481. for (int i = 0; i < tabs.size(); i++) {
  482. Control *c = tabs[i];
  483. if (!c->is_visible_in_tree())
  484. continue;
  485. Size2 cms = c->get_combined_minimum_size();
  486. ms.x = MAX(ms.x, cms.x);
  487. ms.y = MAX(ms.y, cms.y);
  488. }
  489. Ref<StyleBox> tab_bg = get_stylebox("tab_bg");
  490. Ref<StyleBox> tab_fg = get_stylebox("tab_fg");
  491. Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled");
  492. Ref<Font> font = get_font("font");
  493. ms.y += MAX(MAX(tab_bg->get_minimum_size().y, tab_fg->get_minimum_size().y), tab_disabled->get_minimum_size().y);
  494. ms.y += font->get_height();
  495. Ref<StyleBox> sb = get_stylebox("panel");
  496. ms += sb->get_minimum_size();
  497. return ms;
  498. }
  499. void TabContainer::set_popup(Node *p_popup) {
  500. ERR_FAIL_NULL(p_popup);
  501. popup = Object::cast_to<Popup>(p_popup);
  502. update();
  503. }
  504. Popup *TabContainer::get_popup() const {
  505. return popup;
  506. }
  507. void TabContainer::_bind_methods() {
  508. ClassDB::bind_method(D_METHOD("_gui_input"), &TabContainer::_gui_input);
  509. ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
  510. ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
  511. ClassDB::bind_method(D_METHOD("get_current_tab"), &TabContainer::get_current_tab);
  512. ClassDB::bind_method(D_METHOD("get_previous_tab"), &TabContainer::get_previous_tab);
  513. ClassDB::bind_method(D_METHOD("get_current_tab_control"), &TabContainer::get_current_tab_control);
  514. ClassDB::bind_method(D_METHOD("get_tab_control", "idx"), &TabContainer::get_tab_control);
  515. ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &TabContainer::set_tab_align);
  516. ClassDB::bind_method(D_METHOD("get_tab_align"), &TabContainer::get_tab_align);
  517. ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
  518. ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible);
  519. ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
  520. ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
  521. ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
  522. ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
  523. ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
  524. ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &TabContainer::get_tab_disabled);
  525. ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
  526. ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);
  527. ClassDB::bind_method(D_METHOD("_child_renamed_callback"), &TabContainer::_child_renamed_callback);
  528. ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab")));
  529. ADD_SIGNAL(MethodInfo("tab_selected", PropertyInfo(Variant::INT, "tab")));
  530. ADD_SIGNAL(MethodInfo("pre_popup_pressed"));
  531. ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_align", "get_tab_align");
  532. ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
  533. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
  534. BIND_ENUM_CONSTANT(ALIGN_LEFT);
  535. BIND_ENUM_CONSTANT(ALIGN_CENTER);
  536. BIND_ENUM_CONSTANT(ALIGN_RIGHT);
  537. }
  538. TabContainer::TabContainer() {
  539. first_tab_cache = 0;
  540. last_tab_cache = 0;
  541. buttons_visible_cache = false;
  542. tabs_ofs_cache = 0;
  543. current = 0;
  544. previous = 0;
  545. mouse_x_cache = 0;
  546. align = ALIGN_CENTER;
  547. tabs_visible = true;
  548. popup = NULL;
  549. }