Skip to content

Commit

Permalink
Merge pull request #59797 from fire-forge/array-margins
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed Jun 11, 2022
2 parents 126e4d0 + d605d13 commit 1847094
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 38 deletions.
78 changes: 45 additions & 33 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ void EditorPropertyArray::update_property() {
if (array.get_type() == Variant::NIL) {
edit->set_text(vformat(TTR("(Nil) %s"), array_type_name));
edit->set_pressed(false);
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
return;
}
Expand All @@ -241,10 +241,14 @@ void EditorPropertyArray::update_property() {
if (unfolded) {
updating = true;

if (!vbox) {
vbox = memnew(VBoxContainer);
add_child(vbox);
set_bottom_editor(vbox);
if (!container) {
container = memnew(MarginContainer);
container->set_theme_type_variation("MarginContainer4px");
add_child(container);
set_bottom_editor(container);

VBoxContainer *vbox = memnew(VBoxContainer);
container->add_child(vbox);

HBoxContainer *hbox = memnew(HBoxContainer);
vbox->add_child(hbox);
Expand Down Expand Up @@ -372,11 +376,11 @@ void EditorPropertyArray::update_property() {
updating = false;

} else {
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
}
}
Expand Down Expand Up @@ -687,7 +691,7 @@ EditorPropertyArray::EditorPropertyArray() {
add_child(edit);
add_focusable(edit);

vbox = nullptr;
container = nullptr;
property_vbox = nullptr;
size_slider = nullptr;
button_add_item = nullptr;
Expand Down Expand Up @@ -791,11 +795,11 @@ void EditorPropertyDictionary::update_property() {
if (updated_val.get_type() == Variant::NIL) {
edit->set_text(TTR("Dictionary (Nil)")); // This provides symmetry with the array property.
edit->set_pressed(false);
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
return;
}
Expand All @@ -812,10 +816,14 @@ void EditorPropertyDictionary::update_property() {
if (unfolded) {
updating = true;

if (!vbox) {
vbox = memnew(VBoxContainer);
add_child(vbox);
set_bottom_editor(vbox);
if (!container) {
container = memnew(MarginContainer);
container->set_theme_type_variation("MarginContainer4px");
add_child(container);
set_bottom_editor(container);

VBoxContainer *vbox = memnew(VBoxContainer);
container->add_child(vbox);

property_vbox = memnew(VBoxContainer);
property_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -1116,11 +1124,11 @@ void EditorPropertyDictionary::update_property() {
updating = false;

} else {
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
}
}
Expand Down Expand Up @@ -1188,7 +1196,7 @@ EditorPropertyDictionary::EditorPropertyDictionary() {
add_child(edit);
add_focusable(edit);

vbox = nullptr;
container = nullptr;
button_add_item = nullptr;
paginator = nullptr;
change_type = memnew(PopupMenu);
Expand Down Expand Up @@ -1250,11 +1258,11 @@ void EditorPropertyLocalizableString::update_property() {
if (updated_val.get_type() == Variant::NIL) {
edit->set_text(TTR("Localizable String (Nil)")); // This provides symmetry with the array property.
edit->set_pressed(false);
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
return;
}
Expand All @@ -1271,10 +1279,14 @@ void EditorPropertyLocalizableString::update_property() {
if (unfolded) {
updating = true;

if (!vbox) {
vbox = memnew(VBoxContainer);
add_child(vbox);
set_bottom_editor(vbox);
if (!container) {
container = memnew(MarginContainer);
container->set_theme_type_variation("MarginContainer4px");
add_child(container);
set_bottom_editor(container);

VBoxContainer *vbox = memnew(VBoxContainer);
container->add_child(vbox);

property_vbox = memnew(VBoxContainer);
property_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
Expand Down Expand Up @@ -1351,11 +1363,11 @@ void EditorPropertyLocalizableString::update_property() {
updating = false;

} else {
if (vbox) {
if (container) {
set_bottom_editor(nullptr);
memdelete(vbox);
memdelete(container);
button_add_item = nullptr;
vbox = nullptr;
container = nullptr;
}
}
}
Expand Down Expand Up @@ -1410,7 +1422,7 @@ EditorPropertyLocalizableString::EditorPropertyLocalizableString() {
add_child(edit);
add_focusable(edit);

vbox = nullptr;
container = nullptr;
button_add_item = nullptr;
paginator = nullptr;
updating = false;
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_properties_array_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class EditorPropertyArray : public EditorProperty {
int page_index = 0;
int changing_type_index;
Button *edit = nullptr;
VBoxContainer *vbox = nullptr;
MarginContainer *container = nullptr;
VBoxContainer *property_vbox = nullptr;
EditorSpinSlider *size_slider = nullptr;
Button *button_add_item = nullptr;
Expand Down Expand Up @@ -146,9 +146,9 @@ class EditorPropertyDictionary : public EditorProperty {
int page_index = 0;
int changing_type_index;
Button *edit = nullptr;
VBoxContainer *vbox = nullptr;
MarginContainer *container = nullptr;
VBoxContainer *property_vbox = nullptr;
EditorSpinSlider *size_slider = nullptr;
EditorSpinSlider *size_sliderv;
Button *button_add_item = nullptr;
EditorPaginator *paginator = nullptr;

Expand Down Expand Up @@ -181,7 +181,7 @@ class EditorPropertyLocalizableString : public EditorProperty {
int page_length = 20;
int page_index = 0;
Button *edit = nullptr;
VBoxContainer *vbox = nullptr;
MarginContainer *container = nullptr;
VBoxContainer *property_vbox = nullptr;
EditorSpinSlider *size_slider = nullptr;
Button *button_add_item = nullptr;
Expand Down
13 changes: 12 additions & 1 deletion editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,13 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_constant("h_separation", "VFlowContainer", default_margin_size * EDSCALE);
theme->set_constant("v_separation", "VFlowContainer", default_margin_size * EDSCALE);

// Custom theme type for MarginContainer with 4px margins.
theme->set_type_variation("MarginContainer4px", "MarginContainer");
theme->set_constant("margin_left", "MarginContainer4px", 4 * EDSCALE);
theme->set_constant("margin_top", "MarginContainer4px", 4 * EDSCALE);
theme->set_constant("margin_right", "MarginContainer4px", 4 * EDSCALE);
theme->set_constant("margin_bottom", "MarginContainer4px", 4 * EDSCALE);

// Window

// Prevent corner artifacts between window title and body.
Expand Down Expand Up @@ -1626,7 +1633,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_stylebox("preview_picker_label", "ThemeEditor", theme_preview_picker_label_sb);

// Dictionary editor add item.
theme->set_stylebox("DictionaryAddItem", "EditorStyles", make_flat_stylebox(prop_subsection_color, 4, 4, 4, 4, corner_radius));
// Expand to the left and right by 4px to compensate for the dictionary editor margins.
Ref<StyleBoxFlat> style_dictionary_add_item = make_flat_stylebox(prop_subsection_color, 0, 4, 0, 4, corner_radius);
style_dictionary_add_item->set_expand_margin_size(SIDE_LEFT, 4 * EDSCALE);
style_dictionary_add_item->set_expand_margin_size(SIDE_RIGHT, 4 * EDSCALE);
theme->set_stylebox("DictionaryAddItem", "EditorStyles", style_dictionary_add_item);

// adaptive script theme constants
// for comments and elements with lower relevance
Expand Down

0 comments on commit 1847094

Please sign in to comment.