30 using System.Collections.Generic;
31 using System.ComponentModel;
40 private Sizing _horizontalSizing;
41 private Sizing _verticalSizing;
42 private Vector _preferredSize;
43 private double _spaceRequestedByExpandingObjects;
44 private double _spaceRequestedByFixedSizeObjects;
45 private double _spacing = 0;
46 private double _topPadding = 0;
47 private double _bottomPadding = 0;
48 private double _leftPadding = 0;
49 private double _rightPadding = 0;
51 [EditorBrowsable(EditorBrowsableState.Never)]
59 get {
return _spacing; }
60 set { _spacing = value; NotifyParent(); }
68 get {
return _topPadding; }
69 set { _topPadding = value; NotifyParent(); }
77 get {
return _bottomPadding; }
78 set { _bottomPadding = value; NotifyParent(); }
86 get {
return _leftPadding; }
87 set { _leftPadding = value; NotifyParent(); }
95 get {
return _rightPadding; }
96 set { _rightPadding = value; NotifyParent(); }
99 private void NotifyParent()
114 [EditorBrowsable(EditorBrowsableState.Never)]
117 if (objects.Count == 0)
120 double maxHeight = 0;
121 double widthOfExpandingObjects = 0;
122 double widthOfFixedSizeObjects = 0;
126 foreach (var o
in objects)
128 if (o.PreferredSize.Y > maxHeight)
130 maxHeight = o.PreferredSize.Y;
133 if (o.HorizontalSizing ==
Sizing.Expanding)
135 widthOfExpandingObjects += o.PreferredSize.X;
136 horizontalSizing =
Sizing.Expanding;
138 else if (o.HorizontalSizing ==
Sizing.FixedSize)
140 widthOfFixedSizeObjects += o.PreferredSize.X;
143 if (o.VerticalSizing !=
Sizing.FixedSize)
145 verticalSizing =
Sizing.Expanding;
152 _horizontalSizing = horizontalSizing;
153 _verticalSizing = verticalSizing;
154 _spaceRequestedByExpandingObjects = widthOfExpandingObjects;
155 _spaceRequestedByFixedSizeObjects = widthOfFixedSizeObjects;
156 _preferredSize =
new Vector(preferredWidth, preferredHeight);
159 [EditorBrowsable(EditorBrowsableState.Never)]
162 get {
return _horizontalSizing; }
165 [EditorBrowsable(EditorBrowsableState.Never)]
168 get {
return _verticalSizing; }
171 [EditorBrowsable(EditorBrowsableState.Never)]
174 get {
return _preferredSize; }
178 [EditorBrowsable(EditorBrowsableState.Never)]
184 double fixedScale = 1.0;
185 double expandingScale = 0.0;
187 double availableSpaceForObjects = contentWidth - (objects.Count - 1) *
Spacing;
189 if ((availableSpaceForObjects < _spaceRequestedByFixedSizeObjects) && (_spaceRequestedByFixedSizeObjects > 0.0))
192 fixedScale = availableSpaceForObjects / _spaceRequestedByFixedSizeObjects;
197 else if ((maximumSize.
X <
PreferredSize.
X) && (_spaceRequestedByExpandingObjects > 0.0))
204 double availableSpaceForExpandingObjects = availableSpaceForObjects - _spaceRequestedByFixedSizeObjects;
205 expandingScale = availableSpaceForExpandingObjects / _spaceRequestedByExpandingObjects;
213 if (_spaceRequestedByExpandingObjects > 0)
216 expandingScale = (availableSpaceForObjects - _spaceRequestedByFixedSizeObjects) / _spaceRequestedByExpandingObjects;
220 foreach (var o
in objects)
222 double scale = (o.HorizontalSizing ==
Sizing.FixedSize) ? fixedScale : expandingScale;
223 double width = o.PreferredSize.X * scale;
224 double height = o.PreferredSize.Y;
226 if ((o.PreferredSize.Y > contentHeight) || (o.VerticalSizing ==
Sizing.Expanding))
228 height = contentHeight;
231 o.Size =
new Vector(width, height);
232 o.X = left + width / 2;
233 o.Y = (maximumSize.Y / 2) - (
TopPadding + contentHeight / 2);
double LeftPadding
Vasempaan reunaan jäävä tyhjä tila.
Rajapinta asettelijalle. Asettelija asettelee widgetin lapsioliot siten, että ne mahtuvat widgetin si...
Sizing
Olion koon asettaminen asettelijan sisällä.
Asettelee widgetit riviin vaakasuunnassa.
void UpdateSizeHints(IList< GameObject > objects)
double Spacing
Olioiden väliin jäävä tyhjä tila.
void NotifyParentAboutChangedSizingAttributes()
Should be called whenever properties that might affect layouts are changed.
double BottomPadding
Alareunaan jäävä tyhjä tila.
HorizontalLayout()
Luo uuden asettelijan.
Pelialueella liikkuva olio. Käytä fysiikkapeleissä PhysicsObject-olioita.
void Update(IList< GameObject > objects, Vector maximumSize)
double RightPadding
Oikeaan reunaan jäävä tyhjä tila.
double TopPadding
Yläreunaan jäävä tyhjä tila.