DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
SizeToChild.c
Go to the documentation of this file.
1class SizeToChild extends ScriptedWidgetEventHandler
2{
3 reference string m_ChildName;
4 reference float m_HorizontalOffset;
5 reference float m_VerticalOffset;
6 reference bool m_ResizeHorizontal;
7 reference bool m_ResizeVertical;
8
9 protected Widget m_Root;
10 protected Widget m_Child;
11
12 protected static bool m_IgnoredBool;
13
15 {
16 m_Root = w;
17
18 m_Child = m_Root.FindAnyWidget( m_ChildName );
19 if ( m_Child )
20 {
22 }
23 }
24
26 {
27 return ResizeParentToChild( m_IgnoredBool, -1, false );
28 }
29
30 bool ResizeParentToChild( out bool changed_size, int limit = -1, bool immedUpdate = true )
31 {
32 float x, y, o_x, o_y, new_x, new_y;
33 if ( m_Child )
34 {
35 m_Child.Update();
36 m_Child.GetScreenSize( x, y );
37 m_Root.GetScreenSize( new_x, new_y );
38 m_Root.GetSize( o_x, o_y );
39
40 bool changed = false;
41 bool hit_limit = false;
42
43 if ( m_ResizeHorizontal && x != new_x )
44 {
45 new_x = x + m_HorizontalOffset;
46 changed = true;
47 }
48 else
49 new_x = o_x;
50
51 if ( m_ResizeVertical && y != new_y )
52 {
53 new_y = y + m_VerticalOffset;
54 changed = true;
55 }
56 else
57 new_y = o_y;
58
59 if ( limit > 0 && new_y > limit )
60 {
61 new_y = limit;
62 hit_limit = true;
63 }
64
65 if ( changed )
66 {
67 m_Root.SetSize( new_x, new_y, immedUpdate );
68 }
69
70 changed_size = changed;
71 return hit_limit;
72 }
73 else
74 {
75 m_Child = m_Root.FindAnyWidget( m_ChildName );
76 if ( !m_Child )
77 {
78 Print( "Error in size to child, " + m_Root.GetName() + " has no child named " + m_ChildName );
79 }
80 }
81
82 return false;
83 }
84}
85
86class SizeToParent extends ScriptedWidgetEventHandler
87{
88 reference bool m_ResizeHorizontal;
89 reference bool m_ResizeVertical;
90
91 protected Widget m_Root;
92 protected Widget m_Parent;
93
95 {
96 m_Root = w;
97
99 m_Root.ClearFlags( WidgetFlags.HEXACTSIZE );
100 if ( m_ResizeVertical )
101 m_Root.ClearFlags( WidgetFlags.VEXACTSIZE );
102
103 m_Parent = m_Root.GetParent();
104
105 Refresh();
106 }
107
108 void Refresh()
109 {
110 float x, y, o_x, o_y, new_x, new_y;
111 m_Parent.Update();
112 m_Parent.GetScreenSize( x, y );
113 m_Root.GetScreenSize( new_x, new_y );
114 m_Root.GetSize( o_x, o_y );
115
116 bool changed = false;
117
118 if ( m_ResizeHorizontal && x != new_x )
119 {
120 new_x = x;
121 changed = true;
122 }
123 else
124 new_x = o_x;
125
126 if ( m_ResizeVertical && y != new_y )
127 {
128 new_y = y;
129 changed = true;
130 }
131 else
132 new_y = o_y;
133
134 if ( changed )
135 m_Root.SetSize( new_x, new_y );
136 }
137}
Icon x
Icon y
protected Widget m_Parent
Definition SizeToChild.c:92
class SizeToChild extends ScriptedWidgetEventHandler m_ResizeHorizontal
protected Widget m_Root
Definition SizeToChild.c:91
reference bool m_ResizeVertical
Definition SizeToChild.c:89
map: item x vector(index, width, height)
Definition EnWidgets.c:538
protected Widget m_Child
Definition SizeToChild.c:10
reference float m_VerticalOffset
Definition SizeToChild.c:5
reference float m_HorizontalOffset
Definition SizeToChild.c:4
static protected bool m_IgnoredBool
Definition SizeToChild.c:12
reference string m_ChildName
Definition SizeToChild.c:3
protected LayoutHolder m_Parent
Definition LayoutHolder.c:6
bool ResizeParentToChild(out bool changed_size, int limit=-1, bool immedUpdate=true)
Definition SizeToChild.c:30
protected Widget m_Root
Definition SizeToChild.c:9
void OnWidgetScriptInit(Widget w)
Definition SizeToChild.c:14
reference bool m_ResizeVertical
Definition SizeToChild.c:7
reference bool m_ResizeHorizontal
Definition SizeToChild.c:6
proto void Print(void var)
Prints content of variable to console/log.
WidgetFlags
Definition EnWidgets.c:57