CrabUI
Loading...
Searching...
No Matches
CUILayout.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5using System.Diagnostics;
6
7using Barotrauma;
8using Microsoft.Xna.Framework;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Graphics;
11
12namespace CrabUI
13{
14 /// <summary>
15 /// Base class for all layouts
16 /// </summary>
17 public abstract class CUILayout
18 {
19 public CUIComponent Host;
20
21
22 //NOTE: This looks ugly, but no matter how i try to isolate this logic it gets only uglier
23 // i've been stuck here for too long so i'll just do this
24 // and each update pattern in fact used only once, so i think no big deal
25
26 /// <summary>
27 /// This is just for debug, don't use it
28 /// </summary>
29 public void ForceMarkUnchanged()
30 {
31 decorChanged = false;
32 changed = false;
33 absoluteChanged = false;
34
35 foreach (CUIComponent child in Host.Children)
36 {
37 child.Layout.ForceMarkUnchanged();
38 }
39 }
40
41 private void propagateChangedDown()
42 {
43 changed = true;
44 DecorChanged = true;
45 foreach (CUIComponent child in Host.Children)
46 {
47 child.Layout.propagateChangedDown();
48 }
49 }
50 protected bool changed = true; public bool Changed
51 {
52 get => changed;
53 set
54 {
55 changed = value;
56 if (value)
57 {
58 if (Host.Parent != null) Host.Parent.Layout.propagateChangedDown();
59 else propagateChangedDown();
60 }
61 }
62 }
63
64 private void propagateDecorChangedDown()
65 {
66 DecorChanged = true;
67 foreach (CUIComponent child in Host.Children)
68 {
69 child.Layout.propagateDecorChangedDown();
70 }
71 }
72
73 /// <summary>
74 /// It doesn't optimize anything
75 /// </summary>
77 {
78 set
79 {
80 if (value)
81 {
82 changed = true;
83 DecorChanged = true;
84 if (Host.Parent != null)
85 {
86 Host.Parent.Layout.changed = true;
87 Host.Parent.Layout.propagateDecorChangedDown();
88 }
89 }
90 }
91 }
92
93 public bool ChildChanged
94 {
95 set
96 {
97 if (value) propagateChangedDown();
98 }
99 }
100
101 private void propagateAbsoluteChangedUp()
102 {
103 absoluteChanged = true;
104 Host.Parent?.Layout.propagateAbsoluteChangedUp();
105 }
106 protected bool absoluteChanged = true; public bool AbsoluteChanged
107 {
108 get => absoluteChanged;
109 set
110 {
111 if (!value) absoluteChanged = false;
112 if (value && Host.Parent != null) Host.Parent.Layout.absoluteChanged = true;
113 //if (value && Host.Parent != null) Host.Parent.Layout.propagateAbsoluteChangedUp();
114 }
115 }
116 protected bool decorChanged = true; public bool DecorChanged
117 {
118 get => decorChanged;
119 set
120 {
121 decorChanged = value;
122 }
123 }
124
125 internal virtual void Update()
126 {
127 if (Changed)
128 {
129 if (Host.CullChildren)
130 {
131 foreach (CUIComponent c in Host.Children)
132 {
133 c.CulledOut = !c.UnCullable && !c.Real.Intersect(Host.Real);
134 }
135 }
136
137 Changed = false;
138 }
139 }
140
141 internal virtual void UpdateDecor()
142 {
143 if (DecorChanged)
144 {
145 Host.UpdatePseudoChildren();
146 DecorChanged = false;
147 }
148 }
149
150 internal virtual void ResizeToContent()
151 {
152 if (AbsoluteChanged && (Host.FitContent.X || Host.FitContent.Y))
153 {
154 // do something
155 }
156
157 AbsoluteChanged = false;
158 }
159
160 public CUILayout() { }
161 public CUILayout(CUIComponent host)
162 {
163 Host = host;
164 }
165
166 public override string ToString() => this.GetType().Name;
167 public static CUILayout Parse(string raw)
168 {
169 if (raw != null)
170 {
171 raw = raw.Trim();
172 if (CUIReflection.CUILayoutTypes.ContainsKey(raw))
173 {
174 return (CUILayout)Activator.CreateInstance(CUIReflection.CUILayoutTypes[raw]);
175 }
176 }
177 return new CUILayoutSimple();
178 }
179 }
180}
Base class for all components.
CUIBool2 FitContent
Will resize itself to fit components with absolute size, e.g. text.
CUIRect Real
Calculated prop, position on real screen in pixels Should be fully calculated after CUIMainComponent....
bool CullChildren
if child rect doesn't intersect with parent it won't be drawn and won't consume fps It also sets Hi...
Base class for all layouts.
Definition CUILayout.cs:18
void ForceMarkUnchanged()
This is just for debug, don't use it.
Definition CUILayout.cs:29
bool SelfAndParentChanged
It doesn't optimize anything.
Definition CUILayout.cs:77