control.h 21 KB

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