deserialize method
Deserializes the FML template elements, attributes and children
Implementation
@override
void deserialize(XmlElement xml)
{
// deserialize
super.deserialize(xml);
// set constraints
width = Xml.get(node: xml, tag: 'width');
height = Xml.get(node: xml, tag: 'height');
minWidth = Xml.get(node: xml, tag: 'minwidth');
maxWidth = Xml.get(node: xml, tag: 'maxwidth');
minHeight = Xml.get(node: xml, tag: 'minheight');
maxHeight = Xml.get(node: xml, tag: 'maxheight');
// properties
visible = Xml.get(node: xml, tag: 'visible');
enabled = Xml.get(node: xml, tag: 'enabled');
halign = Xml.get(node: xml, tag: 'halign');
valign = Xml.get(node: xml, tag: 'valign');
flex = Xml.get(node: xml, tag: 'flex');
flexfit = Xml.get(node: xml, tag: 'flexfit');
onscreen = Xml.get(node: xml, tag: 'onscreen');
offscreen = Xml.get(node: xml, tag: 'offscreen');
// view sizing and position
// these are treated differently for efficiency reasons
// we only create the observable if its bound to in the template
// otherwise we just store the value in a simple double variable
String? key;
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewwidth'))) _viewWidthObservable = DoubleObservable(key, null, scope: scope);
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewheight'))) _viewHeightObservable = DoubleObservable(key, null, scope: scope);
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewx'))) _viewXObservable = DoubleObservable(key, null, scope: scope);
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewy'))) _viewYObservable = DoubleObservable(key, null, scope: scope);
// view requires a VisibilityDetector if either onstage or offstage is set or
// someone is bound to my visibility
_addVisibilityDetector = visible && (!S.isNullOrEmpty(onscreen) || !S.isNullOrEmpty(offscreen) || WidgetModel.isBound(this, Binding.toKey(id, 'visiblearea')) || WidgetModel.isBound(this, Binding.toKey(id, 'visibleheight')) || WidgetModel.isBound(this, Binding.toKey(id, 'visiblewidth')));
// set margins. Can be comma separated top,left,bottom,right
// space around the widget
var margins = Xml.attribute(node: xml, tag: 'margin') ?? Xml.attribute(node: xml, tag: 'margins');
this.margins = margins;
// set padding. Can be comma separated top,left,bottom,right
// space around the widget's children
var padding = Xml.attribute(node: xml, tag: 'pad') ?? Xml.attribute(node: xml, tag: 'padding') ?? Xml.attribute(node: xml, tag: 'padd');
this.padding = padding;
// tip
List<TooltipModel> tips = findChildrenOfExactType(TooltipModel).cast<TooltipModel>();
if (tips.isNotEmpty)
{
tipModel = tips.first;
removeChildrenOfExactType(TooltipModel);
}
// add animations
children?.forEach((child)
{
if (child is AnimationModel)
{
animations ??= [];
animations!.add(child);
}
});
// remove animations from child list
if (animations != null) children?.removeWhere((element) => animations!.contains(element));
}