diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 64428e95060..7f1f8df11e5 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -779,7 +779,7 @@ float CanvasItemEditor::_anchor_snap(float p_anchor, bool *p_snapped, float p_op bool snapped = false; float dist, dist_min = 0.0; float radius = 0.05 / zoom; - float basic_anchors[3] = { ANCHOR_BEGIN, ANCHOR_CENTER, ANCHOR_END }; + float basic_anchors[3] = { 0.0, 0.5, 1.0 }; for (int i = 0; i < 3; i++) { if ((dist = fabs(p_anchor - basic_anchors[i])) < radius) { if (!snapped || dist <= dist_min) { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index f68132f4ff3..c97426ad427 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1363,7 +1363,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { case PRESET_CENTER_BOTTOM: case PRESET_CENTER: case PRESET_VCENTER_WIDE: - set_anchor(MARGIN_LEFT, ANCHOR_CENTER, p_keep_margin); + set_anchor(MARGIN_LEFT, 0.5, p_keep_margin); break; case PRESET_TOP_RIGHT: @@ -1391,7 +1391,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { case PRESET_CENTER_RIGHT: case PRESET_CENTER: case PRESET_HCENTER_WIDE: - set_anchor(MARGIN_TOP, ANCHOR_CENTER, p_keep_margin); + set_anchor(MARGIN_TOP, 0.5, p_keep_margin); break; case PRESET_BOTTOM_LEFT: @@ -1415,7 +1415,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { case PRESET_CENTER_BOTTOM: case PRESET_CENTER: case PRESET_VCENTER_WIDE: - set_anchor(MARGIN_RIGHT, ANCHOR_CENTER, p_keep_margin); + set_anchor(MARGIN_RIGHT, 0.5, p_keep_margin); break; case PRESET_TOP_RIGHT: @@ -1443,7 +1443,7 @@ void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin) { case PRESET_CENTER_RIGHT: case PRESET_CENTER: case PRESET_HCENTER_WIDE: - set_anchor(MARGIN_BOTTOM, ANCHOR_CENTER, p_keep_margin); + set_anchor(MARGIN_BOTTOM, 0.5, p_keep_margin); break; case PRESET_BOTTOM_LEFT: @@ -2694,6 +2694,9 @@ void Control::_bind_methods() { BIND_CONSTANT(GROW_DIRECTION_BEGIN); BIND_CONSTANT(GROW_DIRECTION_END); + BIND_CONSTANT(ANCHOR_BEGIN); + BIND_CONSTANT(ANCHOR_END); + ADD_SIGNAL(MethodInfo("resized")); ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ADD_SIGNAL(MethodInfo("mouse_entered")); diff --git a/scene/gui/control.h b/scene/gui/control.h index 60d835044a5..d73ca3f7c9c 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -51,9 +51,11 @@ class Control : public CanvasItem { OBJ_CATEGORY("GUI Nodes"); public: - static const float ANCHOR_BEGIN = 0.0f; - static const float ANCHOR_CENTER = 0.5f; - static const float ANCHOR_END = 1.0f; + enum Anchor { + + ANCHOR_BEGIN = 0, + ANCHOR_END = 1 + }; enum GrowDirection { GROW_DIRECTION_BEGIN, @@ -449,5 +451,6 @@ VARIANT_ENUM_CAST(Control::CursorShape); VARIANT_ENUM_CAST(Control::LayoutPreset); VARIANT_ENUM_CAST(Control::MouseFilter); VARIANT_ENUM_CAST(Control::GrowDirection); +VARIANT_ENUM_CAST(Control::Anchor); #endif