Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
spacerbase.c
Go to the documentation of this file.
1 // -----------------------------------------------------------
3 {
4  protected Widget m_root;
5  protected int m_count;
6 
7  // -----------------------------------------------------------
8  void OnWidgetScriptInit(Widget w)
9  {
10  m_root = w;
11  m_count = 0;
12 
13  Widget child = m_root.GetChildren();
14  while (child)
15  {
16  m_count++;
17  child.SetFlags(WidgetFlags.EXACTPOS | WidgetFlags.EXACTSIZE, false);
18  child = child.GetSibling();
19  }
20 
21  m_root.SetHandler(this);
22  }
23 
24  // -----------------------------------------------------------
25  override bool OnUpdate(Widget w)
26  {
27  if (w == m_root) UpdateLayout();
28  return false;
29  }
30 
31  // -----------------------------------------------------------
32  override bool OnChildAdd( Widget w, Widget child)
33  {
34  m_count++;
35  child.SetFlags(WidgetFlags.EXACTPOS | WidgetFlags.EXACTSIZE, false);
36  return false;
37  }
38 
39  // -----------------------------------------------------------
40  override bool OnChildRemove( Widget w, Widget child)
41  {
42  m_count--;
43  return false;
44  }
45 
46  // -----------------------------------------------------------
47  protected int GetChildIndex(Widget w)
48  {
49  Widget child = m_root.GetChildren();
50 
51  int index = 0;
52  while (child)
53  {
54  if (child == w) return index;
55 
56  index++;
57  child = child.GetSibling();
58  }
59 
60  return INDEX_NOT_FOUND;
61  }
62 
63  // -----------------------------------------------------------
64  void UpdateLayout()
65  {
66  if (m_count == 0) return;
67 
68  float width;
69  float height;
70  m_root.GetScreenSize(width, height);
71 
72  Widget child = m_root.GetChildren();
73 
74  int index = 0;
75  while (child)
76  {
77  UpdateChild(child, width, height, index);
78  index++;
79  child = child.GetSibling();
80  }
81  }
82  protected void UpdateChild(Widget child, float w, float h, int index) {}
83 };
INDEX_NOT_FOUND
const int INDEX_NOT_FOUND
Definition: gameplay.c:13
SpacerBase
Definition: spacerbase.c:2
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Widget
Definition: enwidgets.c:189
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650