button.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /*************************************************************************/
  2. /* button.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 "button.h"
  31. #include "core/string/translation.h"
  32. #include "servers/rendering_server.h"
  33. Size2 Button::get_minimum_size() const {
  34. Size2 minsize = text_buf->get_size();
  35. if (clip_text) {
  36. minsize.width = 0;
  37. }
  38. if (!expand_icon) {
  39. Ref<Texture2D> _icon;
  40. if (icon.is_null() && has_theme_icon("icon")) {
  41. _icon = Control::get_theme_icon("icon");
  42. } else {
  43. _icon = icon;
  44. }
  45. if (!_icon.is_null()) {
  46. minsize.height = MAX(minsize.height, _icon->get_height());
  47. if (icon_align != ALIGN_CENTER) {
  48. minsize.width += _icon->get_width();
  49. if (xl_text != "") {
  50. minsize.width += get_theme_constant("hseparation");
  51. }
  52. } else {
  53. minsize.width = MAX(minsize.width, _icon->get_width());
  54. }
  55. }
  56. }
  57. Ref<Font> font = get_theme_font("font");
  58. float font_height = font->get_height(get_theme_font_size("font_size"));
  59. minsize.height = MAX(font_height, minsize.height);
  60. return get_theme_stylebox("normal")->get_minimum_size() + minsize;
  61. }
  62. void Button::_set_internal_margin(Side p_side, float p_value) {
  63. _internal_margin[p_side] = p_value;
  64. }
  65. void Button::_notification(int p_what) {
  66. switch (p_what) {
  67. case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
  68. update();
  69. } break;
  70. case NOTIFICATION_TRANSLATION_CHANGED: {
  71. xl_text = tr(text);
  72. _shape();
  73. minimum_size_changed();
  74. update();
  75. } break;
  76. case NOTIFICATION_THEME_CHANGED: {
  77. _shape();
  78. minimum_size_changed();
  79. update();
  80. } break;
  81. case NOTIFICATION_DRAW: {
  82. RID ci = get_canvas_item();
  83. Size2 size = get_size();
  84. Color color;
  85. Color color_icon(1, 1, 1, 1);
  86. Ref<StyleBox> style = get_theme_stylebox("normal");
  87. bool rtl = is_layout_rtl();
  88. switch (get_draw_mode()) {
  89. case DRAW_NORMAL: {
  90. if (rtl && has_theme_stylebox("normal_mirrored")) {
  91. style = get_theme_stylebox("normal_mirrored");
  92. } else {
  93. style = get_theme_stylebox("normal");
  94. }
  95. if (!flat) {
  96. style->draw(ci, Rect2(Point2(0, 0), size));
  97. }
  98. color = get_theme_color("font_color");
  99. if (has_theme_color("icon_normal_color")) {
  100. color_icon = get_theme_color("icon_normal_color");
  101. }
  102. } break;
  103. case DRAW_HOVER_PRESSED: {
  104. if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) {
  105. if (rtl && has_theme_stylebox("hover_pressed_mirrored")) {
  106. style = get_theme_stylebox("hover_pressed_mirrored");
  107. } else {
  108. style = get_theme_stylebox("hover_pressed");
  109. }
  110. if (!flat) {
  111. style->draw(ci, Rect2(Point2(0, 0), size));
  112. }
  113. if (has_theme_color("font_hover_pressed_color")) {
  114. color = get_theme_color("font_hover_pressed_color");
  115. } else {
  116. color = get_theme_color("font_color");
  117. }
  118. if (has_theme_color("icon_hover_pressed_color")) {
  119. color_icon = get_theme_color("icon_hover_pressed_color");
  120. }
  121. break;
  122. }
  123. [[fallthrough]];
  124. }
  125. case DRAW_PRESSED: {
  126. if (rtl && has_theme_stylebox("pressed_mirrored")) {
  127. style = get_theme_stylebox("pressed_mirrored");
  128. } else {
  129. style = get_theme_stylebox("pressed");
  130. }
  131. if (!flat) {
  132. style->draw(ci, Rect2(Point2(0, 0), size));
  133. }
  134. if (has_theme_color("font_pressed_color")) {
  135. color = get_theme_color("font_pressed_color");
  136. } else {
  137. color = get_theme_color("font_color");
  138. }
  139. if (has_theme_color("icon_pressed_color")) {
  140. color_icon = get_theme_color("icon_pressed_color");
  141. }
  142. } break;
  143. case DRAW_HOVER: {
  144. if (rtl && has_theme_stylebox("hover_mirrored")) {
  145. style = get_theme_stylebox("hover_mirrored");
  146. } else {
  147. style = get_theme_stylebox("hover");
  148. }
  149. if (!flat) {
  150. style->draw(ci, Rect2(Point2(0, 0), size));
  151. }
  152. color = get_theme_color("font_hover_color");
  153. if (has_theme_color("icon_hover_color")) {
  154. color_icon = get_theme_color("icon_hover_color");
  155. }
  156. } break;
  157. case DRAW_DISABLED: {
  158. if (rtl && has_theme_stylebox("disabled_mirrored")) {
  159. style = get_theme_stylebox("disabled_mirrored");
  160. } else {
  161. style = get_theme_stylebox("disabled");
  162. }
  163. if (!flat) {
  164. style->draw(ci, Rect2(Point2(0, 0), size));
  165. }
  166. color = get_theme_color("font_disabled_color");
  167. if (has_theme_color("icon_disabled_color")) {
  168. color_icon = get_theme_color("icon_disabled_color");
  169. }
  170. } break;
  171. }
  172. if (has_focus()) {
  173. Ref<StyleBox> style2 = get_theme_stylebox("focus");
  174. style2->draw(ci, Rect2(Point2(), size));
  175. }
  176. Ref<Texture2D> _icon;
  177. if (icon.is_null() && has_theme_icon("icon")) {
  178. _icon = Control::get_theme_icon("icon");
  179. } else {
  180. _icon = icon;
  181. }
  182. Rect2 icon_region = Rect2();
  183. TextAlign icon_align_rtl_checked = icon_align;
  184. TextAlign align_rtl_checked = align;
  185. // Swap icon and text alignment sides if right-to-left layout is set.
  186. if (rtl) {
  187. if (icon_align == ALIGN_RIGHT) {
  188. icon_align_rtl_checked = ALIGN_LEFT;
  189. } else if (icon_align == ALIGN_LEFT) {
  190. icon_align_rtl_checked = ALIGN_RIGHT;
  191. }
  192. if (align == ALIGN_RIGHT) {
  193. align_rtl_checked = ALIGN_LEFT;
  194. } else if (align == ALIGN_LEFT) {
  195. align_rtl_checked = ALIGN_RIGHT;
  196. }
  197. }
  198. if (!_icon.is_null()) {
  199. int valign = size.height - style->get_minimum_size().y;
  200. if (is_disabled()) {
  201. color_icon.a = 0.4;
  202. }
  203. float icon_ofs_region = 0.0;
  204. Point2 style_offset;
  205. Size2 icon_size = _icon->get_size();
  206. if (icon_align_rtl_checked == ALIGN_LEFT) {
  207. style_offset.x = style->get_margin(SIDE_LEFT);
  208. if (_internal_margin[SIDE_LEFT] > 0) {
  209. icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
  210. }
  211. } else if (icon_align_rtl_checked == ALIGN_CENTER) {
  212. style_offset.x = 0.0;
  213. } else if (icon_align_rtl_checked == ALIGN_RIGHT) {
  214. style_offset.x = -style->get_margin(SIDE_RIGHT);
  215. if (_internal_margin[SIDE_RIGHT] > 0) {
  216. icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation");
  217. }
  218. }
  219. style_offset.y = style->get_margin(SIDE_TOP);
  220. if (expand_icon) {
  221. Size2 _size = get_size() - style->get_offset() * 2;
  222. _size.width -= get_theme_constant("hseparation") + icon_ofs_region;
  223. if (!clip_text && icon_align_rtl_checked != ALIGN_CENTER) {
  224. _size.width -= text_buf->get_size().width;
  225. }
  226. float icon_width = _icon->get_width() * _size.height / _icon->get_height();
  227. float icon_height = _size.height;
  228. if (icon_width > _size.width) {
  229. icon_width = _size.width;
  230. icon_height = _icon->get_height() * icon_width / _icon->get_width();
  231. }
  232. icon_size = Size2(icon_width, icon_height);
  233. }
  234. if (icon_align_rtl_checked == ALIGN_LEFT) {
  235. icon_region = Rect2(style_offset + Point2(icon_ofs_region, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  236. } else if (icon_align_rtl_checked == ALIGN_CENTER) {
  237. 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);
  238. } else {
  239. icon_region = Rect2(style_offset + Point2(icon_ofs_region + size.x - icon_size.x, Math::floor((valign - icon_size.y) * 0.5)), icon_size);
  240. }
  241. if (icon_region.size.width > 0) {
  242. draw_texture_rect_region(_icon, icon_region, Rect2(Point2(), _icon->get_size()), color_icon);
  243. }
  244. }
  245. Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2();
  246. if (align_rtl_checked == ALIGN_CENTER && icon_align_rtl_checked == ALIGN_CENTER) {
  247. icon_ofs.x = 0.0;
  248. }
  249. int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width;
  250. text_buf->set_width(clip_text ? text_clip : -1);
  251. int text_width = clip_text ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x;
  252. if (_internal_margin[SIDE_LEFT] > 0) {
  253. text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
  254. }
  255. if (_internal_margin[SIDE_RIGHT] > 0) {
  256. text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant("hseparation");
  257. }
  258. 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;
  259. switch (align_rtl_checked) {
  260. case ALIGN_LEFT: {
  261. if (icon_align_rtl_checked != ALIGN_LEFT) {
  262. icon_ofs.x = 0.0;
  263. }
  264. if (_internal_margin[SIDE_LEFT] > 0) {
  265. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation");
  266. } else {
  267. text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x;
  268. }
  269. text_ofs.y += style->get_offset().y;
  270. } break;
  271. case ALIGN_CENTER: {
  272. if (text_ofs.x < 0) {
  273. text_ofs.x = 0;
  274. }
  275. if (icon_align_rtl_checked == ALIGN_LEFT) {
  276. text_ofs += icon_ofs;
  277. }
  278. text_ofs += style->get_offset();
  279. } break;
  280. case ALIGN_RIGHT: {
  281. if (_internal_margin[SIDE_RIGHT] > 0) {
  282. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation");
  283. } else {
  284. text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width;
  285. }
  286. text_ofs.y += style->get_offset().y;
  287. if (icon_align_rtl_checked == ALIGN_RIGHT) {
  288. text_ofs.x -= icon_ofs.x;
  289. }
  290. } break;
  291. }
  292. Color font_outline_color = get_theme_color("font_outline_color");
  293. int outline_size = get_theme_constant("outline_size");
  294. if (outline_size > 0 && font_outline_color.a > 0) {
  295. text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color);
  296. }
  297. text_buf->draw(ci, text_ofs, color);
  298. } break;
  299. }
  300. }
  301. void Button::_shape() {
  302. Ref<Font> font = get_theme_font("font");
  303. int font_size = get_theme_font_size("font_size");
  304. text_buf->clear();
  305. if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
  306. text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR);
  307. } else {
  308. text_buf->set_direction((TextServer::Direction)text_direction);
  309. }
  310. text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
  311. }
  312. void Button::set_text(const String &p_text) {
  313. if (text != p_text) {
  314. text = p_text;
  315. xl_text = tr(text);
  316. _shape();
  317. update();
  318. minimum_size_changed();
  319. }
  320. }
  321. String Button::get_text() const {
  322. return text;
  323. }
  324. void Button::set_text_direction(Control::TextDirection p_text_direction) {
  325. ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
  326. if (text_direction != p_text_direction) {
  327. text_direction = p_text_direction;
  328. _shape();
  329. update();
  330. }
  331. }
  332. Control::TextDirection Button::get_text_direction() const {
  333. return text_direction;
  334. }
  335. void Button::clear_opentype_features() {
  336. opentype_features.clear();
  337. _shape();
  338. update();
  339. }
  340. void Button::set_opentype_feature(const String &p_name, int p_value) {
  341. int32_t tag = TS->name_to_tag(p_name);
  342. if (!opentype_features.has(tag) || (int)opentype_features[tag] != p_value) {
  343. opentype_features[tag] = p_value;
  344. _shape();
  345. update();
  346. }
  347. }
  348. int Button::get_opentype_feature(const String &p_name) const {
  349. int32_t tag = TS->name_to_tag(p_name);
  350. if (!opentype_features.has(tag)) {
  351. return -1;
  352. }
  353. return opentype_features[tag];
  354. }
  355. void Button::set_language(const String &p_language) {
  356. if (language != p_language) {
  357. language = p_language;
  358. _shape();
  359. update();
  360. }
  361. }
  362. String Button::get_language() const {
  363. return language;
  364. }
  365. void Button::set_icon(const Ref<Texture2D> &p_icon) {
  366. if (icon != p_icon) {
  367. icon = p_icon;
  368. update();
  369. minimum_size_changed();
  370. }
  371. }
  372. Ref<Texture2D> Button::get_icon() const {
  373. return icon;
  374. }
  375. void Button::set_expand_icon(bool p_expand_icon) {
  376. if (expand_icon != p_expand_icon) {
  377. expand_icon = p_expand_icon;
  378. update();
  379. minimum_size_changed();
  380. }
  381. }
  382. bool Button::is_expand_icon() const {
  383. return expand_icon;
  384. }
  385. void Button::set_flat(bool p_flat) {
  386. if (flat != p_flat) {
  387. flat = p_flat;
  388. update();
  389. }
  390. }
  391. bool Button::is_flat() const {
  392. return flat;
  393. }
  394. void Button::set_clip_text(bool p_clip_text) {
  395. if (clip_text != p_clip_text) {
  396. clip_text = p_clip_text;
  397. update();
  398. minimum_size_changed();
  399. }
  400. }
  401. bool Button::get_clip_text() const {
  402. return clip_text;
  403. }
  404. void Button::set_text_align(TextAlign p_align) {
  405. if (align != p_align) {
  406. align = p_align;
  407. update();
  408. }
  409. }
  410. Button::TextAlign Button::get_text_align() const {
  411. return align;
  412. }
  413. void Button::set_icon_align(TextAlign p_align) {
  414. icon_align = p_align;
  415. minimum_size_changed();
  416. update();
  417. }
  418. Button::TextAlign Button::get_icon_align() const {
  419. return icon_align;
  420. }
  421. bool Button::_set(const StringName &p_name, const Variant &p_value) {
  422. String str = p_name;
  423. if (str.begins_with("opentype_features/")) {
  424. String name = str.get_slicec('/', 1);
  425. int32_t tag = TS->name_to_tag(name);
  426. double value = p_value;
  427. if (value == -1) {
  428. if (opentype_features.has(tag)) {
  429. opentype_features.erase(tag);
  430. _shape();
  431. update();
  432. }
  433. } else {
  434. if ((double)opentype_features[tag] != value) {
  435. opentype_features[tag] = value;
  436. _shape();
  437. update();
  438. }
  439. }
  440. notify_property_list_changed();
  441. return true;
  442. }
  443. return false;
  444. }
  445. bool Button::_get(const StringName &p_name, Variant &r_ret) const {
  446. String str = p_name;
  447. if (str.begins_with("opentype_features/")) {
  448. String name = str.get_slicec('/', 1);
  449. int32_t tag = TS->name_to_tag(name);
  450. if (opentype_features.has(tag)) {
  451. r_ret = opentype_features[tag];
  452. return true;
  453. } else {
  454. r_ret = -1;
  455. return true;
  456. }
  457. }
  458. return false;
  459. }
  460. void Button::_get_property_list(List<PropertyInfo> *p_list) const {
  461. for (const Variant *ftr = opentype_features.next(nullptr); ftr != nullptr; ftr = opentype_features.next(ftr)) {
  462. String name = TS->tag_to_name(*ftr);
  463. p_list->push_back(PropertyInfo(Variant::FLOAT, "opentype_features/" + name));
  464. }
  465. p_list->push_back(PropertyInfo(Variant::NIL, "opentype_features/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
  466. }
  467. void Button::_bind_methods() {
  468. ClassDB::bind_method(D_METHOD("set_text", "text"), &Button::set_text);
  469. ClassDB::bind_method(D_METHOD("get_text"), &Button::get_text);
  470. ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &Button::set_text_direction);
  471. ClassDB::bind_method(D_METHOD("get_text_direction"), &Button::get_text_direction);
  472. ClassDB::bind_method(D_METHOD("set_opentype_feature", "tag", "value"), &Button::set_opentype_feature);
  473. ClassDB::bind_method(D_METHOD("get_opentype_feature", "tag"), &Button::get_opentype_feature);
  474. ClassDB::bind_method(D_METHOD("clear_opentype_features"), &Button::clear_opentype_features);
  475. ClassDB::bind_method(D_METHOD("set_language", "language"), &Button::set_language);
  476. ClassDB::bind_method(D_METHOD("get_language"), &Button::get_language);
  477. ClassDB::bind_method(D_METHOD("set_button_icon", "texture"), &Button::set_icon);
  478. ClassDB::bind_method(D_METHOD("get_button_icon"), &Button::get_icon);
  479. ClassDB::bind_method(D_METHOD("set_flat", "enabled"), &Button::set_flat);
  480. ClassDB::bind_method(D_METHOD("is_flat"), &Button::is_flat);
  481. ClassDB::bind_method(D_METHOD("set_clip_text", "enabled"), &Button::set_clip_text);
  482. ClassDB::bind_method(D_METHOD("get_clip_text"), &Button::get_clip_text);
  483. ClassDB::bind_method(D_METHOD("set_text_align", "align"), &Button::set_text_align);
  484. ClassDB::bind_method(D_METHOD("get_text_align"), &Button::get_text_align);
  485. ClassDB::bind_method(D_METHOD("set_icon_align", "icon_align"), &Button::set_icon_align);
  486. ClassDB::bind_method(D_METHOD("get_icon_align"), &Button::get_icon_align);
  487. ClassDB::bind_method(D_METHOD("set_expand_icon"), &Button::set_expand_icon);
  488. ClassDB::bind_method(D_METHOD("is_expand_icon"), &Button::is_expand_icon);
  489. BIND_ENUM_CONSTANT(ALIGN_LEFT);
  490. BIND_ENUM_CONSTANT(ALIGN_CENTER);
  491. BIND_ENUM_CONSTANT(ALIGN_RIGHT);
  492. ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
  493. ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
  494. ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
  495. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon");
  496. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat");
  497. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text");
  498. ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_align", "get_text_align");
  499. ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_icon_align", "get_icon_align");
  500. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand_icon"), "set_expand_icon", "is_expand_icon");
  501. }
  502. Button::Button(const String &p_text) {
  503. text_buf.instantiate();
  504. text_buf->set_flags(TextServer::BREAK_MANDATORY);
  505. set_mouse_filter(MOUSE_FILTER_STOP);
  506. set_text(p_text);
  507. }
  508. Button::~Button() {
  509. }