Skip to content

Commit

Permalink
Rename drawing utility RectExtensions to avoid collision with BCI
Browse files Browse the repository at this point in the history
  • Loading branch information
neilsarkar committed Jul 20, 2020
1 parent 1a084d4 commit 0a21ce0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 71 deletions.
128 changes: 64 additions & 64 deletions Editor/RectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
/// Utility extensions for manipulating Rect values. //TODO: Go through this
/// </summary>
public static class RectExtMethods {
public static Rect SetPosition(this Rect rect, Vector2 position) {
return rect.SetPosition(position.x, position.y);
public static Rect VioletSetPosition(this Rect rect, Vector2 position) {
return rect.VioletSetPosition(position.x, position.y);
}

public static Rect SetPosition(this Rect rect, float x, float y) {
public static Rect VioletSetPosition(this Rect rect, float x, float y) {
return new Rect(x, y, rect.width, rect.height);
}

public static Rect DisplaceX(this Rect rect, float x) {
public static Rect VioletDisplaceX(this Rect rect, float x) {
return new Rect(rect.x + x, rect.y, rect.width, rect.height);
}

public static Rect DisplaceY(this Rect rect, float y) {
public static Rect VioletDisplaceY(this Rect rect, float y) {
return new Rect(rect.x, rect.y + y, rect.width, rect.height);
}

public static Rect Displace(this Rect rect, float x, float y) {
public static Rect VioletDisplace(this Rect rect, float x, float y) {
return new Rect(rect.x + x, rect.y + y, rect.width, rect.height);
}

public static Rect Displace(this Rect rect, Vector2 displacement) {
public static Rect VioletDisplace(this Rect rect, Vector2 displacement) {
return new Rect(rect.position + displacement, rect.size);
}

public static Rect SetWidth(this Rect rect, float width) {
public static Rect VioletSetWidth(this Rect rect, float width) {
return new Rect(rect.x, rect.y, width, rect.height);
}

public static Rect SetHeight(this Rect rect, float height) {
public static Rect VioletSetHeight(this Rect rect, float height) {
return new Rect(rect.x, rect.y, rect.width, height);
}

public static Rect Transform(this Rect rect, Matrix4x4 matrix) {
public static Rect VioletTransform(this Rect rect, Matrix4x4 matrix) {
return new Rect(matrix.MultiplyPoint3x4(rect.position), matrix.MultiplyVector(rect.size));
}

Expand All @@ -48,36 +48,36 @@ public static float longestSide(this Rect rect) {
return Mathf.Max(rect.width, rect.height);
}

public static Rect SetSize(this Rect rect, float size) {
return rect.SetSize(Vector2.one * size);
public static Rect VioletSetSize(this Rect rect, float size) {
return rect.VioletSetSize(Vector2.one * size);
}

public static Rect SetSize(this Rect rect, float width, float height) {
return rect.SetSize(new Vector2(width, height));
public static Rect VioletSetSize(this Rect rect, float width, float height) {
return rect.VioletSetSize(new Vector2(width, height));
}

public static Rect SetSize(this Rect rect, Vector2 size) {
public static Rect VioletSetSize(this Rect rect, Vector2 size) {
return new Rect(rect.position, size);
}

public static Rect SetSizeCentered(this Rect rect, float size) {
return rect.SetSizeCentered(Vector2.one * size);
public static Rect VioletSetSizeCentered(this Rect rect, float size) {
return rect.VioletSetSizeCentered(Vector2.one * size);
}

public static Rect SetSizeCentered(this Rect rect, float width, float height) {
return rect.SetSizeCentered(new Vector2(width, height));
public static Rect VioletSetSizeCentered(this Rect rect, float width, float height) {
return rect.VioletSetSizeCentered(new Vector2(width, height));
}

public static Rect SetSizeCentered(this Rect rect, Vector2 size) {
public static Rect VioletSetSizeCentered(this Rect rect, Vector2 size) {
return new Rect(rect.center - size * 0.5f, size);
}

#region Transalation
public static Rect Translate(this Rect rect, float x, float y) {
return Translate(rect, new Vector2(x, y));
public static Rect VioletTranslate(this Rect rect, float x, float y) {
return VioletTranslate(rect, new Vector2(x, y));
}

public static Rect Translate(this Rect rect, Vector2 translation) {
public static Rect VioletTranslate(this Rect rect, Vector2 translation) {
return new Rect(rect.position + translation, rect.size);
}
#endregion
Expand All @@ -90,10 +90,10 @@ public static Rect Translate(this Rect rect, Vector2 translation) {
/// <param name="inset">Inset width.</param>
/// <param name="result">Inset Rect.</param>
/// <returns></returns>
public static Rect SplitRight(this Rect rect, float inset, out Rect result) {
public static Rect VioletSplitRight(this Rect rect, float inset, out Rect result) {
result = new Rect(rect.x + rect.width - inset, rect.y, inset, rect.height);

return rect.PadRight(inset);
return rect.VioletPadRight(inset);
}

/// <summary>
Expand All @@ -103,10 +103,10 @@ public static Rect SplitRight(this Rect rect, float inset, out Rect result) {
/// <param name="inset">Inset width.</param>
/// <param name="result">Inset Rect.</param>
/// <returns></returns>
public static Rect SplitLeft(this Rect rect, float inset, out Rect result) {
public static Rect VioletSplitLeft(this Rect rect, float inset, out Rect result) {
result = new Rect(rect.x, rect.y, inset, rect.height);

return rect.PadLeft(inset);
return rect.VioletPadLeft(inset);
}

/// <summary>
Expand All @@ -116,10 +116,10 @@ public static Rect SplitLeft(this Rect rect, float inset, out Rect result) {
/// <param name="inset">Inset height.</param>
/// <param name="result">Inset Rect.</param>
/// <returns></returns>
public static Rect SplitBottom(this Rect rect, float inset, out Rect result) {
public static Rect VioletSplitBottom(this Rect rect, float inset, out Rect result) {
result = new Rect(rect.x, rect.y + rect.height - inset, rect.width, inset);

return rect.PadBottom(inset);
return rect.VioletPadBottom(inset);
}

/// <summary>
Expand All @@ -129,10 +129,10 @@ public static Rect SplitBottom(this Rect rect, float inset, out Rect result) {
/// <param name="inset">Inset height.</param>
/// <param name="result">Inset Rect.</param>
/// <returns></returns>
public static Rect SplitTop(this Rect rect, float inset, out Rect result) {
public static Rect VioletSplitTop(this Rect rect, float inset, out Rect result) {
result = new Rect(rect.x, rect.y, rect.width, inset);

return rect.PadTop(inset);
return rect.VioletPadTop(inset);
}
#endregion

Expand All @@ -143,8 +143,8 @@ public static Rect SplitTop(this Rect rect, float inset, out Rect result) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect Pad(this Rect rect, float padding) {
return Pad(rect, padding, padding, padding, padding);
public static Rect VioletPad(this Rect rect, float padding) {
return VioletPad(rect, padding, padding, padding, padding);
}

/// <summary>
Expand All @@ -153,8 +153,8 @@ public static Rect Pad(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadLeft(this Rect rect, float padding) {
return Pad(rect, padding, 0.0f, 0.0f, 0.0f);
public static Rect VioletPadLeft(this Rect rect, float padding) {
return VioletPad(rect, padding, 0.0f, 0.0f, 0.0f);
}

/// <summary>
Expand All @@ -163,8 +163,8 @@ public static Rect PadLeft(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadRight(this Rect rect, float padding) {
return Pad(rect, 0.0f, padding, 0.0f, 0.0f);
public static Rect VioletPadRight(this Rect rect, float padding) {
return VioletPad(rect, 0.0f, padding, 0.0f, 0.0f);
}

/// <summary>
Expand All @@ -173,8 +173,8 @@ public static Rect PadRight(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadTop(this Rect rect, float padding) {
return Pad(rect, 0.0f, 0.0f, padding, 0.0f);
public static Rect VioletPadTop(this Rect rect, float padding) {
return VioletPad(rect, 0.0f, 0.0f, padding, 0.0f);
}

/// <summary>
Expand All @@ -183,8 +183,8 @@ public static Rect PadTop(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadBottom(this Rect rect, float padding) {
return Pad(rect, 0.0f, 0.0f, 0.0f, padding);
public static Rect VioletPadBottom(this Rect rect, float padding) {
return VioletPad(rect, 0.0f, 0.0f, 0.0f, padding);
}

/// <summary>
Expand All @@ -193,8 +193,8 @@ public static Rect PadBottom(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadHorizontal(this Rect rect, float padding) {
return Pad(rect, padding, padding, 0.0f, 0.0f);
public static Rect VioletPadHorizontal(this Rect rect, float padding) {
return VioletPad(rect, padding, padding, 0.0f, 0.0f);
}

/// <summary>
Expand All @@ -203,76 +203,76 @@ public static Rect PadHorizontal(this Rect rect, float padding) {
/// <param name="rect">Rect to pad.</param>
/// <param name="padding">Amount to pad.</param>
/// <returns>Padded Rect.</returns>
public static Rect PadVertical(this Rect rect, float padding) {
return Pad(rect, 0.0f, 0.0f, padding, padding);
public static Rect VioletPadVertical(this Rect rect, float padding) {
return VioletPad(rect, 0.0f, 0.0f, padding, padding);
}

/// <summary>
/// Pad a Rect from its left, right, top, and bottom edges.
/// </summary>
/// <param name="rect">Rect to pad.</param>
/// <param name="left">Amount to pad left edge.</param>
/// <param name="right">Amount to pad left edge.</param>
/// <param name="top">Amount to pad left edge.</param>
/// <param name="right">Amount to pad right edge.</param>
/// <param name="top">Amount to pad top edge.</param>
/// <param name="bottom">Amount to pad left edge.</param>
/// <returns>Padded Rect.</returns>
public static Rect Pad(this Rect rect, float left, float right, float top, float bottom) {
public static Rect VioletPad(this Rect rect, float left, float right, float top, float bottom) {
return new Rect(rect.x + left, rect.y + top, rect.width - left - right, rect.height - top - bottom);
}
#endregion

#region Sequencing
public static Rect StepDown(this Rect rect, float padding = 0.0f) {
public static Rect VioletStepDown(this Rect rect, float padding = 0.0f) {
return new Rect(rect.x, rect.y + rect.height + padding, rect.width, rect.height);
}

public static Rect StepUp(this Rect rect, float padding = 0.0f) {
public static Rect VioletStepUp(this Rect rect, float padding = 0.0f) {
return new Rect(rect.x, rect.y - rect.height - padding, rect.width, rect.height);
}

public static Rect StepLeft(this Rect rect, float padding = 0.0f) {
public static Rect VioletStepLeft(this Rect rect, float padding = 0.0f) {
return new Rect(rect.x - rect.width - padding, rect.y, rect.width, rect.height);
}

public static Rect StepRight(this Rect rect, float padding = 0.0f) {
public static Rect VioletStepRight(this Rect rect, float padding = 0.0f) {
return new Rect(rect.x + rect.width + padding, rect.y, rect.width, rect.height);
}
#endregion

#region Extrusions
public static Rect ExtrudeLeft(this Rect rect, float width) {
public static Rect VioletExtrudeLeft(this Rect rect, float width) {
return new Rect(rect.x - width, rect.y, width, rect.height);
}

public static Rect ExtrudeRight(this Rect rect, float width) {
public static Rect VioletExtrudeRight(this Rect rect, float width) {
return new Rect(rect.x + rect.width, rect.y, width, rect.height);
}

public static Rect ExtrudeTop(this Rect rect, float height) {
public static Rect VioletExtrudeTop(this Rect rect, float height) {
return new Rect(rect.x, rect.y - height, rect.width, height);
}

public static Rect ExtrudeBottom(this Rect rect, float height) {
public static Rect VioletExtrudeBottom(this Rect rect, float height) {
return new Rect(rect.x, rect.y + rect.height, rect.width, height);
}
#endregion


#region Backfills
public static Rect BackfillLeft(this Rect rect, float width) {
return rect.PadRight(rect.width - width);
public static Rect VioletBackfillLeft(this Rect rect, float width) {
return rect.VioletPadRight(rect.width - width);
}

public static Rect BackfillRight(this Rect rect, float width) {
return rect.PadLeft(rect.width - width);
public static Rect VioletBackfillRight(this Rect rect, float width) {
return rect.VioletPadLeft(rect.width - width);
}

public static Rect BackfillTop(this Rect rect, float height) {
return rect.PadBottom(rect.height - height);
public static Rect VioletBackfillTop(this Rect rect, float height) {
return rect.VioletPadBottom(rect.height - height);
}

public static Rect BackfillBottom(this Rect rect, float height) {
return rect.PadTop(rect.height - height);
public static Rect VioletBackfillBottom(this Rect rect, float height) {
return rect.VioletPadTop(rect.height - height);
}
#endregion

Expand Down
13 changes: 6 additions & 7 deletions Editor/ScreenEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ private static GUIStyle InitStyle(ref GUIStyle style, GUIStyle original, TextAnc

return style;
}

private static bool Button(Rect rect, string label, string tooltip, Color color, FontStyle fontStyle = FontStyle.Normal, int dot = 0, int i = 0, int n = 1) {
rect = rect.BackfillRight(BUTTON_WIDTH);
rect = rect.VioletBackfillRight(BUTTON_WIDTH);

GUIStyle style = null;

Expand Down Expand Up @@ -108,20 +107,20 @@ private static bool Button(Rect rect, string label, string tooltip, Color color,
shadowColor.a = 0.8f;

if (dot > 0) {
var dotRect = rect.BackfillRight(rect.height).DisplaceX(1f)/*.Pad( 4f )*/;
var dotRect = rect.VioletBackfillRight(rect.width - rect.height).VioletDisplaceX(1f)/*.Pad( 4f )*/;
var dotColor = dot == 2 ? color : Color.grey;

dotColor.a = 0.5f;

GUI.Box(dotRect, GUIContent.none);
EditorGUI.DrawRect(dotRect.Pad(3f).DisplaceX(-1f), dotColor);
EditorGUI.DrawRect(dotRect.VioletPad(3f).VioletDisplaceX(-1f), dotColor);

}

rect = rect.SetWidth(3f).DisplaceX(4f).PadVertical(1f);
rect = rect.VioletSetWidth(3f).VioletDisplaceX(4f).VioletPadVertical(1f);

EditorGUI.DrawRect(rect.ExtrudeLeft(1f), shadowColor);
EditorGUI.DrawRect(rect.ExtrudeRight(1f), shadowColor);
EditorGUI.DrawRect(rect.VioletExtrudeLeft(1f), shadowColor);
EditorGUI.DrawRect(rect.VioletExtrudeRight(1f), shadowColor);

color.a = 0.5f;

Expand Down

0 comments on commit 0a21ce0

Please sign in to comment.