public static NPatch Diff(NElement oldE, ref NElement newE) { var oldSet = oldE != null; var newSet = newE != null; if (oldSet == newSet) { if (!oldSet) { return(null); } if (NPatch.ElementEquals(oldE, newE)) { var oldC = oldE as NClass; if (oldC != null) { var newC = (NClass)newE; newE = oldE; return(oldC.Upgrade(newC)); } return(new NPropDiffer(oldE, newE).Diff()); } } return(NPatch.AssignNewValue); }
internal NPatch Diff() { var update = _force || ShouldComponentUpdate(_props, _state, _propsCommitted, _stateCommitted); Commit(); if (!update) { return(null); } var oldUI = _ui; var newUI = RenderUI(); var patch = NPropDiffer.Diff(oldUI, ref newUI); //if (oldUI is NClass) // oldUI represented by nested class which is assigned after NPropDiffer anyway // return patch; _ui = newUI; if (patch == NPatch.AssignNewValue) // Assign New UI { patch = new NActionPatch(i => { var result = Xaml = newUI.Create(); oldUI?.Free(); return(result); }); } return(patch); }
NPropDiffer(NElement source, NElement target) { _source = source; _target = target; _type = source.GetXamlType(); _head = null; _tail = null; }
public virtual NElement AssignPropsExcluding(NElement source, params NProperty[] exclude) { for (var i = source._props.Head; i != null; i = i.Next) { if (Array.IndexOf(exclude, i.Key) < 0) { SetProp(i.Key, i._value, false); } } return(this); }
public static NElement Render(this ContentControl control, NElement content) { var cls = content as NClass; if (cls != null) { cls.XamlChanged = (c, p) => control.Content = p; } control.Content = content.Create(); return(content); }
public static NElement Render(this Border control, NElement content) { control.Child = (UIElement)content.Create(); var cls = content as NClass; if (cls != null) { cls.XamlChanged = (c, p) => control.Child = (UIElement)p; } return(content); }
public static NElement Render(this Window control, NElement content) { control.Content = (FrameworkElement)content.Create(); var cls = content as NClass; if (cls != null) { cls.XamlChanged = (c, p) => control.Content = (FrameworkElement)p; } return(content); }
public static NElement Render(this Activity control, NElement content) { content.Context = control; var cls = content as NClass; if (cls != null) { cls.XamlChanged = (c, p) => control.SetContentView(p as View); } control.SetContentView(content.Create() as View); return(content); }
void Update(int idx, NElement newE, NElement oldE) { if (oldE is NClass) { _target[idx] = oldE; // transfer updated classes } var p = NPropDiffer.Diff(oldE, ref newE); if (p != null) { Add(new NListPatchEntry { Op = NListPatchOp.Patch, Value = oldE, iFinal = idx, Patch = p }); } }
internal void AssignProps(NElement source, bool silent) { for (var i = _props.Head; i != null; i = i.Next) { if (!source._props.HasKey(i.Key)) { UnsetProp(i.Key, silent); } } for (var i = source._props.Head; i != null; i = i.Next) { SetProp(i.Key, i._value, silent); } }
public static NElement Render(this Application app, NElement content) { if (content is NClass) { var border = new Border { HorizontalAlignment = sw.HorizontalAlignment.Stretch, VerticalAlignment = sw.VerticalAlignment.Stretch }; content = border.Render(content); app.RootVisual = border; } else { app.RootVisual = (UIElement)content.Create(); } return(content); }
NElement AssignAttachedProps(NElement result) { if (result == null) #if XAML { result = new NXaml <StackPanel>(); } #else { throw new ArgumentNullException(nameof(result)); } #endif for (var i = _props.Head; i != null; i = i.Next) { if (Ambients.Contains(i.Key)) { result.Set(i.Key, i._value); } } return(result); }
public static NElement Child(this NElement self, NElement child) { return(self.Set(Properties.Child, child)); }
public static NElement SelectionChanged(this NElement self, Action <object> value) { return(self.Set(Properties.SelectionChanged, value)); }
public static NElement SelectionChanged(this NElement self, SelectionChangedEventHandler value) { return(self.Set(Properties.SelectionChanged, value)); }
public static NElement PointerPressed(this NElement self, PointerEventHandler value, bool includeHandled = false) { return(self.Set(Properties.PointerPressed, NEventAdapter.PackHandler(value, includeHandled))); }
protected static bool IsElementPatching(NElement element) => element._isPatching;
public static NElement TextOptions(this NElement self, TextHintingMode value) { return(self.Set(Properties.TextOptionsTextHintingMode, value)); }
public virtual NElement AssignProps(NElement source) { AssignProps(source, false); return(this); }
public static NElement Children(this NElement self, params NElement[] children) { return(self.Set(Properties.Children, EnsureKeys(children))); }
public static void SetRender(DependencyObject obj, NElement value) { obj.SetValue(RenderProperty, value); }
public static NElement MouseLeftButtonUp(this NElement self, Action <object> value, bool includeHandled = false) { return(self.Set(Properties.MouseLeftButtonUp, NEventAdapter.PackHandler(value, includeHandled))); }
public static NElement MouseLeftButtonDown(this NElement self, MouseEventHandler value, bool includeHandled = false) { return(self.Set(Properties.MouseLeftButtonDown, NEventAdapter.PackHandler(value, includeHandled))); }
public static NElement Ref(this NElement self, Action <object> refCallback) { self._refCallback = refCallback; return(self); }
public static NElement Key(this NElement self, object key) { self._key = key; return(self); }
public static NElement Height(this NElement self, string value) { return(self.Set(Properties.Height, value)); }
public static NElement Ref <T>(this NElement self, Action <T> refCallback) { self._refCallback = i => refCallback((T)i); return(self); }
public static NElement Width(this NElement self, string value) { return(self.Set(Properties.Width, value)); }
internal static bool ElementEquals(NElement a, NElement b) { return(a.GetXamlType() == b.GetXamlType() && Equals(a._key, b._key)); }
public static NElement Children(this NElement self, params object[] children) { return(self.Set(Properties.Children, EnsureKeys(Flatten(children).ToArray()))); }