GUILayoutUtility.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup GUI-Engine
  8. * @{
  9. */
  10. /// <summary>
  11. /// Helper class that performs various operations related to
  12. /// GUILayout and GUI element sizing/placement.
  13. /// </summary>
  14. public class GUILayoutUtility
  15. {
  16. /// <summary>
  17. /// Calculates optimal size of a GUI element.
  18. /// </summary>
  19. /// <param name="element">GUI element to calculate the optimal size for.</param>
  20. /// <returns>Size that allows the GUI element to properly display all of its content.</returns>
  21. public static Vector2I CalculateOptimalSize(GUIElement element)
  22. {
  23. Vector2I output;
  24. Internal_CalculateOptimalSize(element.GetCachedPtr(), out output);
  25. return output;
  26. }
  27. /// <summary>
  28. /// Calculates the bounds of a GUI element. This is similar to <see cref="GUIElement.Bounds"/> but allows you to
  29. /// returns bounds relative to a specific parent GUI panel.
  30. /// </summary>
  31. /// <param name="element">Elements to calculate the bounds for.</param>
  32. /// <param name="relativeTo">GUI panel the bounds will be relative to. If this is null or the provided panel is not
  33. /// a parent of the provided GUI element, the returned bounds will be relative to the
  34. /// first GUI panel parent instead.</param>
  35. /// <returns>Bounds of a GUI element relative to the provided GUI panel.</returns>
  36. public static Rect2I CalculateBounds(GUIElement element, GUIPanel relativeTo = null)
  37. {
  38. IntPtr relativeToNative = IntPtr.Zero;
  39. if (relativeTo != null)
  40. relativeToNative = relativeTo.GetCachedPtr();
  41. Rect2I output;
  42. Internal_CalculateBounds(element.GetCachedPtr(), relativeToNative, out output);
  43. return output;
  44. }
  45. [MethodImpl(MethodImplOptions.InternalCall)]
  46. private static extern void Internal_CalculateOptimalSize(IntPtr element, out Vector2I output);
  47. [MethodImpl(MethodImplOptions.InternalCall)]
  48. private static extern void Internal_CalculateBounds(IntPtr element, IntPtr relativeTo, out Rect2I output);
  49. }
  50. /** @} */
  51. }