File size: 946 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// -----------------------------------------------------------
class HorizontalSpacerWithFixedAspect: ScriptedWidgetEventHandler
{
	protected Widget m_root;
	reference int border;
	reference int gap;
	reference float coef;
	float itemWidth;
	float itemHeight;
	
	// -----------------------------------------------------------
	void OnWidgetScriptInit(Widget w)
	{
		m_root = w;
		m_root.SetHandler(this);
	}
	
	// -----------------------------------------------------------
	override bool OnUpdate(Widget w)
	{
		if (w == m_root) UpdateLayout();
		return false;
	}
	
	protected void UpdateLayout()
	{
		Widget child = m_root.GetChildren();
		
			int index = 0;
			while (child)
			{
				if( index == 0 )
				{
					child.GetScreenSize(itemWidth, itemHeight);
				}
				else
				{
					child.SetFlags( WidgetFlags.EXACTPOS, false);
					child.SetPos(itemWidth+(itemWidth*coef), 0);
				}
				
				index++;
				child = child.GetSibling();
		}
	}
};