control.h 22 KB

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