Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LayoutArea.cs
1using System.Threading.Tasks;
2using System.Xml;
4
6{
10 public enum Overflow
11 {
15 Clip,
16
20 Ignore
21 }
22
26 public abstract class LayoutArea : LayoutElement
27 {
28 private LengthAttribute width;
29 private LengthAttribute height;
30 private LengthAttribute maxWidth;
31 private LengthAttribute maxHeight;
32 private LengthAttribute minWidth;
33 private LengthAttribute minHeight;
34 private EnumAttribute<Overflow> overflow;
35 private ExpressionAttribute onClick;
36
43 : base(Document, Parent)
44 {
45 }
46
51 {
52 get => this.width;
53 set => this.width = value;
54 }
55
60 {
61 get => this.height;
62 set => this.height = value;
63 }
64
69 {
70 get => this.maxWidth;
71 set => this.maxWidth = value;
72 }
73
78 {
79 get => this.maxHeight;
80 set => this.maxHeight = value;
81 }
82
87 {
88 get => this.minWidth;
89 set => this.minWidth = value;
90 }
91
96 {
97 get => this.minHeight;
98 set => this.minHeight = value;
99 }
100
105 {
106 get => this.overflow;
107 set => this.overflow = value;
108 }
109
114 {
115 get => this.onClick;
116 set => this.onClick = value;
117 }
118
123 public override Task FromXml(XmlElement Input)
124 {
125 this.width = new LengthAttribute(Input, "width", this.Document);
126 this.height = new LengthAttribute(Input, "height", this.Document);
127 this.maxWidth = new LengthAttribute(Input, "maxWidth", this.Document);
128 this.maxHeight = new LengthAttribute(Input, "maxHeight", this.Document);
129 this.minWidth = new LengthAttribute(Input, "minWidth", this.Document);
130 this.minHeight = new LengthAttribute(Input, "minHeight", this.Document);
131 this.overflow = new EnumAttribute<Overflow>(Input, "overflow", this.Document);
132 this.onClick = new ExpressionAttribute(Input, "onClick", this.Document);
133
134 return base.FromXml(Input);
135 }
136
141 public override void ExportAttributes(XmlWriter Output)
142 {
143 base.ExportAttributes(Output);
144
145 this.width?.Export(Output);
146 this.height?.Export(Output);
147 this.maxWidth?.Export(Output);
148 this.maxHeight?.Export(Output);
149 this.minWidth?.Export(Output);
150 this.minHeight?.Export(Output);
151 this.overflow?.Export(Output);
152 this.onClick?.Export(Output);
153 }
154
159 public override void CopyContents(ILayoutElement Destination)
160 {
161 base.CopyContents(Destination);
162
163 if (Destination is LayoutArea Dest)
164 {
165 Dest.width = this.width?.CopyIfNotPreset(Destination.Document);
166 Dest.height = this.height?.CopyIfNotPreset(Destination.Document);
167 Dest.maxWidth = this.maxWidth?.CopyIfNotPreset(Destination.Document);
168 Dest.maxHeight = this.maxHeight?.CopyIfNotPreset(Destination.Document);
169 Dest.minWidth = this.minWidth?.CopyIfNotPreset(Destination.Document);
170 Dest.minHeight = this.minHeight?.CopyIfNotPreset(Destination.Document);
171 Dest.overflow = this.overflow?.CopyIfNotPreset(Destination.Document);
172 Dest.onClick = this.onClick?.CopyIfNotPreset(Destination.Document);
173 }
174 }
175
181 public override async Task DoMeasureDimensions(DrawingState State)
182 {
183 await base.DoMeasureDimensions(State);
184 float a;
185
186 EvaluationResult<Length> Length = await this.width.TryEvaluate(State.Session);
187 if (Length.Ok)
188 {
189 a = this.Width ?? 0;
190 State.CalcDrawingSize(Length.Result, ref a, true, this);
191 this.Width = this.ExplicitWidth = a;
192 }
193
194 Length = await this.height.TryEvaluate(State.Session);
195 if (Length.Ok)
196 {
197 a = this.Height ?? 0;
198 State.CalcDrawingSize(Length.Result, ref a, true, this);
199 this.Height = this.ExplicitHeight = a;
200 }
201
202 Length = await this.minWidth.TryEvaluate(State.Session);
203 if (Length.Ok)
204 {
205 a = this.MinWidth ?? 0;
206 State.CalcDrawingSize(Length.Result, ref a, true, this);
207 this.MinWidth = a;
208 }
209
210 Length = await this.maxWidth.TryEvaluate(State.Session);
211 if (Length.Ok)
212 {
213 a = this.MaxWidth ?? 0;
214 State.CalcDrawingSize(Length.Result, ref a, true, this);
215 this.MaxWidth = a;
216 }
217
218 Length = await this.minHeight.TryEvaluate(State.Session);
219 if (Length.Ok)
220 {
221 a = this.MinHeight ?? 0;
222 State.CalcDrawingSize(Length.Result, ref a, true, this);
223 this.MinHeight = a;
224 }
225
226 Length = await this.maxHeight.TryEvaluate(State.Session);
227 if (Length.Ok)
228 {
229 a = this.MaxHeight ?? 0;
230 State.CalcDrawingSize(Length.Result, ref a, true, this);
231 this.MaxHeight = a;
232 }
233 }
234
239 public override void ExportStateAttributes(XmlWriter Output)
240 {
241 base.ExportStateAttributes(Output);
242
243 this.width?.ExportState(Output);
244 this.height?.ExportState(Output);
245 this.maxWidth?.ExportState(Output);
246 this.maxHeight?.ExportState(Output);
247 this.minWidth?.ExportState(Output);
248 this.minHeight?.ExportState(Output);
249 this.overflow?.ExportState(Output);
250 this.onClick?.ExportState(Output);
251 }
252
253 }
254}
Contains a 2D layout document.
void Export(XmlWriter Output)
Exports the attribute.
Definition: Attribute.cs:187
void ExportState(XmlWriter Output)
Exports the state of the attribute.
Definition: Attribute.cs:199
static async Task< EvaluationResult< T > > TryEvaluate(Attribute< T > Attribute, Variables Session)
Tries to evaluate the attribute value.
Definition: Attribute.cs:256
EnumAttribute< TEnum > CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
ExpressionAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
LengthAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
Variables Session
Current session.
Definition: DrawingState.cs:89
void CalcDrawingSize(Length L, ref float Size, bool Horizontal, ILayoutElement Element)
Converts a defined length to drawing size.
Abstract base class for layout elements with an implicit area.
Definition: LayoutArea.cs:27
LengthAttribute WidthAttribute
Width
Definition: LayoutArea.cs:51
LayoutArea(Layout2DDocument Document, ILayoutElement Parent)
Abstract base class for layout elements with an implicit area.
Definition: LayoutArea.cs:42
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: LayoutArea.cs:239
LengthAttribute MinWidthAttribute
Minimum Width
Definition: LayoutArea.cs:87
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: LayoutArea.cs:141
LengthAttribute HeightAttribute
Height
Definition: LayoutArea.cs:60
ExpressionAttribute OnClickAttribute
OnClick event script
Definition: LayoutArea.cs:114
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: LayoutArea.cs:159
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: LayoutArea.cs:181
LengthAttribute MaxWidthAttribute
Maximum Width
Definition: LayoutArea.cs:69
LengthAttribute MinHeightAttribute
Minimum Height
Definition: LayoutArea.cs:96
LengthAttribute MaxHeightAttribute
Maximum Height
Definition: LayoutArea.cs:78
EnumAttribute< Overflow > OverflowAttribute
Overflow
Definition: LayoutArea.cs:105
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: LayoutArea.cs:123
Abstract base class for layout elements.
Layout2DDocument Document
Layout document.
Base interface for all layout elements.
Layout2DDocument Document
Layout document.
Overflow
Overflow handling.
Definition: LayoutArea.cs:11