3131#include " control_editor_plugin.h"
3232
3333#include " editor/editor_node.h"
34- #include " editor/editor_string_names.h"
3534#include " editor/editor_undo_redo_manager.h"
3635#include " editor/plugins/canvas_item_editor_plugin.h"
3736#include " editor/themes/editor_scale.h"
37+ #include " scene/gui/button.h"
38+ #include " scene/gui/check_box.h"
3839#include " scene/gui/check_button.h"
3940#include " scene/gui/grid_container.h"
41+ #include " scene/gui/option_button.h"
42+ #include " scene/gui/panel_container.h"
4043#include " scene/gui/separator.h"
44+ #include " scene/gui/texture_rect.h"
4145
4246// Inspector controls.
4347
@@ -160,6 +164,41 @@ void EditorPropertyAnchorsPreset::_set_read_only(bool p_read_only) {
160164 options->set_disabled (p_read_only);
161165}
162166
167+ void EditorPropertyAnchorsPreset::_notification (int p_what) {
168+ switch (p_what) {
169+ case NOTIFICATION_THEME_CHANGED: {
170+ for (int i = 0 ; i < options->get_item_count (); i++) {
171+ if (options->is_item_separator (i)) {
172+ continue ;
173+ }
174+ int64_t preset = options->get_item_metadata (i);
175+ if (preset < 0 || PRESET_FULL_RECT < preset) {
176+ continue ;
177+ }
178+ static const StringName icon_names[] = {
179+ StringName (" ControlAlignTopLeft" , true ),
180+ StringName (" ControlAlignTopRight" , true ),
181+ StringName (" ControlAlignBottomLeft" , true ),
182+ StringName (" ControlAlignBottomRight" , true ),
183+ StringName (" ControlAlignCenterLeft" , true ),
184+ StringName (" ControlAlignCenterTop" , true ),
185+ StringName (" ControlAlignCenterRight" , true ),
186+ StringName (" ControlAlignCenterBottom" , true ),
187+ StringName (" ControlAlignCenter" , true ),
188+ StringName (" ControlAlignLeftWide" , true ),
189+ StringName (" ControlAlignTopWide" , true ),
190+ StringName (" ControlAlignRightWide" , true ),
191+ StringName (" ControlAlignBottomWide" , true ),
192+ StringName (" ControlAlignVCenterWide" , true ),
193+ StringName (" ControlAlignHCenterWide" , true ),
194+ StringName (" ControlAlignFullRect" , true ),
195+ };
196+ options->set_item_icon (i, get_editor_theme_icon (icon_names[preset]));
197+ }
198+ } break ;
199+ }
200+ }
201+
163202void EditorPropertyAnchorsPreset::_option_selected (int p_which) {
164203 int64_t val = options->get_item_metadata (p_which);
165204 emit_changed (get_edited_property (), val);
@@ -180,30 +219,22 @@ void EditorPropertyAnchorsPreset::update_property() {
180219void EditorPropertyAnchorsPreset::setup (const Vector<String> &p_options) {
181220 options->clear ();
182221
183- Vector<String> split_after;
184- split_after.append (" Custom" );
185- split_after.append (" PresetFullRect" );
186- split_after.append (" PresetBottomLeft" );
187- split_after.append (" PresetCenter" );
222+ const Vector<int > split_after = {
223+ -1 ,
224+ PRESET_FULL_RECT,
225+ PRESET_BOTTOM_LEFT,
226+ PRESET_CENTER,
227+ };
188228
189- for (int i = 0 , j = 0 ; i < p_options.size (); i++, j ++) {
229+ for (int i = 0 ; i < p_options.size (); i++) {
190230 Vector<String> text_split = p_options[i].split (" :" );
191231 int64_t current_val = text_split[1 ].to_int ();
192232
193233 const String &option_name = text_split[0 ];
194- if (option_name.begins_with (" Preset" )) {
195- String preset_name = option_name.trim_prefix (" Preset" );
196- String humanized_name = preset_name.capitalize ();
197- String icon_name = " ControlAlign" + preset_name;
198- options->add_icon_item (EditorNode::get_singleton ()->get_editor_theme ()->get_icon (icon_name, EditorStringName (EditorIcons)), humanized_name);
199- } else {
200- options->add_item (option_name);
201- }
202-
203- options->set_item_metadata (j, current_val);
204- if (split_after.has (option_name)) {
234+ options->add_item (option_name);
235+ options->set_item_metadata (-1 , current_val);
236+ if (split_after.has (current_val)) {
205237 options->add_separator ();
206- j++;
207238 }
208239 }
209240}
@@ -613,33 +644,33 @@ AnchorPresetPicker::AnchorPresetPicker() {
613644 top_row->add_theme_constant_override (" separation" , grid_separation);
614645 main_vb->add_child (top_row);
615646
616- _add_row_button (top_row, PRESET_TOP_LEFT, TTR (" Top Left" ));
617- _add_row_button (top_row, PRESET_CENTER_TOP, TTR (" Center Top" ));
618- _add_row_button (top_row, PRESET_TOP_RIGHT, TTR (" Top Right" ));
647+ _add_row_button (top_row, PRESET_TOP_LEFT, TTRC (" Top Left" ));
648+ _add_row_button (top_row, PRESET_CENTER_TOP, TTRC (" Center Top" ));
649+ _add_row_button (top_row, PRESET_TOP_RIGHT, TTRC (" Top Right" ));
619650 _add_separator (top_row, memnew (VSeparator));
620- _add_row_button (top_row, PRESET_TOP_WIDE, TTR (" Top Wide" ));
651+ _add_row_button (top_row, PRESET_TOP_WIDE, TTRC (" Top Wide" ));
621652
622653 HBoxContainer *mid_row = memnew (HBoxContainer);
623654 mid_row->set_alignment (BoxContainer::ALIGNMENT_CENTER);
624655 mid_row->add_theme_constant_override (" separation" , grid_separation);
625656 main_vb->add_child (mid_row);
626657
627- _add_row_button (mid_row, PRESET_CENTER_LEFT, TTR (" Center Left" ));
628- _add_row_button (mid_row, PRESET_CENTER, TTR (" Center" ));
629- _add_row_button (mid_row, PRESET_CENTER_RIGHT, TTR (" Center Right" ));
658+ _add_row_button (mid_row, PRESET_CENTER_LEFT, TTRC (" Center Left" ));
659+ _add_row_button (mid_row, PRESET_CENTER, TTRC (" Center" ));
660+ _add_row_button (mid_row, PRESET_CENTER_RIGHT, TTRC (" Center Right" ));
630661 _add_separator (mid_row, memnew (VSeparator));
631- _add_row_button (mid_row, PRESET_HCENTER_WIDE, TTR (" HCenter Wide" ));
662+ _add_row_button (mid_row, PRESET_HCENTER_WIDE, TTRC (" HCenter Wide" ));
632663
633664 HBoxContainer *bot_row = memnew (HBoxContainer);
634665 bot_row->set_alignment (BoxContainer::ALIGNMENT_CENTER);
635666 bot_row->add_theme_constant_override (" separation" , grid_separation);
636667 main_vb->add_child (bot_row);
637668
638- _add_row_button (bot_row, PRESET_BOTTOM_LEFT, TTR (" Bottom Left" ));
639- _add_row_button (bot_row, PRESET_CENTER_BOTTOM, TTR (" Center Bottom" ));
640- _add_row_button (bot_row, PRESET_BOTTOM_RIGHT, TTR (" Bottom Right" ));
669+ _add_row_button (bot_row, PRESET_BOTTOM_LEFT, TTRC (" Bottom Left" ));
670+ _add_row_button (bot_row, PRESET_CENTER_BOTTOM, TTRC (" Center Bottom" ));
671+ _add_row_button (bot_row, PRESET_BOTTOM_RIGHT, TTRC (" Bottom Right" ));
641672 _add_separator (bot_row, memnew (VSeparator));
642- _add_row_button (bot_row, PRESET_BOTTOM_WIDE, TTR (" Bottom Wide" ));
673+ _add_row_button (bot_row, PRESET_BOTTOM_WIDE, TTRC (" Bottom Wide" ));
643674
644675 _add_separator (main_vb, memnew (HSeparator));
645676
@@ -648,11 +679,11 @@ AnchorPresetPicker::AnchorPresetPicker() {
648679 extra_row->add_theme_constant_override (" separation" , grid_separation);
649680 main_vb->add_child (extra_row);
650681
651- _add_row_button (extra_row, PRESET_LEFT_WIDE, TTR (" Left Wide" ));
652- _add_row_button (extra_row, PRESET_VCENTER_WIDE, TTR (" VCenter Wide" ));
653- _add_row_button (extra_row, PRESET_RIGHT_WIDE, TTR (" Right Wide" ));
682+ _add_row_button (extra_row, PRESET_LEFT_WIDE, TTRC (" Left Wide" ));
683+ _add_row_button (extra_row, PRESET_VCENTER_WIDE, TTRC (" VCenter Wide" ));
684+ _add_row_button (extra_row, PRESET_RIGHT_WIDE, TTRC (" Right Wide" ));
654685 _add_separator (extra_row, memnew (VSeparator));
655- _add_row_button (extra_row, PRESET_FULL_RECT, TTR (" Full Rect" ));
686+ _add_row_button (extra_row, PRESET_FULL_RECT, TTRC (" Full Rect" ));
656687}
657688
658689void SizeFlagPresetPicker::_preset_button_pressed (const int p_preset) {
0 commit comments