button.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. /*************************************************************************/
  2. /* button.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "button.h"
  31. #include "core/string/translation.h"
  32. #include "servers/rendering_server.h"
  33. Size2 Button::get_minimum_size() const {
  34. Ref<Texture2D> _icon;
  35. if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
  36. _icon = Control::get_theme_icon(SNAME("icon"));
  37. } else {
  38. _icon = icon;
  39. }
  40. return get_minimum_size_for_text_and_icon("", _icon);
  41. }
  42. void Button::_set_internal_margin(Side p_side, float p_value) {
  43. _internal_margin[p_side] = p_value;
  44. }
  45. void Button::_notification(int p_what) {
  46. switch (p_what) {
  47. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
  48. update();
  49. } break;
  50. case NOTIFICATION_TRANSLATION_CHANGED: {
  51. xl_text = atr(text);
  52. _shape();
  53. update_minimum_size();
  54. update();
  55. } break;
  56. case NOTIFICATION_THEME_CHANGED: {
  57. _shape();
  58. update_minimum_size();
  59. update();
  60. } break;
  61. case NOTIFICATION_DRAW: {
  62. RID ci = get_canvas_item();
  63. Size2 size = get_size();
  64. Color color;
  65. Color color_icon(1, 1, 1, 1);
  66. Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
  67. bool rtl = is_layout_rtl();
  68. switch (get_draw_mode()) {
  69. case DRAW_NORMAL: {
  70. if (rtl && has_theme_stylebox(SNAME("normal_mirrored"))) {
  71. style = get_theme_stylebox(SNAME("normal_mirrored"));
  72. } else {
  73. style = get_theme_stylebox(SNAME("normal"));
  74. }
  75. if (!flat) {
  76. style->draw(ci, Rect2(Point2(0, 0), size));
  77. }
  78. // Focus colors only take precedence over normal state.
  79. if (has_focus()) {
  80. color = get_theme_color(SNAME("font_focus_color"));
  81. if (has_theme_color(SNAME("icon_focus_color"))) {
  82. color_icon = get_theme_color(SNAME("icon_focus_color"));
  83. }
  84. } else {
  85. color = get_theme_color(SNAME("font_color"));
  86. if (has_theme_color(SNAME("icon_normal_color"))) {
  87. color_icon = get_theme_color(SNAME("icon_normal_color"));
  88. }
  89. }
  90. } break;
  91. case DRAW_HOVER_PRESSED: {
  92. // Edge case for CheckButton and CheckBox.
  93. if (has_theme_stylebox("hover_pressed")) {
  94. if (rtl && has_theme_stylebox(SNAME("hover_pressed_mirrored"))) {
  95. style = get_theme_stylebox(SNAME("hover_pressed_mirrored"));
  96. } else {
  97. style = get_theme_stylebox(SNAME("hover_pressed"));
  98. }
  99. if (!flat) {
  100. style->draw(ci, Rect2(Point2(0, 0), size));
  101. }
  102. if (has_theme_color(SNAME("font_hover_pressed_color"))) {
  103. color = get_theme_color(SNAME("font_hover_pressed_color"));
  104. }
  105. if (has_theme_color(SNAME("icon_hover_pressed_color"))) {
  106. color_icon = get_theme_color(SNAME("icon_hover_pressed_color"));
  107. }
  108. break;
  109. }
  110. [[fallthrough]];
  111. }
  112. case DRAW_PRESSED: {
  113. if (rtl && has_theme_stylebox(SNAME("pressed_mirrored"))) {
  114. style = get_theme_stylebox(SNAME("pressed_mirrored"));
  115. } else {
  116. style = get_theme_stylebox(SNAME("pressed"));
  117. }
  118. if (!flat) {
  119. style->draw(ci, Rect2(Point2(0, 0), size));
  120. }
  121. if (has_theme_color(SNAME("font_pressed_color"))) {
  122. color = get_theme_color(SNAME("font_pressed_color"));
  123. } else {
  124. color = get_theme_color(SNAME("font_color"));
  125. }
  126. if (has_theme_color(SNAME("icon_pressed_color"))) {
  127. color_icon = get_theme_color(SNAME("icon_pressed_color"));
  128. }
  129. } break;
  130. case DRAW_HOVER: {
  131. if (rtl && has_theme_stylebox(SNAME("hover_mirrored"))) {
  132. style = get_theme_stylebox(SNAME("hover_mirrored"));
  133. } else {
  134. style = get_theme_stylebox(SNAME("hover"));
  135. }
  136. if (!flat) {
  137. style->draw(ci, Rect2(Point2(0, 0), size));
  138. }
  139. color = get_theme_color(SNAME("font_hover_color"));
  140. if (has_theme_color(SNAME("icon_hover_color"))) {
  141. color_icon = get_theme_color(SNAME("icon_hover_color"));
  142. }
  143. } break;
  144. case DRAW_DISABLED: {
  145. if (rtl && has_theme_stylebox(SNAME("disabled_mirrored"))) {
  146. style = get_theme_stylebox(SNAME("disabled_mirrored"));
  147. } else {
  148. style = get_theme_stylebox(SNAME("disabled"));
  149. }
  150. if (!flat) {
  151. style->draw(ci, Rect2(Point2(0, 0), size));
  152. }
  153. color = get_theme_color(SNAME("font_disabled_color"));
  154. if (has_theme_color(SNAME("icon_disabled_color"))) {
  155. color_icon = get_theme_color(SNAME("icon_disabled_color"));
  156. } else {
  157. color_icon.a = 0.4;
  158. }
  159. } break;
  160. }
  161. if (has_focus()) {
  162. Ref<StyleBox> style2 = get_theme_stylebox(SNAME("focus"));
  163. style2->draw(ci, Rect2(Point2(), size));
  164. }
  165. Ref<Texture2D> _icon;
  166. if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
  167. _icon = Control::get_theme_icon(SNAME("icon"));
  168. } else {
  169. _icon = icon;
  170. }
  171. Rect2 icon_region = Rect2();
  172. HorizontalAlignment icon_align_rtl_checked = icon_alignment;
  173. HorizontalAlignment align_rtl_checked = alignment;
  174. // Swap icon and text alignment sides if right-to-left layout is set.
  175. if (rtl) {
  176. if (icon_alignment == HORIZONTAL_ALIGNMENT_RIGHT) {
  177. icon_align_rtl_checked = HORIZONTAL_ALIGNMENT_LEFT;
  178. } else if (icon_alignment == HORIZONTAL_ALIGNMENT_LEFT) {
  179. icon_align_rtl_checked = HORIZONTAL_ALIGNMENT_RIGHT;
  180. }
  181. if (alignment == HORIZONTAL_ALIGNMENT_RIGHT) {
  182. align_rtl_checked = HORIZONTAL_ALIGNMENT_LEFT;
  183. } else if (alignment == HORIZONTAL_ALIGNMENT_LEFT) {
  184. align_rtl_checked = HORIZONTAL_ALIGNMENT_RIGHT;
  185. }
  186. }
  187. if (!_icon.is_null()) {
  188. int valign = size.height - style->get_minimum_size().y;
  189. float icon_ofs_region = 0.0;
  190. Point2 style_offset;
  191. Size2 icon_size = _icon->get_size();
  192. if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
  193. style_offset.x = style->get_margin(SIDE_LEFT);
  194. if (_internal_margin[SIDE_LEFT] > 0) {
  195. icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("h_separation"));
  196. }
  197. } else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
  198. style_offset.x = 0.0;
  199. } else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_RIGHT) {
  200. style_offset.x = -style->get_margin(SIDE_RIGHT);
  201. if (_internal_margin[SIDE_RIGHT] > 0) {
  202. icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("h_separation"));
  203. }
  204. }
  205. style_offset.y = style->get_margin(SIDE_TOP);
  206. if (expand_icon) {
  207. Size2 _size = get_size() - style->get_offset() * 2;
  208. int icon_text_separation = text.is_empty() ? 0 : get_theme_constant(SNAME("h_separation"));
  209. _size.width -= icon_text_separation + icon_ofs_region;
  210. if (!clip_text && icon_align_rtl_checked != HORIZONTAL_ALIGNMENT_CENTER) {
  211. _size.width -= text_buf->get_size().width;
  212. }
  213. float icon_width = _icon->get_width() * _size.height / _icon->get_height();
  214. float icon_height = _size.height;
  215. if (icon_width > _size.width) {
  216. icon_width = _size.width;
  217. icon_height = _icon->get_height() * icon_width / _icon->get_width();
  218. }
  219. icon_size = Size2(icon_width, icon_height);
  220. }
  221. if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
  222. icon_region = Rect2(style_offset + Point2(icon_ofs_region, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  223. } else if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
  224. icon_region = Rect2(style_offset + Point2(icon_ofs_region + Math::floor((size.x - icon_size.x) * 0.5), Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  225. } else {
  226. icon_region = Rect2(style_offset + Point2(icon_ofs_region + size.x - icon_size.x, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  227. }
  228. if (icon_region.size.width > 0) {
  229. Rect2 icon_region_rounded = Rect2(icon_region.position.round(), icon_region.size.round());
  230. draw_texture_rect(_icon, icon_region_rounded, false, color_icon);
  231. }
  232. }
  233. Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant(SNAME("h_separation")), 0) : Point2();
  234. if (align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER && icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_CENTER) {
  235. icon_ofs.x = 0.0;
  236. }
  237. int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width;
  238. text_buf->set_width((clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? text_clip : -1);
  239. int text_width = MAX(1, (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x);
  240. if (_internal_margin[SIDE_LEFT] > 0) {
  241. text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("h_separation"));
  242. }
  243. if (_internal_margin[SIDE_RIGHT] > 0) {
  244. text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant(SNAME("h_separation"));
  245. }
  246. Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0;
  247. text_buf->set_alignment(align_rtl_checked);
  248. text_buf->set_width(text_width);
  249. switch (align_rtl_checked) {
  250. case HORIZONTAL_ALIGNMENT_FILL:
  251. case HORIZONTAL_ALIGNMENT_LEFT: {
  252. if (icon_align_rtl_checked != HORIZONTAL_ALIGNMENT_LEFT) {
  253. icon_ofs.x = 0.0;
  254. }
  255. if (_internal_margin[SIDE_LEFT] > 0) {
  256. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("h_separation"));
  257. } else {
  258. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x;
  259. }
  260. text_ofs.y += style->get_offset().y;
  261. } break;
  262. case HORIZONTAL_ALIGNMENT_CENTER: {
  263. if (text_ofs.x < 0) {
  264. text_ofs.x = 0;
  265. }
  266. if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_LEFT) {
  267. text_ofs += icon_ofs;
  268. }
  269. text_ofs += style->get_offset();
  270. } break;
  271. case HORIZONTAL_ALIGNMENT_RIGHT: {
  272. if (_internal_margin[SIDE_RIGHT] > 0) {
  273. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("h_separation"));
  274. } else {
  275. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width;
  276. }
  277. text_ofs.y += style->get_offset().y;
  278. if (icon_align_rtl_checked == HORIZONTAL_ALIGNMENT_RIGHT) {
  279. text_ofs.x -= icon_ofs.x;
  280. }
  281. } break;
  282. }
  283. Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
  284. int outline_size = get_theme_constant(SNAME("outline_size"));
  285. if (outline_size > 0 && font_outline_color.a > 0) {
  286. text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color);
  287. }
  288. text_buf->draw(ci, text_ofs, color);
  289. } break;
  290. }
  291. }
  292. Size2 Button::get_minimum_size_for_text_and_icon(const String &p_text, Ref<Texture2D> p_icon) const {
  293. Ref<TextParagraph> paragraph;
  294. if (p_text.is_empty()) {
  295. paragraph = text_buf;
  296. } else {
  297. paragraph.instantiate();
  298. const_cast<Button *>(this)->_shape(paragraph, p_text);
  299. }
  300. Size2 minsize = paragraph->get_size();
  301. if (clip_text || overrun_behavior != TextServer::OVERRUN_NO_TRIMMING) {
  302. minsize.width = 0;
  303. }
  304. if (!expand_icon && !p_icon.is_null()) {
  305. minsize.height = MAX(minsize.height, p_icon->get_height());
  306. if (icon_alignment != HORIZONTAL_ALIGNMENT_CENTER) {
  307. minsize.width += p_icon->get_width();
  308. if (!xl_text.is_empty() || !p_text.is_empty()) {
  309. minsize.width += get_theme_constant(SNAME("hseparation"));
  310. }
  311. } else {
  312. minsize.width = MAX(minsize.width, p_icon->get_width());
  313. }
  314. }
  315. if (!xl_text.is_empty() || !p_text.is_empty()) {
  316. Ref<Font> font = get_theme_font(SNAME("font"));
  317. float font_height = font->get_height(get_theme_font_size(SNAME("font_size")));
  318. minsize.height = MAX(font_height, minsize.height);
  319. }
  320. return get_theme_stylebox(SNAME("normal"))->get_minimum_size() + minsize;
  321. }
  322. void Button::_shape(Ref<TextParagraph> p_paragraph, String p_text) {
  323. if (p_paragraph.is_null()) {
  324. p_paragraph = text_buf;
  325. }
  326. if (p_text.is_empty()) {
  327. p_text = xl_text;
  328. }
  329. Ref<Font> font = get_theme_font(SNAME("font"));
  330. int font_size = get_theme_font_size(SNAME("font_size"));
  331. p_paragraph->clear();
  332. if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
  333. p_paragraph->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
  334. } else {
  335. p_paragraph->set_direction((TextServer::Direction)text_direction);
  336. }
  337. p_paragraph->add_string(p_text, font, font_size, language);
  338. p_paragraph->set_text_overrun_behavior(overrun_behavior);
  339. }
  340. void Button::set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior) {
  341. if (overrun_behavior != p_behavior) {
  342. overrun_behavior = p_behavior;
  343. _shape();
  344. update();
  345. update_minimum_size();
  346. }
  347. }
  348. TextServer::OverrunBehavior Button::get_text_overrun_behavior() const {
  349. return overrun_behavior;
  350. }
  351. void Button::set_text(const String &p_text) {
  352. if (text != p_text) {
  353. text = p_text;
  354. xl_text = atr(text);
  355. _shape();
  356. update();
  357. update_minimum_size();
  358. }
  359. }
  360. String Button::get_text() const {
  361. return text;
  362. }
  363. void Button::set_text_direction(Control::TextDirection p_text_direction) {
  364. ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
  365. if (text_direction != p_text_direction) {
  366. text_direction = p_text_direction;
  367. _shape();
  368. update();
  369. }
  370. }
  371. Control::TextDirection Button::get_text_direction() const {
  372. return text_direction;
  373. }
  374. void Button::set_language(const String &p_language) {
  375. if (language != p_language) {
  376. language = p_language;
  377. _shape();
  378. update();
  379. }
  380. }
  381. String Button::get_language() const {
  382. return language;
  383. }
  384. void Button::set_icon(const Ref<Texture2D> &p_icon) {
  385. if (icon != p_icon) {
  386. icon = p_icon;
  387. update();
  388. update_minimum_size();
  389. }
  390. }
  391. Ref<Texture2D> Button::get_icon() const {
  392. return icon;
  393. }
  394. void Button::set_expand_icon(bool p_enabled) {
  395. if (expand_icon != p_enabled) {
  396. expand_icon = p_enabled;
  397. update();
  398. update_minimum_size();
  399. }
  400. }
  401. bool Button::is_expand_icon() const {
  402. return expand_icon;
  403. }
  404. void Button::set_flat(bool p_enabled) {
  405. if (flat != p_enabled) {
  406. flat = p_enabled;
  407. update();
  408. }
  409. }
  410. bool Button::is_flat() const {
  411. return flat;
  412. }
  413. void Button::set_clip_text(bool p_enabled) {
  414. if (clip_text != p_enabled) {
  415. clip_text = p_enabled;
  416. update();
  417. update_minimum_size();
  418. }
  419. }
  420. bool Button::get_clip_text() const {
  421. return clip_text;
  422. }
  423. void Button::set_text_alignment(HorizontalAlignment p_alignment) {
  424. if (alignment != p_alignment) {
  425. alignment = p_alignment;
  426. update();
  427. }
  428. }
  429. HorizontalAlignment Button::get_text_alignment() const {
  430. return alignment;
  431. }
  432. void Button::set_icon_alignment(HorizontalAlignment p_alignment) {
  433. icon_alignment = p_alignment;
  434. update_minimum_size();
  435. update();
  436. }
  437. HorizontalAlignment Button::get_icon_alignment() const {
  438. return icon_alignment;
  439. }
  440. void Button::_bind_methods() {
  441. ClassDB::bind_method(D_METHOD("set_text", "text"), &Button::set_text);
  442. ClassDB::bind_method(D_METHOD("get_text"), &Button::get_text);
  443. ClassDB::bind_method(D_METHOD("set_text_overrun_behavior", "overrun_behavior"), &Button::set_text_overrun_behavior);
  444. ClassDB::bind_method(D_METHOD("get_text_overrun_behavior"), &Button::get_text_overrun_behavior);
  445. ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &Button::set_text_direction);
  446. ClassDB::bind_method(D_METHOD("get_text_direction"), &Button::get_text_direction);
  447. ClassDB::bind_method(D_METHOD("set_language", "language"), &Button::set_language);
  448. ClassDB::bind_method(D_METHOD("get_language"), &Button::get_language);
  449. ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon);
  450. ClassDB::bind_method(D_METHOD("get_button_icon"), &Button::get_icon);
  451. ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &Button::set_flat);
  452. ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat);
  453. ClassDB::bind_method(D_METHOD("set_clip_text", "enabled"), &Button::set_clip_text);
  454. ClassDB::bind_method(D_METHOD("get_clip_text"), &Button::get_clip_text);
  455. ClassDB::bind_method(D_METHOD("set_text_alignment", "alignment"), &Button::set_text_alignment);
  456. ClassDB::bind_method(D_METHOD("get_text_alignment"), &Button::get_text_alignment);
  457. ClassDB::bind_method(D_METHOD("set_icon_alignment", "icon_alignment"), &Button::set_icon_alignment);
  458. ClassDB::bind_method(D_METHOD("get_icon_alignment"), &Button::get_icon_alignment);
  459. ClassDB::bind_method(D_METHOD("set_expand_icon", "enabled"), &Button::set_expand_icon);
  460. ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon);
  461. ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
  462. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon");
  463. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
  464. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
  465. ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_alignment", "get_text_alignment");
  466. ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
  467. ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_icon_alignment", "get_icon_alignment");
  468. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_icon"), "set_expand_icon", "is_expand_icon");
  469. ADD_GROUP("BiDi", "");
  470. ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
  471. ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
  472. }
  473. Button::Button(const String &p_text) {
  474. text_buf.instantiate();
  475. text_buf->set_break_flags(TextServer::BREAK_MANDATORY);
  476. set_mouse_filter(MOUSE_FILTER_STOP);
  477. set_text(p_text);
  478. }
  479. Button::~Button() {
  480. }