public static string GetAnchorAsString(this MagicUIAnchorType me) { int left = me.GetAnchor(MagicUIAnchorType.Left) ? 1 : 0; int right = me.GetAnchor(MagicUIAnchorType.Right) ? 1 : 0; int top = me.GetAnchor(MagicUIAnchorType.Top) ? 1 : 0; int bottom = me.GetAnchor(MagicUIAnchorType.Bottom) ? 1 : 0; return(string.Format("{0}{1}{2}{3}", left, right, top, bottom)); }
public static bool GetAnchor(this MagicUIAnchorType me, MagicUIAnchorType side) { if (side == MagicUIAnchorType.None) { return(false); } return((me & side) == side); }
public static MagicUIAnchorType SetAnchor(this MagicUIAnchorType me, MagicUIAnchorType side, bool isSet) { MagicUIAnchorType result = me & ~side; if (isSet) { result = result | side; } return(result); }
public static MagicUIAnchorType SetAnchor(this MagicUIAnchorType me, string all) { MagicUIAnchorType result = MagicUIAnchorType.None; if (!string.IsNullOrEmpty(all)) { result = result.SetAnchor(MagicUIAnchorType.Left, all.Length > 0 && all[0] == '1'); result = result.SetAnchor(MagicUIAnchorType.Right, all.Length > 1 && all[1] == '1'); result = result.SetAnchor(MagicUIAnchorType.Top, all.Length > 2 && all[2] == '1'); result = result.SetAnchor(MagicUIAnchorType.Bottom, all.Length > 3 && all[3] == '1'); } return(result); }
protected override Rect calculateExtents(Rect bounds, MagicUIAnchorType anchors) { Vector2 expected = _container.ExpectedSize; Vector2 extra = _container.ExtraSize; float left = bounds.x * expected.x; float top = bounds.y * expected.y; float width = bounds.width * expected.x; float height = bounds.height * expected.y; _expected = new Vector2(width, height); if (anchors.GetAnchor(MagicUIAnchorType.Left) && anchors.GetAnchor(MagicUIAnchorType.Right)) { width += extra.x; } else if (!anchors.GetAnchor(MagicUIAnchorType.Left) && !anchors.GetAnchor(MagicUIAnchorType.Right)) { left += extra.x * 0.5f; } else if (anchors.GetAnchor(MagicUIAnchorType.Right)) { left += extra.x; } //else if (anchors.GetAnchor(MagicUIAnchorType.Left)) Do nothing if (anchors.GetAnchor(MagicUIAnchorType.Top) && anchors.GetAnchor(MagicUIAnchorType.Bottom)) { height += extra.y; } else if (!anchors.GetAnchor(MagicUIAnchorType.Top) && !anchors.GetAnchor(MagicUIAnchorType.Bottom)) { top += extra.y * 0.5f; } else if (anchors.GetAnchor(MagicUIAnchorType.Bottom)) { top += extra.y; } //else if (anchors.GetAnchor(MagicUIAnchorType.Left)) Do nothing _extra = new Vector2(width, height) - _expected; Vector2 actual = expected + extra; return(new Rect(left - (0.5f * actual.x), (0.5f * actual.y) - top, width, height)); }