using UnityEngine; namespace UnityAtoms { /// /// Utility methods for IMGUI. /// public static class IMGUIUtils { /// /// Snip a `Rect` horizontally. /// /// The rect. /// The range. /// A new `Rect` snipped horizontally. 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); } /// /// Snip a `Rect` horizontally. /// /// The rect. /// The range. /// Rest rect. /// Gutter /// A new `Rect` snipped horizontally. 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); } /// /// Snip a `Rect` vertically. /// /// The rect. /// The range. /// A new `Rect` snipped vertically. 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); } /// /// Snip a `Rect` vertically. /// /// The rect. /// The range. /// Rest rect. /// Gutter /// A new `Rect` snipped vertically. 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); } } }