diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 7ce884a4558..bd99aa17bbe 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -2239,6 +2239,7 @@ void CanvasItemEditor::_notification(int p_what) { p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE); p->add_separator(); p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE); + p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT); AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed"); _keying_changed(); @@ -2444,6 +2445,35 @@ void CanvasItemEditor::_set_anchor(Control::AnchorType p_left, Control::AnchorTy undo_redo->commit_action(); } +void CanvasItemEditor::_set_full_rect() { + List &selection = editor_selection->get_selected_node_list(); + + undo_redo->create_action(TTR("Change Anchors")); + for (List::Element *E = selection.front(); E; E = E->next()) { + + Control *c = E->get()->cast_to(); + + undo_redo->add_do_method(c, "set_anchor", MARGIN_LEFT, ANCHOR_BEGIN); + undo_redo->add_do_method(c, "set_anchor", MARGIN_TOP, ANCHOR_BEGIN); + undo_redo->add_do_method(c, "set_anchor", MARGIN_RIGHT, ANCHOR_END); + undo_redo->add_do_method(c, "set_anchor", MARGIN_BOTTOM, ANCHOR_END); + undo_redo->add_do_method(c, "set_margin", MARGIN_LEFT, 0); + undo_redo->add_do_method(c, "set_margin", MARGIN_TOP, 0); + undo_redo->add_do_method(c, "set_margin", MARGIN_RIGHT, 0); + undo_redo->add_do_method(c, "set_margin", MARGIN_BOTTOM, 0); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_TOP, c->get_anchor(MARGIN_TOP)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_RIGHT, c->get_anchor(MARGIN_RIGHT)); + undo_redo->add_undo_method(c, "set_anchor", MARGIN_BOTTOM, c->get_anchor(MARGIN_BOTTOM)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_LEFT, c->get_margin(MARGIN_LEFT)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_TOP, c->get_margin(MARGIN_TOP)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_RIGHT, c->get_margin(MARGIN_RIGHT)); + undo_redo->add_undo_method(c, "set_margin", MARGIN_BOTTOM, c->get_margin(MARGIN_BOTTOM)); + } + + undo_redo->commit_action(); +} + void CanvasItemEditor::_popup_callback(int p_op) { last_option = MenuOption(p_op); @@ -2601,29 +2631,6 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; - case EXPAND_TO_PARENT: { - - List &selection = editor_selection->get_selected_node_list(); - - for (List::Element *E = selection.front(); E; E = E->next()) { - - CanvasItem *canvas_item = E->get()->cast_to(); - if (!canvas_item || !canvas_item->is_visible_in_tree()) - continue; - - if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) - continue; - - Control *c = canvas_item->cast_to(); - if (!c) - continue; - c->set_area_as_parent_rect(); - } - - viewport->update(); - - } break; - case ALIGN_VERTICAL: { #if 0 if ( ref_item && canvas_items.size() > 1 ) { @@ -2716,6 +2723,9 @@ void CanvasItemEditor::_popup_callback(int p_op) { case ANCHOR_ALIGN_WIDE: { _set_anchor(ANCHOR_BEGIN, ANCHOR_BEGIN, ANCHOR_END, ANCHOR_END); } break; + case ANCHOR_ALIGN_WIDE_FIT: { + _set_full_rect(); + } break; case ANIM_INSERT_KEY: case ANIM_INSERT_KEY_EXISTING: { @@ -3331,8 +3341,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_pixel_snap", TTR("Use Pixel Snap")), SNAP_USE_PIXEL); p->add_separator(); - p->add_shortcut(ED_SHORTCUT("canvas_item_editor/expand_to_parent", TTR("Expand to Parent"), KEY_MASK_CMD | KEY_P), EXPAND_TO_PARENT); - p->add_separator(); p->add_submenu_item(TTR("Skeleton.."), "skeleton"); skeleton_menu = memnew(PopupMenu); p->add_child(skeleton_menu); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 702deb51f9a..f40a7cbc4ad 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -111,10 +111,10 @@ class CanvasItemEditor : public VBoxContainer { ANCHOR_ALIGN_VCENTER_WIDE, ANCHOR_ALIGN_HCENTER_WIDE, ANCHOR_ALIGN_WIDE, + ANCHOR_ALIGN_WIDE_FIT, SPACE_HORIZONTAL, SPACE_VERTICAL, - EXPAND_TO_PARENT, ANIM_INSERT_KEY, ANIM_INSERT_KEY_EXISTING, ANIM_INSERT_POS, @@ -361,6 +361,7 @@ class CanvasItemEditor : public VBoxContainer { void _focus_selection(int p_op); void _set_anchor(Control::AnchorType p_left, Control::AnchorType p_top, Control::AnchorType p_right, Control::AnchorType p_bottom); + void _set_full_rect(); HSplitContainer *palette_split; VSplitContainer *bottom_split;