Advertisement
Guest User

Untitled

a guest
Oct 8th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. NewGuiRectAligner = function()
  2. return NewSceneNode() where
  3. Class = $RectAlignerClass
  4. end
  5. end
  6.  
  7. GuiRectAlignerClass = $GuiRectAlignableClass.Copy() where
  8.  
  9. HorizontalMode
  10. HorizontalPad
  11. VerticalMode
  12. VerticalPad
  13.  
  14. RectAlignChildren = method()
  15.  
  16. //scan children
  17. foreach Children() as node
  18. if not $node.$IsGuiRectAlignable then continue end
  19. childrenSize += $node.$Size
  20. childCount += 1
  21. end
  22.  
  23. //get horizontal settings
  24. select $HorizontalMode
  25. case Left
  26. x = 0
  27. xAdvance = $HorizontalPad
  28. case Center
  29. x = ($Size.$x - $childrenSize.$x) / 2
  30. xAdvance = $HorizontalPad
  31. case Right
  32. x = $Size.$x - $childrenSize.$x
  33. xAdvance = $HorizontalPad
  34. case Justified
  35. x = 0
  36. if $childCount <= 1 then xAdvance = 0 else xAdvance = ($Size.$x - $childrenSize.$x) / ($childCount - 1) end
  37. end
  38.  
  39. //get vertical settings
  40. select $VerticalMode
  41. case Top
  42. y = 0
  43. yStep = $VerticalPad
  44. case Center
  45. y = ($Size.$y - $childrenSize.$y) / 2
  46. yAdvance = $VerticalPad
  47. case Bottom
  48. y = $Size.$y - $childrenSize.$y
  49. yAdvance = $VerticalPad
  50. case Justified
  51. y = 0
  52. if $childCount <= 1 then yAdvance = 0 else yAdvance = ($Size.$y - $childrenSize.$y) / ($childCount - 1) end
  53. end
  54.  
  55. position |$x,$y|
  56. advance = |$xAdvance,$yAdvance|
  57.  
  58. //align
  59. foreach Children() as node
  60. if not $node.$IsGuiRectAlignable then continue end
  61. $node.Position = $position - $node.$Offset
  62. position += $node.$Size + $advance
  63. end
  64.  
  65. end
  66.  
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement