control.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**************************************************************************/
  2. /* control.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef CONTROL_H
  31. #define CONTROL_H
  32. #include "core/math/transform_2d.h"
  33. #include "core/object/gdvirtual.gen.inc"
  34. #include "core/templates/rid.h"
  35. #include "scene/main/canvas_item.h"
  36. #include "scene/main/timer.h"
  37. #include "scene/resources/theme.h"
  38. class Viewport;
  39. class Label;
  40. class Panel;
  41. class ThemeOwner;
  42. class Control : public CanvasItem {
  43. GDCLASS(Control, CanvasItem);
  44. public:
  45. enum Anchor {
  46. ANCHOR_BEGIN = 0,
  47. ANCHOR_END = 1
  48. };
  49. enum GrowDirection {
  50. GROW_DIRECTION_BEGIN,
  51. GROW_DIRECTION_END,
  52. GROW_DIRECTION_BOTH
  53. };
  54. enum FocusMode {
  55. FOCUS_NONE,
  56. FOCUS_CLICK,
  57. FOCUS_ALL
  58. };
  59. enum SizeFlags {
  60. SIZE_SHRINK_BEGIN = 0,
  61. SIZE_FILL = 1,
  62. SIZE_EXPAND = 2,
  63. SIZE_SHRINK_CENTER = 4,
  64. SIZE_SHRINK_END = 8,
  65. SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
  66. };
  67. enum MouseFilter {
  68. MOUSE_FILTER_STOP,
  69. MOUSE_FILTER_PASS,
  70. MOUSE_FILTER_IGNORE
  71. };
  72. enum CursorShape {
  73. CURSOR_ARROW,
  74. CURSOR_IBEAM,
  75. CURSOR_POINTING_HAND,
  76. CURSOR_CROSS,
  77. CURSOR_WAIT,
  78. CURSOR_BUSY,
  79. CURSOR_DRAG,
  80. CURSOR_CAN_DROP,
  81. CURSOR_FORBIDDEN,
  82. CURSOR_VSIZE,
  83. CURSOR_HSIZE,
  84. CURSOR_BDIAGSIZE,
  85. CURSOR_FDIAGSIZE,
  86. CURSOR_MOVE,
  87. CURSOR_VSPLIT,
  88. CURSOR_HSPLIT,
  89. CURSOR_HELP,
  90. CURSOR_MAX
  91. };
  92. enum LayoutPreset {
  93. PRESET_TOP_LEFT,
  94. PRESET_TOP_RIGHT,
  95. PRESET_BOTTOM_LEFT,
  96. PRESET_BOTTOM_RIGHT,
  97. PRESET_CENTER_LEFT,
  98. PRESET_CENTER_TOP,
  99. PRESET_CENTER_RIGHT,
  100. PRESET_CENTER_BOTTOM,
  101. PRESET_CENTER,
  102. PRESET_LEFT_WIDE,
  103. PRESET_TOP_WIDE,
  104. PRESET_RIGHT_WIDE,
  105. PRESET_BOTTOM_WIDE,
  106. PRESET_VCENTER_WIDE,
  107. PRESET_HCENTER_WIDE,
  108. PRESET_FULL_RECT
  109. };
  110. enum LayoutPresetMode {
  111. PRESET_MODE_MINSIZE,
  112. PRESET_MODE_KEEP_WIDTH,
  113. PRESET_MODE_KEEP_HEIGHT,
  114. PRESET_MODE_KEEP_SIZE
  115. };
  116. enum LayoutMode {
  117. LAYOUT_MODE_POSITION,
  118. LAYOUT_MODE_ANCHORS,
  119. LAYOUT_MODE_CONTAINER,
  120. LAYOUT_MODE_UNCONTROLLED,
  121. };
  122. enum LayoutDirection {
  123. LAYOUT_DIRECTION_INHERITED,
  124. LAYOUT_DIRECTION_LOCALE,
  125. LAYOUT_DIRECTION_LTR,
  126. LAYOUT_DIRECTION_RTL
  127. };
  128. enum TextDirection {
  129. TEXT_DIRECTION_AUTO = TextServer::DIRECTION_AUTO,
  130. TEXT_DIRECTION_LTR = TextServer::DIRECTION_LTR,
  131. TEXT_DIRECTION_RTL = TextServer::DIRECTION_RTL,
  132. TEXT_DIRECTION_INHERITED = TextServer::DIRECTION_INHERITED,
  133. };
  134. private:
  135. struct CComparator {
  136. bool operator()(const Control *p_a, const Control *p_b) const {
  137. if (p_a->get_canvas_layer() == p_b->get_canvas_layer()) {
  138. return p_b->is_greater_than(p_a);
  139. }
  140. return p_a->get_canvas_layer() < p_b->get_canvas_layer();
  141. }
  142. };
  143. // This Data struct is to avoid namespace pollution in derived classes.
  144. struct Data {
  145. // Global relations.
  146. List<Control *>::Element *RI = nullptr;
  147. Control *parent_control = nullptr;
  148. Window *parent_window = nullptr;
  149. CanvasItem *parent_canvas_item = nullptr;
  150. Callable forward_drag;
  151. Callable forward_can_drop;
  152. Callable forward_drop;
  153. // Positioning and sizing.
  154. LayoutMode stored_layout_mode = LayoutMode::LAYOUT_MODE_POSITION;
  155. bool stored_use_custom_anchors = false;
  156. real_t offset[4] = { 0.0, 0.0, 0.0, 0.0 };
  157. real_t anchor[4] = { ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_BEGIN };
  158. FocusMode focus_mode = FOCUS_NONE;
  159. GrowDirection h_grow = GROW_DIRECTION_END;
  160. GrowDirection v_grow = GROW_DIRECTION_END;
  161. real_t rotation = 0.0;
  162. Vector2 scale = Vector2(1, 1);
  163. Vector2 pivot_offset;
  164. Point2 pos_cache;
  165. Size2 size_cache;
  166. Size2 minimum_size_cache;
  167. bool minimum_size_valid = false;
  168. Size2 last_minimum_size;
  169. bool updating_last_minimum_size = false;
  170. bool block_minimum_size_adjust = false;
  171. bool size_warning = true;
  172. // Container sizing.
  173. BitField<SizeFlags> h_size_flags = SIZE_FILL;
  174. BitField<SizeFlags> v_size_flags = SIZE_FILL;
  175. real_t expand = 1.0;
  176. Point2 custom_minimum_size;
  177. // Input events and rendering.
  178. MouseFilter mouse_filter = MOUSE_FILTER_STOP;
  179. bool force_pass_scroll_events = true;
  180. bool clip_contents = false;
  181. bool disable_visibility_clip = false;
  182. CursorShape default_cursor = CURSOR_ARROW;
  183. // Focus.
  184. NodePath focus_neighbor[4];
  185. NodePath focus_next;
  186. NodePath focus_prev;
  187. ObjectID shortcut_context;
  188. // Theming.
  189. ThemeOwner *theme_owner = nullptr;
  190. Ref<Theme> theme;
  191. StringName theme_type_variation;
  192. bool bulk_theme_override = false;
  193. Theme::ThemeIconMap theme_icon_override;
  194. Theme::ThemeStyleMap theme_style_override;
  195. Theme::ThemeFontMap theme_font_override;
  196. Theme::ThemeFontSizeMap theme_font_size_override;
  197. Theme::ThemeColorMap theme_color_override;
  198. Theme::ThemeConstantMap theme_constant_override;
  199. mutable HashMap<StringName, Theme::ThemeIconMap> theme_icon_cache;
  200. mutable HashMap<StringName, Theme::ThemeStyleMap> theme_style_cache;
  201. mutable HashMap<StringName, Theme::ThemeFontMap> theme_font_cache;
  202. mutable HashMap<StringName, Theme::ThemeFontSizeMap> theme_font_size_cache;
  203. mutable HashMap<StringName, Theme::ThemeColorMap> theme_color_cache;
  204. mutable HashMap<StringName, Theme::ThemeConstantMap> theme_constant_cache;
  205. // Internationalization.
  206. LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED;
  207. bool is_rtl_dirty = true;
  208. bool is_rtl = false;
  209. bool auto_translate = true;
  210. bool localize_numeral_system = true;
  211. // Extra properties.
  212. String tooltip;
  213. } data;
  214. // Dynamic properties.
  215. static constexpr unsigned properties_managed_by_container_count = 12;
  216. static String properties_managed_by_container[properties_managed_by_container_count];
  217. // Global relations.
  218. friend class Viewport;
  219. // Positioning and sizing.
  220. void _update_canvas_item_transform();
  221. Transform2D _get_internal_transform() const;
  222. void _set_anchor(Side p_side, real_t p_anchor);
  223. void _set_position(const Point2 &p_point);
  224. void _set_global_position(const Point2 &p_point);
  225. void _set_size(const Size2 &p_size);
  226. void _compute_offsets(Rect2 p_rect, const real_t p_anchors[4], real_t (&r_offsets)[4]);
  227. void _compute_anchors(Rect2 p_rect, const real_t p_offsets[4], real_t (&r_anchors)[4]);
  228. void _set_layout_mode(LayoutMode p_mode);
  229. void _update_layout_mode();
  230. LayoutMode _get_layout_mode() const;
  231. LayoutMode _get_default_layout_mode() const;
  232. void _set_anchors_layout_preset(int p_preset);
  233. int _get_anchors_layout_preset() const;
  234. void _update_minimum_size_cache();
  235. void _update_minimum_size();
  236. void _size_changed();
  237. void _top_level_changed() override {} // Controls don't need to do anything, only other CanvasItems.
  238. void _top_level_changed_on_parent() override;
  239. void _clear_size_warning();
  240. // Input events.
  241. void _call_gui_input(const Ref<InputEvent> &p_event);
  242. // Focus.
  243. void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest);
  244. Control *_get_focus_neighbor(Side p_side, int p_count = 0);
  245. // Theming.
  246. void _theme_changed();
  247. void _notify_theme_override_changed();
  248. void _invalidate_theme_cache();
  249. // Extra properties.
  250. String get_tooltip_text() const;
  251. protected:
  252. // Dynamic properties.
  253. bool _set(const StringName &p_name, const Variant &p_value);
  254. bool _get(const StringName &p_name, Variant &r_ret) const;
  255. void _get_property_list(List<PropertyInfo> *p_list) const;
  256. void _validate_property(PropertyInfo &p_property) const;
  257. bool _property_can_revert(const StringName &p_name) const;
  258. bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
  259. // Theming.
  260. virtual void _update_theme_item_cache();
  261. // Internationalization.
  262. virtual TypedArray<Vector3i> structured_text_parser(TextServer::StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
  263. // Base object overrides.
  264. void _notification(int p_notification);
  265. static void _bind_methods();
  266. // Exposed virtual methods.
  267. GDVIRTUAL1RC(bool, _has_point, Vector2)
  268. GDVIRTUAL2RC(TypedArray<Vector3i>, _structured_text_parser, Array, String)
  269. GDVIRTUAL0RC(Vector2, _get_minimum_size)
  270. GDVIRTUAL1RC(Variant, _get_drag_data, Vector2)
  271. GDVIRTUAL2RC(bool, _can_drop_data, Vector2, Variant)
  272. GDVIRTUAL2(_drop_data, Vector2, Variant)
  273. GDVIRTUAL1RC(Object *, _make_custom_tooltip, String)
  274. GDVIRTUAL1(_gui_input, Ref<InputEvent>)
  275. public:
  276. enum {
  277. NOTIFICATION_RESIZED = 40,
  278. NOTIFICATION_MOUSE_ENTER = 41,
  279. NOTIFICATION_MOUSE_EXIT = 42,
  280. NOTIFICATION_FOCUS_ENTER = 43,
  281. NOTIFICATION_FOCUS_EXIT = 44,
  282. NOTIFICATION_THEME_CHANGED = 45,
  283. NOTIFICATION_SCROLL_BEGIN = 47,
  284. NOTIFICATION_SCROLL_END = 48,
  285. NOTIFICATION_LAYOUT_DIRECTION_CHANGED = 49,
  286. };
  287. // Editor plugin interoperability.
  288. // TODO: Decouple controls from their editor plugin and get rid of this.
  289. #ifdef TOOLS_ENABLED
  290. virtual Dictionary _edit_get_state() const override;
  291. virtual void _edit_set_state(const Dictionary &p_state) override;
  292. virtual void _edit_set_position(const Point2 &p_position) override;
  293. virtual Point2 _edit_get_position() const override;
  294. virtual void _edit_set_scale(const Size2 &p_scale) override;
  295. virtual Size2 _edit_get_scale() const override;
  296. virtual void _edit_set_rect(const Rect2 &p_edit_rect) override;
  297. virtual Rect2 _edit_get_rect() const override;
  298. virtual bool _edit_use_rect() const override;
  299. virtual void _edit_set_rotation(real_t p_rotation) override;
  300. virtual real_t _edit_get_rotation() const override;
  301. virtual bool _edit_use_rotation() const override;
  302. virtual void _edit_set_pivot(const Point2 &p_pivot) override;
  303. virtual Point2 _edit_get_pivot() const override;
  304. virtual bool _edit_use_pivot() const override;
  305. virtual Size2 _edit_get_minimum_size() const override;
  306. #endif
  307. virtual void reparent(Node *p_parent, bool p_keep_global_transform = true) override;
  308. // Editor integration.
  309. virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const override;
  310. PackedStringArray get_configuration_warnings() const override;
  311. virtual bool is_text_field() const;
  312. // Global relations.
  313. bool is_top_level_control() const;
  314. Control *get_parent_control() const;
  315. Window *get_parent_window() const;
  316. Control *get_root_parent_control() const;
  317. Size2 get_parent_area_size() const;
  318. Rect2 get_parent_anchorable_rect() const;
  319. // Positioning and sizing.
  320. virtual Transform2D get_transform() const override;
  321. void set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset = true, bool p_push_opposite_anchor = true);
  322. real_t get_anchor(Side p_side) const;
  323. void set_offset(Side p_side, real_t p_value);
  324. real_t get_offset(Side p_side) const;
  325. void set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos, bool p_push_opposite_anchor = true);
  326. // TODO: Rename to set_begin/end_offsets ?
  327. void set_begin(const Point2 &p_point);
  328. Point2 get_begin() const;
  329. void set_end(const Point2 &p_point);
  330. Point2 get_end() const;
  331. void set_h_grow_direction(GrowDirection p_direction);
  332. GrowDirection get_h_grow_direction() const;
  333. void set_v_grow_direction(GrowDirection p_direction);
  334. GrowDirection get_v_grow_direction() const;
  335. void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true);
  336. void set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
  337. void set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
  338. void set_grow_direction_preset(LayoutPreset p_preset);
  339. void set_position(const Point2 &p_point, bool p_keep_offsets = false);
  340. void set_global_position(const Point2 &p_point, bool p_keep_offsets = false);
  341. Point2 get_position() const;
  342. Point2 get_global_position() const;
  343. Point2 get_screen_position() const;
  344. void set_size(const Size2 &p_size, bool p_keep_offsets = false);
  345. Size2 get_size() const;
  346. void reset_size();
  347. void set_rect(const Rect2 &p_rect); // Reset anchors to begin and set rect, for faster container children sorting.
  348. Rect2 get_rect() const;
  349. Rect2 get_global_rect() const;
  350. Rect2 get_screen_rect() const;
  351. Rect2 get_anchorable_rect() const override;
  352. void set_scale(const Vector2 &p_scale);
  353. Vector2 get_scale() const;
  354. void set_rotation(real_t p_radians);
  355. void set_rotation_degrees(real_t p_degrees);
  356. real_t get_rotation() const;
  357. real_t get_rotation_degrees() const;
  358. void set_pivot_offset(const Vector2 &p_pivot);
  359. Vector2 get_pivot_offset() const;
  360. void update_minimum_size();
  361. void set_block_minimum_size_adjust(bool p_block);
  362. virtual Size2 get_minimum_size() const;
  363. virtual Size2 get_combined_minimum_size() const;
  364. void set_custom_minimum_size(const Size2 &p_custom);
  365. Size2 get_custom_minimum_size() const;
  366. // Container sizing.
  367. void set_h_size_flags(BitField<SizeFlags> p_flags);
  368. BitField<SizeFlags> get_h_size_flags() const;
  369. void set_v_size_flags(BitField<SizeFlags> p_flags);
  370. BitField<SizeFlags> get_v_size_flags() const;
  371. void set_stretch_ratio(real_t p_ratio);
  372. real_t get_stretch_ratio() const;
  373. // Input events.
  374. virtual void gui_input(const Ref<InputEvent> &p_event);
  375. void accept_event();
  376. virtual bool has_point(const Point2 &p_point) const;
  377. void set_mouse_filter(MouseFilter p_filter);
  378. MouseFilter get_mouse_filter() const;
  379. void set_force_pass_scroll_events(bool p_force_pass_scroll_events);
  380. bool is_force_pass_scroll_events() const;
  381. void warp_mouse(const Point2 &p_position);
  382. bool is_focus_owner_in_shortcut_context() const;
  383. void set_shortcut_context(const Node *p_node);
  384. Node *get_shortcut_context() const;
  385. // Drag and drop handling.
  386. virtual void set_drag_forwarding(const Callable &p_drag, const Callable &p_can_drop, const Callable &p_drop);
  387. virtual Variant get_drag_data(const Point2 &p_point);
  388. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const;
  389. virtual void drop_data(const Point2 &p_point, const Variant &p_data);
  390. void set_drag_preview(Control *p_control);
  391. void force_drag(const Variant &p_data, Control *p_control);
  392. bool is_drag_successful() const;
  393. // Focus.
  394. void set_focus_mode(FocusMode p_focus_mode);
  395. FocusMode get_focus_mode() const;
  396. bool has_focus() const;
  397. void grab_focus();
  398. void grab_click_focus();
  399. void release_focus();
  400. Control *find_next_valid_focus() const;
  401. Control *find_prev_valid_focus() const;
  402. void set_focus_neighbor(Side p_side, const NodePath &p_neighbor);
  403. NodePath get_focus_neighbor(Side p_side) const;
  404. void set_focus_next(const NodePath &p_next);
  405. NodePath get_focus_next() const;
  406. void set_focus_previous(const NodePath &p_prev);
  407. NodePath get_focus_previous() const;
  408. // Rendering.
  409. void set_default_cursor_shape(CursorShape p_shape);
  410. CursorShape get_default_cursor_shape() const;
  411. virtual CursorShape get_cursor_shape(const Point2 &p_pos = Point2i()) const;
  412. void set_clip_contents(bool p_clip);
  413. bool is_clipping_contents();
  414. void set_disable_visibility_clip(bool p_ignore);
  415. bool is_visibility_clip_disabled() const;
  416. // Theming.
  417. void set_theme_owner_node(Node *p_node);
  418. Node *get_theme_owner_node() const;
  419. bool has_theme_owner_node() const;
  420. void set_theme(const Ref<Theme> &p_theme);
  421. Ref<Theme> get_theme() const;
  422. void set_theme_type_variation(const StringName &p_theme_type);
  423. StringName get_theme_type_variation() const;
  424. void begin_bulk_theme_override();
  425. void end_bulk_theme_override();
  426. void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon);
  427. void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style);
  428. void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font);
  429. void add_theme_font_size_override(const StringName &p_name, int p_font_size);
  430. void add_theme_color_override(const StringName &p_name, const Color &p_color);
  431. void add_theme_constant_override(const StringName &p_name, int p_constant);
  432. void remove_theme_icon_override(const StringName &p_name);
  433. void remove_theme_style_override(const StringName &p_name);
  434. void remove_theme_font_override(const StringName &p_name);
  435. void remove_theme_font_size_override(const StringName &p_name);
  436. void remove_theme_color_override(const StringName &p_name);
  437. void remove_theme_constant_override(const StringName &p_name);
  438. Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  439. Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  440. Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  441. int get_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  442. Color get_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  443. int get_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  444. bool has_theme_icon_override(const StringName &p_name) const;
  445. bool has_theme_stylebox_override(const StringName &p_name) const;
  446. bool has_theme_font_override(const StringName &p_name) const;
  447. bool has_theme_font_size_override(const StringName &p_name) const;
  448. bool has_theme_color_override(const StringName &p_name) const;
  449. bool has_theme_constant_override(const StringName &p_name) const;
  450. bool has_theme_icon(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  451. bool has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  452. bool has_theme_font(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  453. bool has_theme_font_size(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  454. bool has_theme_color(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  455. bool has_theme_constant(const StringName &p_name, const StringName &p_theme_type = StringName()) const;
  456. float get_theme_default_base_scale() const;
  457. Ref<Font> get_theme_default_font() const;
  458. int get_theme_default_font_size() const;
  459. // Internationalization.
  460. void set_layout_direction(LayoutDirection p_direction);
  461. LayoutDirection get_layout_direction() const;
  462. virtual bool is_layout_rtl() const;
  463. void set_localize_numeral_system(bool p_enable);
  464. bool is_localizing_numeral_system() const;
  465. void set_auto_translate(bool p_enable);
  466. bool is_auto_translating() const;
  467. _FORCE_INLINE_ String atr(const String p_string) const {
  468. return is_auto_translating() ? tr(p_string) : p_string;
  469. };
  470. // Extra properties.
  471. void set_tooltip_text(const String &text);
  472. virtual String get_tooltip(const Point2 &p_pos) const;
  473. virtual Control *make_custom_tooltip(const String &p_text) const;
  474. Control();
  475. ~Control();
  476. };
  477. VARIANT_ENUM_CAST(Control::FocusMode);
  478. VARIANT_BITFIELD_CAST(Control::SizeFlags);
  479. VARIANT_ENUM_CAST(Control::CursorShape);
  480. VARIANT_ENUM_CAST(Control::LayoutPreset);
  481. VARIANT_ENUM_CAST(Control::LayoutPresetMode);
  482. VARIANT_ENUM_CAST(Control::MouseFilter);
  483. VARIANT_ENUM_CAST(Control::GrowDirection);
  484. VARIANT_ENUM_CAST(Control::Anchor);
  485. VARIANT_ENUM_CAST(Control::LayoutMode);
  486. VARIANT_ENUM_CAST(Control::LayoutDirection);
  487. VARIANT_ENUM_CAST(Control::TextDirection);
  488. // G = get_drag_data_fw, C = can_drop_data_fw, D = drop_data_fw, U = underscore
  489. #define SET_DRAG_FORWARDING_CD(from, to) from->set_drag_forwarding(Callable(), callable_mp(this, &to::can_drop_data_fw).bind(from), callable_mp(this, &to::drop_data_fw).bind(from));
  490. #define SET_DRAG_FORWARDING_CDU(from, to) from->set_drag_forwarding(Callable(), callable_mp(this, &to::_can_drop_data_fw).bind(from), callable_mp(this, &to::_drop_data_fw).bind(from));
  491. #define SET_DRAG_FORWARDING_GCD(from, to) from->set_drag_forwarding(callable_mp(this, &to::get_drag_data_fw).bind(from), callable_mp(this, &to::can_drop_data_fw).bind(from), callable_mp(this, &to::drop_data_fw).bind(from));
  492. #define SET_DRAG_FORWARDING_GCDU(from, to) from->set_drag_forwarding(callable_mp(this, &to::_get_drag_data_fw).bind(from), callable_mp(this, &to::_can_drop_data_fw).bind(from), callable_mp(this, &to::_drop_data_fw).bind(from));
  493. #endif // CONTROL_H