2019-05-07 16:37:50 -04:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace UnityAtoms
|
|
|
|
{
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Utility methods for IMGUI.
|
|
|
|
/// </summary>
|
2019-10-13 16:47:22 -04:00
|
|
|
public static class IMGUIUtils
|
2019-05-07 16:37:50 -04:00
|
|
|
{
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Snip a `Rect` horizontally.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rect">The rect.</param>
|
|
|
|
/// <param name="range">The range.</param>
|
|
|
|
/// <returns>A new `Rect` snipped horizontally.</returns>
|
|
|
|
|
2019-05-07 16:37:50 -04:00
|
|
|
private static Rect SnipRectH(Rect rect, float range)
|
|
|
|
{
|
|
|
|
if (range == 0) return new Rect(rect);
|
|
|
|
if (range > 0)
|
|
|
|
{
|
|
|
|
return new Rect(rect.x, rect.y, range, rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Rect(rect.x + rect.width + range, rect.y, -range, rect.height);
|
|
|
|
}
|
|
|
|
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Snip a `Rect` horizontally.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rect">The rect.</param>
|
|
|
|
/// <param name="range">The range.</param>
|
|
|
|
/// <param name="rest">Rest rect.</param>
|
|
|
|
/// <param name="gutter">Gutter</param>
|
|
|
|
/// <returns>A new `Rect` snipped horizontally.</returns>
|
2019-05-07 16:37:50 -04:00
|
|
|
public static Rect SnipRectH(Rect rect, float range, out Rect rest, float gutter = 0f)
|
|
|
|
{
|
|
|
|
if (range == 0) rest = new Rect();
|
|
|
|
if (range > 0)
|
|
|
|
{
|
|
|
|
rest = new Rect(rect.x + range + gutter, rect.y, rect.width - range - gutter, rect.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rest = new Rect(rect.x, rect.y, rect.width + range + gutter, rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SnipRectH(rect, range);
|
|
|
|
}
|
|
|
|
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Snip a `Rect` vertically.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rect">The rect.</param>
|
|
|
|
/// <param name="range">The range.</param>
|
|
|
|
/// <returns>A new `Rect` snipped vertically.</returns>
|
2019-05-07 16:37:50 -04:00
|
|
|
private static Rect SnipRectV(Rect rect, float range)
|
|
|
|
{
|
|
|
|
if (range == 0) return new Rect(rect);
|
|
|
|
if (range > 0)
|
|
|
|
{
|
|
|
|
return new Rect(rect.x, rect.y, rect.width, range);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Rect(rect.x, rect.y + rect.height + range, rect.width, -range);
|
|
|
|
}
|
|
|
|
|
2019-10-15 13:19:44 -04:00
|
|
|
/// <summary>
|
|
|
|
/// Snip a `Rect` vertically.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="rect">The rect.</param>
|
|
|
|
/// <param name="range">The range.</param>
|
|
|
|
/// <param name="rest">Rest rect.</param>
|
|
|
|
/// <param name="gutter">Gutter</param>
|
|
|
|
/// <returns>A new `Rect` snipped vertically.</returns>
|
2019-05-07 16:37:50 -04:00
|
|
|
public static Rect SnipRectV(Rect rect, float range, out Rect rest, float gutter = 0f)
|
|
|
|
{
|
|
|
|
if (range == 0) rest = new Rect();
|
|
|
|
if (range > 0)
|
|
|
|
{
|
|
|
|
rest = new Rect(rect.x, rect.y + range + gutter, rect.width, rect.height - range - gutter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rest = new Rect(rect.x, rect.y, rect.width, rect.height + range + gutter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SnipRectV(rect, range);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|