Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/scene/gui/theme_editor_plugin.h
9912 views
1
/**************************************************************************/
2
/* theme_editor_plugin.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
31
#pragma once
32
33
#include "editor/plugins/editor_plugin.h"
34
#include "editor/scene/gui/theme_editor_preview.h"
35
#include "scene/gui/dialogs.h"
36
#include "scene/gui/margin_container.h"
37
#include "scene/gui/tree.h"
38
#include "scene/resources/theme.h"
39
40
class Button;
41
class CheckButton;
42
class EditorFileDialog;
43
class ItemList;
44
class Label;
45
class LineEdit;
46
class OptionButton;
47
class PanelContainer;
48
class TabBar;
49
class TabContainer;
50
class ThemeEditorPlugin;
51
class TextureRect;
52
53
class ThemeItemImportTree : public VBoxContainer {
54
GDCLASS(ThemeItemImportTree, VBoxContainer);
55
56
Ref<Theme> edited_theme;
57
Ref<Theme> base_theme;
58
59
struct ThemeItem {
60
String type_name;
61
Theme::DataType data_type;
62
String item_name;
63
64
bool operator<(const ThemeItem &p_item) const {
65
if (type_name == p_item.type_name && data_type == p_item.data_type) {
66
return item_name < p_item.item_name;
67
}
68
if (type_name == p_item.type_name) {
69
return data_type < p_item.data_type;
70
}
71
return type_name < p_item.type_name;
72
}
73
};
74
75
enum ItemCheckedState {
76
SELECT_IMPORT_DEFINITION,
77
SELECT_IMPORT_FULL,
78
};
79
80
RBMap<ThemeItem, ItemCheckedState> selected_items;
81
82
LineEdit *import_items_filter = nullptr;
83
84
Tree *import_items_tree = nullptr;
85
List<TreeItem *> tree_color_items;
86
List<TreeItem *> tree_constant_items;
87
List<TreeItem *> tree_font_items;
88
List<TreeItem *> tree_font_size_items;
89
List<TreeItem *> tree_icon_items;
90
List<TreeItem *> tree_stylebox_items;
91
92
bool updating_tree = false;
93
94
enum ItemActionFlag {
95
IMPORT_ITEM = 1,
96
IMPORT_ITEM_DATA = 2,
97
};
98
99
TextureRect *select_colors_icon = nullptr;
100
Label *select_colors_label = nullptr;
101
Button *select_all_colors_button = nullptr;
102
Button *select_full_colors_button = nullptr;
103
Button *deselect_all_colors_button = nullptr;
104
Label *total_selected_colors_label = nullptr;
105
106
TextureRect *select_constants_icon = nullptr;
107
Label *select_constants_label = nullptr;
108
Button *select_all_constants_button = nullptr;
109
Button *select_full_constants_button = nullptr;
110
Button *deselect_all_constants_button = nullptr;
111
Label *total_selected_constants_label = nullptr;
112
113
TextureRect *select_fonts_icon = nullptr;
114
Label *select_fonts_label = nullptr;
115
Button *select_all_fonts_button = nullptr;
116
Button *select_full_fonts_button = nullptr;
117
Button *deselect_all_fonts_button = nullptr;
118
Label *total_selected_fonts_label = nullptr;
119
120
TextureRect *select_font_sizes_icon = nullptr;
121
Label *select_font_sizes_label = nullptr;
122
Button *select_all_font_sizes_button = nullptr;
123
Button *select_full_font_sizes_button = nullptr;
124
Button *deselect_all_font_sizes_button = nullptr;
125
Label *total_selected_font_sizes_label = nullptr;
126
127
TextureRect *select_icons_icon = nullptr;
128
Label *select_icons_label = nullptr;
129
Button *select_all_icons_button = nullptr;
130
Button *select_full_icons_button = nullptr;
131
Button *deselect_all_icons_button = nullptr;
132
Label *total_selected_icons_label = nullptr;
133
134
TextureRect *select_styleboxes_icon = nullptr;
135
Label *select_styleboxes_label = nullptr;
136
Button *select_all_styleboxes_button = nullptr;
137
Button *select_full_styleboxes_button = nullptr;
138
Button *deselect_all_styleboxes_button = nullptr;
139
Label *total_selected_styleboxes_label = nullptr;
140
141
HBoxContainer *select_icons_warning_hb = nullptr;
142
TextureRect *select_icons_warning_icon = nullptr;
143
Label *select_icons_warning = nullptr;
144
145
Button *import_collapse_types_button = nullptr;
146
Button *import_expand_types_button = nullptr;
147
Button *import_select_all_button = nullptr;
148
Button *import_select_full_button = nullptr;
149
Button *import_deselect_all_button = nullptr;
150
151
void _update_items_tree();
152
void _toggle_type_items(bool p_collapse);
153
void _filter_text_changed(const String &p_value);
154
155
void _store_selected_item(TreeItem *p_tree_item);
156
void _restore_selected_item(TreeItem *p_tree_item);
157
void _update_total_selected(Theme::DataType p_data_type);
158
159
void _tree_item_edited();
160
void _check_propagated_to_tree_item(Object *p_obj, int p_column);
161
void _select_all_subitems(TreeItem *p_root_item, bool p_select_with_data);
162
void _deselect_all_subitems(TreeItem *p_root_item, bool p_deselect_completely);
163
164
void _select_all_items_pressed();
165
void _select_full_items_pressed();
166
void _deselect_all_items_pressed();
167
168
void _select_all_data_type_pressed(int p_data_type);
169
void _select_full_data_type_pressed(int p_data_type);
170
void _deselect_all_data_type_pressed(int p_data_type);
171
172
void _import_selected();
173
174
protected:
175
void _notification(int p_what);
176
static void _bind_methods();
177
178
public:
179
void set_edited_theme(const Ref<Theme> &p_theme);
180
void set_base_theme(const Ref<Theme> &p_theme);
181
void reset_item_tree();
182
183
bool has_selected_items() const;
184
185
ThemeItemImportTree();
186
};
187
188
class ThemeTypeEditor;
189
190
class ThemeItemEditorDialog : public AcceptDialog {
191
GDCLASS(ThemeItemEditorDialog, AcceptDialog);
192
193
ThemeTypeEditor *theme_type_editor = nullptr;
194
195
Ref<Theme> edited_theme;
196
197
TabContainer *tc = nullptr;
198
199
enum TypesTreeAction {
200
TYPES_TREE_REMOVE_ITEM,
201
};
202
203
Tree *edit_type_list = nullptr;
204
LineEdit *edit_add_type_value = nullptr;
205
Button *edit_add_type_button = nullptr;
206
String edited_item_type;
207
208
Button *edit_items_add_color = nullptr;
209
Button *edit_items_add_constant = nullptr;
210
Button *edit_items_add_font = nullptr;
211
Button *edit_items_add_font_size = nullptr;
212
Button *edit_items_add_icon = nullptr;
213
Button *edit_items_add_stylebox = nullptr;
214
Button *edit_items_remove_class = nullptr;
215
Button *edit_items_remove_custom = nullptr;
216
Button *edit_items_remove_all = nullptr;
217
Tree *edit_items_tree = nullptr;
218
Label *edit_items_message = nullptr;
219
220
enum ItemsTreeAction {
221
ITEMS_TREE_RENAME_ITEM,
222
ITEMS_TREE_REMOVE_ITEM,
223
ITEMS_TREE_REMOVE_DATA_TYPE,
224
};
225
226
ConfirmationDialog *edit_theme_item_dialog = nullptr;
227
VBoxContainer *edit_theme_item_old_vb = nullptr;
228
Label *theme_item_old_name = nullptr;
229
LineEdit *theme_item_name = nullptr;
230
231
enum ItemPopupMode {
232
CREATE_THEME_ITEM,
233
RENAME_THEME_ITEM,
234
ITEM_POPUP_MODE_MAX
235
};
236
237
ItemPopupMode item_popup_mode = ITEM_POPUP_MODE_MAX;
238
String edit_item_old_name;
239
Theme::DataType edit_item_data_type = Theme::DATA_TYPE_MAX;
240
241
ThemeItemImportTree *import_default_theme_items = nullptr;
242
ThemeItemImportTree *import_editor_theme_items = nullptr;
243
ThemeItemImportTree *import_other_theme_items = nullptr;
244
245
LineEdit *import_another_theme_value = nullptr;
246
Button *import_another_theme_button = nullptr;
247
EditorFileDialog *import_another_theme_dialog = nullptr;
248
249
ConfirmationDialog *confirm_closing_dialog = nullptr;
250
251
void ok_pressed() override;
252
void _close_dialog();
253
254
void _dialog_about_to_show();
255
void _update_edit_types();
256
void _edited_type_selected();
257
void _edited_type_edited();
258
void _edited_type_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
259
260
void _update_edit_item_tree(String p_item_type);
261
void _item_tree_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button);
262
263
void _add_theme_type();
264
void _add_theme_item(Theme::DataType p_data_type, const String &p_item_name, const String &p_item_type);
265
void _remove_theme_type(const String &p_theme_type);
266
void _remove_data_type_items(Theme::DataType p_data_type, String p_item_type);
267
void _remove_class_items();
268
void _remove_custom_items();
269
void _remove_all_items();
270
271
void _open_add_theme_item_dialog(int p_data_type);
272
void _open_rename_theme_item_dialog(Theme::DataType p_data_type, String p_item_name);
273
void _confirm_edit_theme_item();
274
void _edit_theme_item_gui_input(const Ref<InputEvent> &p_event);
275
276
void _open_select_another_theme();
277
void _select_another_theme_cbk(const String &p_path);
278
279
protected:
280
void _notification(int p_what);
281
static void _bind_methods();
282
283
public:
284
void set_edited_theme(const Ref<Theme> &p_theme);
285
286
ThemeItemEditorDialog(ThemeTypeEditor *p_theme_editor);
287
};
288
289
class ThemeTypeDialog : public ConfirmationDialog {
290
GDCLASS(ThemeTypeDialog, ConfirmationDialog);
291
292
Ref<Theme> edited_theme;
293
bool include_own_types = false;
294
295
String pre_submitted_value;
296
297
LineEdit *add_type_filter = nullptr;
298
ItemList *add_type_options = nullptr;
299
ConfirmationDialog *add_type_confirmation = nullptr;
300
301
void _dialog_about_to_show();
302
void ok_pressed() override;
303
304
void _update_add_type_options(const String &p_filter = "");
305
306
void _add_type_filter_cbk(const String &p_value);
307
void _type_filter_input(const Ref<InputEvent> &p_event);
308
void _add_type_options_cbk(int p_index);
309
void _add_type_dialog_entered(const String &p_value);
310
void _add_type_dialog_activated(int p_index);
311
312
void _add_type_selected(const String &p_type_name);
313
void _add_type_confirmed();
314
315
protected:
316
void _notification(int p_what);
317
static void _bind_methods();
318
319
public:
320
void set_edited_theme(const Ref<Theme> &p_theme);
321
void set_include_own_types(bool p_enable);
322
323
ThemeTypeDialog();
324
};
325
326
// Custom `Label` needed to use `EditorHelpBit` to display theme item documentation.
327
class ThemeItemLabel : public Label {
328
virtual Control *make_custom_tooltip(const String &p_text) const;
329
};
330
331
class ThemeTypeEditor : public MarginContainer {
332
GDCLASS(ThemeTypeEditor, MarginContainer);
333
334
Ref<Theme> edited_theme;
335
String edited_type;
336
bool updating = false;
337
338
struct LeadingStylebox {
339
bool pinned = false;
340
StringName item_name;
341
Ref<StyleBox> stylebox;
342
Ref<StyleBox> ref_stylebox;
343
};
344
345
LeadingStylebox leading_stylebox;
346
347
OptionButton *theme_type_list = nullptr;
348
Button *add_type_button = nullptr;
349
Button *rename_type_button = nullptr;
350
ConfirmationDialog *theme_type_rename_dialog = nullptr;
351
LineEdit *theme_type_rename_line_edit = nullptr;
352
Button *remove_type_button = nullptr;
353
354
CheckButton *show_default_items_button = nullptr;
355
356
TabContainer *data_type_tabs = nullptr;
357
VBoxContainer *color_items_list = nullptr;
358
VBoxContainer *constant_items_list = nullptr;
359
VBoxContainer *font_items_list = nullptr;
360
VBoxContainer *font_size_items_list = nullptr;
361
VBoxContainer *icon_items_list = nullptr;
362
VBoxContainer *stylebox_items_list = nullptr;
363
364
LineEdit *type_variation_edit = nullptr;
365
Button *type_variation_button = nullptr;
366
Label *type_variation_locked = nullptr;
367
368
enum TypeDialogMode {
369
ADD_THEME_TYPE,
370
ADD_VARIATION_BASE,
371
};
372
373
TypeDialogMode add_type_mode = ADD_THEME_TYPE;
374
ThemeTypeDialog *add_type_dialog = nullptr;
375
376
Vector<Control *> focusables;
377
Timer *update_debounce_timer = nullptr;
378
379
VBoxContainer *_create_item_list(Theme::DataType p_data_type);
380
void _update_type_list();
381
void _update_type_list_debounced();
382
HashMap<StringName, bool> _get_type_items(String p_type_name, Theme::DataType p_type, bool p_include_default);
383
HBoxContainer *_create_property_control(Theme::DataType p_data_type, String p_item_name, bool p_editable);
384
void _add_focusable(Control *p_control);
385
void _update_type_items();
386
387
void _list_type_selected(int p_index);
388
void _add_type_button_cbk();
389
void _rename_type_button_cbk();
390
void _theme_type_rename_dialog_confirmed();
391
void _remove_type_button_cbk();
392
void _add_default_type_items();
393
394
void _update_add_button(const String &p_text, LineEdit *p_for_edit);
395
void _item_add_cbk(int p_data_type, Control *p_control);
396
void _item_add_lineedit_cbk(String p_value, int p_data_type, Control *p_control);
397
void _item_override_cbk(int p_data_type, String p_item_name);
398
void _item_remove_cbk(int p_data_type, String p_item_name);
399
void _item_rename_cbk(int p_data_type, String p_item_name, Control *p_control);
400
void _item_rename_confirmed(int p_data_type, String p_item_name, Control *p_control);
401
void _item_rename_entered(String p_value, int p_data_type, String p_item_name, Control *p_control);
402
void _item_rename_canceled(int p_data_type, String p_item_name, Control *p_control);
403
404
void _color_item_changed(Color p_value, String p_item_name);
405
void _constant_item_changed(float p_value, String p_item_name);
406
void _font_size_item_changed(float p_value, String p_item_name);
407
void _edit_resource_item(Ref<Resource> p_resource, bool p_edit);
408
void _font_item_changed(Ref<Font> p_value, String p_item_name);
409
void _icon_item_changed(Ref<Texture2D> p_value, String p_item_name);
410
void _stylebox_item_changed(Ref<StyleBox> p_value, String p_item_name);
411
void _change_pinned_stylebox();
412
void _on_pin_leader_button_pressed(Control *p_editor, String p_item_name);
413
void _pin_leading_stylebox(String p_item_name, Ref<StyleBox> p_stylebox);
414
void _on_unpin_leader_button_pressed();
415
void _unpin_leading_stylebox();
416
void _update_stylebox_from_leading();
417
418
void _type_variation_changed(const String p_value);
419
void _add_type_variation_cbk();
420
421
void _add_type_dialog_selected(const String p_type_name);
422
423
protected:
424
void _notification(int p_what);
425
static void _bind_methods();
426
427
public:
428
void set_edited_theme(const Ref<Theme> &p_theme);
429
void select_type(String p_type_name);
430
bool is_stylebox_pinned(Ref<StyleBox> p_stylebox);
431
432
ThemeTypeEditor();
433
};
434
435
class ThemeEditor : public VBoxContainer {
436
GDCLASS(ThemeEditor, VBoxContainer);
437
438
friend class ThemeEditorPlugin;
439
ThemeEditorPlugin *plugin = nullptr;
440
441
Ref<Theme> theme;
442
443
TabBar *preview_tabs = nullptr;
444
PanelContainer *preview_tabs_content = nullptr;
445
Button *add_preview_button = nullptr;
446
EditorFileDialog *preview_scene_dialog = nullptr;
447
448
ThemeTypeEditor *theme_type_editor = nullptr;
449
450
Label *theme_name = nullptr;
451
ThemeItemEditorDialog *theme_edit_dialog = nullptr;
452
453
void _theme_save_button_cbk(bool p_save_as);
454
void _theme_edit_button_cbk();
455
void _theme_close_button_cbk();
456
void _scene_closed(const String &p_path);
457
void _resource_saved(const Ref<Resource> &p_resource);
458
void _files_moved(const String &p_old_path, const String &p_new_path);
459
void _update_theme_name(const String &p_name);
460
461
void _add_preview_button_cbk();
462
void _preview_scene_dialog_cbk(const String &p_path);
463
void _add_preview_tab(ThemeEditorPreview *p_preview_tab, const String &p_preview_name, const Ref<Texture2D> &p_icon);
464
void _change_preview_tab(int p_tab);
465
void _remove_preview_tab(int p_tab);
466
void _remove_preview_tab_invalid(Node *p_tab_control);
467
void _update_preview_tab(Node *p_tab_control);
468
void _preview_control_picked(String p_class_name);
469
470
protected:
471
void _notification(int p_what);
472
473
public:
474
void edit(const Ref<Theme> &p_theme);
475
Ref<Theme> get_edited_theme();
476
477
bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
478
void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);
479
480
ThemeEditor();
481
};
482
483
class ThemeEditorPlugin : public EditorPlugin {
484
GDCLASS(ThemeEditorPlugin, EditorPlugin);
485
486
ThemeEditor *theme_editor = nullptr;
487
Button *button = nullptr;
488
489
public:
490
virtual String get_plugin_name() const override { return "Theme"; }
491
bool has_main_screen() const override { return false; }
492
virtual void edit(Object *p_object) override;
493
virtual bool handles(Object *p_object) const override;
494
virtual void make_visible(bool p_visible) override;
495
virtual bool can_auto_hide() const override;
496
497
ThemeEditorPlugin();
498
};
499
500