BsGUIHelper.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsPrerequisites.h"
  5. #include "BsTextSprite.h"
  6. #include "BsGUIContent.h"
  7. namespace bs
  8. {
  9. /** @addtogroup GUI-Internal
  10. * @{
  11. */
  12. /** Contains various helper methods used by GUI. */
  13. class BS_EXPORT GUIHelper
  14. {
  15. public:
  16. /**
  17. * Calculates optimal content size by returning the nearest valid size to the provided value.
  18. *
  19. * @param[in] contentSize Wanted content size. This will be limited by minimal constraints of the style and
  20. * layout options.
  21. * @param[in] style Style to use for determining size constraints.
  22. * @param[in] dimensions Dimension constraints of a GUI element.
  23. */
  24. static Vector2I calcOptimalContentsSize(const Vector2I& contentSize, const GUIElementStyle& style,
  25. const GUIDimensions& dimensions);
  26. /**
  27. * Calculates optimal content size for the provided content using the provided style and layout options for
  28. * constraints.
  29. *
  30. * @param[in] content Content to calculate size for.
  31. * @param[in] style Style to use for determining size constraints.
  32. * @param[in] dimensions Dimension constraints of a GUI element.
  33. * @param[in] state State of the GUI element in case the content changes according to state.
  34. */
  35. static Vector2I calcOptimalContentsSize(const GUIContent& content, const GUIElementStyle& style,
  36. const GUIDimensions& dimensions, GUIElementState state = GUIElementState::Normal);
  37. /**
  38. * Calculates optimal content size for the provided text using the provided style and layout options for
  39. * constraints.
  40. *
  41. * @param[in] text Text to calculate size for.
  42. * @param[in] style Style to use for determining size constraints.
  43. * @param[in] dimensions Dimension constraints of a GUI element.
  44. */
  45. static Vector2I calcOptimalContentsSize(const WString& text, const GUIElementStyle& style,
  46. const GUIDimensions& dimensions);
  47. /**
  48. * Calculates optimal content size for the provided text using the provided font and size. Size is calculated
  49. * without word wrap.
  50. *
  51. * @param[in] text Text to calculate the size for.
  52. * @param[in] font Font to use for rendering the text.
  53. * @param[in] fontSize Size of individual characters in the font, in points.
  54. * @return Width/height required to display the text, in pixels.
  55. */
  56. static Vector2I calcTextSize(const WString& text, const HFont& font, UINT32 fontSize);
  57. };
  58. /** @} */
  59. }