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 BooleanAttribute keepAspectRatio;
35 private EnumAttribute<Overflow> overflow;
36 private ExpressionAttribute onClick;
37
44 : base(Document, Parent)
45 {
46 }
47
52 {
53 get => this.width;
54 set => this.width = value;
55 }
56
61 {
62 get => this.height;
63 set => this.height = value;
64 }
65
70 {
71 get => this.maxWidth;
72 set => this.maxWidth = value;
73 }
74
79 {
80 get => this.maxHeight;
81 set => this.maxHeight = value;
82 }
83
88 {
89 get => this.minWidth;
90 set => this.minWidth = value;
91 }
92
97 {
98 get => this.minHeight;
99 set => this.minHeight = value;
100 }
101
106 {
107 get => this.keepAspectRatio;
108 set => this.keepAspectRatio = value;
109 }
110
115 {
116 get => this.overflow;
117 set => this.overflow = value;
118 }
119
124 {
125 get => this.onClick;
126 set => this.onClick = value;
127 }
128
133 public override Task FromXml(XmlElement Input)
134 {
135 this.width = new LengthAttribute(Input, "width", this.Document);
136 this.height = new LengthAttribute(Input, "height", this.Document);
137 this.maxWidth = new LengthAttribute(Input, "maxWidth", this.Document);
138 this.maxHeight = new LengthAttribute(Input, "maxHeight", this.Document);
139 this.minWidth = new LengthAttribute(Input, "minWidth", this.Document);
140 this.minHeight = new LengthAttribute(Input, "minHeight", this.Document);
141 this.keepAspectRatio = new BooleanAttribute(Input, "keepAspectRatio", this.Document);
142 this.overflow = new EnumAttribute<Overflow>(Input, "overflow", this.Document);
143 this.onClick = new ExpressionAttribute(Input, "onClick", this.Document);
144
145 return base.FromXml(Input);
146 }
147
152 public override void ExportAttributes(XmlWriter Output)
153 {
154 base.ExportAttributes(Output);
155
156 this.width?.Export(Output);
157 this.height?.Export(Output);
158 this.maxWidth?.Export(Output);
159 this.maxHeight?.Export(Output);
160 this.minWidth?.Export(Output);
161 this.minHeight?.Export(Output);
162 this.keepAspectRatio?.Export(Output);
163 this.overflow?.Export(Output);
164 this.onClick?.Export(Output);
165 }
166
171 public override void CopyContents(ILayoutElement Destination)
172 {
173 base.CopyContents(Destination);
174
175 if (Destination is LayoutArea Dest)
176 {
177 Dest.width = this.width?.CopyIfNotPreset(Destination.Document);
178 Dest.height = this.height?.CopyIfNotPreset(Destination.Document);
179 Dest.maxWidth = this.maxWidth?.CopyIfNotPreset(Destination.Document);
180 Dest.maxHeight = this.maxHeight?.CopyIfNotPreset(Destination.Document);
181 Dest.minWidth = this.minWidth?.CopyIfNotPreset(Destination.Document);
182 Dest.minHeight = this.minHeight?.CopyIfNotPreset(Destination.Document);
183 Dest.keepAspectRatio = this.keepAspectRatio?.CopyIfNotPreset(Destination.Document);
184 Dest.overflow = this.overflow?.CopyIfNotPreset(Destination.Document);
185 Dest.onClick = this.onClick?.CopyIfNotPreset(Destination.Document);
186 }
187 }
188
194 public override async Task DoMeasureDimensions(DrawingState State)
195 {
196 await base.DoMeasureDimensions(State);
197 float a;
198
199 EvaluationResult<Length> Length = await this.width.TryEvaluate(State.Session);
200 if (Length.Ok)
201 {
202 a = this.Width ?? 0;
203 State.CalcDrawingSize(Length.Result, ref a, true, this);
204 this.Width = this.ExplicitWidth = a;
205 }
206
207 Length = await this.height.TryEvaluate(State.Session);
208 if (Length.Ok)
209 {
210 a = this.Height ?? 0;
211 State.CalcDrawingSize(Length.Result, ref a, true, this);
212 this.Height = this.ExplicitHeight = a;
213 }
214
215 Length = await this.minWidth.TryEvaluate(State.Session);
216 if (Length.Ok)
217 {
218 a = this.MinWidth ?? 0;
219 State.CalcDrawingSize(Length.Result, ref a, true, this);
220 this.MinWidth = a;
221 }
222
223 Length = await this.maxWidth.TryEvaluate(State.Session);
224 if (Length.Ok)
225 {
226 a = this.MaxWidth ?? 0;
227 State.CalcDrawingSize(Length.Result, ref a, true, this);
228 this.MaxWidth = a;
229 }
230
231 Length = await this.minHeight.TryEvaluate(State.Session);
232 if (Length.Ok)
233 {
234 a = this.MinHeight ?? 0;
235 State.CalcDrawingSize(Length.Result, ref a, true, this);
236 this.MinHeight = a;
237 }
238
239 Length = await this.maxHeight.TryEvaluate(State.Session);
240 if (Length.Ok)
241 {
242 a = this.MaxHeight ?? 0;
243 State.CalcDrawingSize(Length.Result, ref a, true, this);
244 this.MaxHeight = a;
245 }
246 }
247
252 public override void ExportStateAttributes(XmlWriter Output)
253 {
254 base.ExportStateAttributes(Output);
255
256 this.width?.ExportState(Output);
257 this.height?.ExportState(Output);
258 this.maxWidth?.ExportState(Output);
259 this.maxHeight?.ExportState(Output);
260 this.minWidth?.ExportState(Output);
261 this.minHeight?.ExportState(Output);
262 this.keepAspectRatio?.ExportState(Output);
263 this.overflow?.ExportState(Output);
264 this.onClick?.ExportState(Output);
265 }
266
267 }
268}
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
BooleanAttribute CopyIfNotPreset(Layout2DDocument ForDocument)
Copies the attribute object if undefined, or defined by an expression. Returns a reference to itself,...
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:91
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:52
LayoutArea(Layout2DDocument Document, ILayoutElement Parent)
Abstract base class for layout elements with an implicit area.
Definition: LayoutArea.cs:43
override void ExportStateAttributes(XmlWriter Output)
Exports the local attributes of the current element.
Definition: LayoutArea.cs:252
LengthAttribute MinWidthAttribute
Minimum Width
Definition: LayoutArea.cs:88
override void ExportAttributes(XmlWriter Output)
Exports attributes to XML.
Definition: LayoutArea.cs:152
LengthAttribute HeightAttribute
Height
Definition: LayoutArea.cs:61
ExpressionAttribute OnClickAttribute
OnClick event script
Definition: LayoutArea.cs:124
BooleanAttribute KeepAspectRatioAttribute
Keep aspect-ratio
Definition: LayoutArea.cs:106
override void CopyContents(ILayoutElement Destination)
Copies contents (attributes and children) to the destination element.
Definition: LayoutArea.cs:171
override async Task DoMeasureDimensions(DrawingState State)
Measures layout entities and defines unassigned properties, related to dimensions.
Definition: LayoutArea.cs:194
LengthAttribute MaxWidthAttribute
Maximum Width
Definition: LayoutArea.cs:70
LengthAttribute MinHeightAttribute
Minimum Height
Definition: LayoutArea.cs:97
LengthAttribute MaxHeightAttribute
Maximum Height
Definition: LayoutArea.cs:79
EnumAttribute< Overflow > OverflowAttribute
Overflow
Definition: LayoutArea.cs:115
override Task FromXml(XmlElement Input)
Populates the element (including children) with information from its XML definition.
Definition: LayoutArea.cs:133
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