Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 NPropDiffer(NElement source, NElement target)
 {
     _source = source;
     _target = target;
     _type   = source.GetXamlType();
     _head   = null;
     _tail   = null;
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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
                });
            }
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
 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);
 }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 public static NElement Child(this NElement self, NElement child)
 {
     return(self.Set(Properties.Child, child));
 }
Ejemplo n.º 14
0
 public static NElement SelectionChanged(this NElement self, Action <object> value)
 {
     return(self.Set(Properties.SelectionChanged, value));
 }
Ejemplo n.º 15
0
 public static NElement SelectionChanged(this NElement self, SelectionChangedEventHandler value)
 {
     return(self.Set(Properties.SelectionChanged, value));
 }
Ejemplo n.º 16
0
 public static NElement PointerPressed(this NElement self, PointerEventHandler value, bool includeHandled = false)
 {
     return(self.Set(Properties.PointerPressed, NEventAdapter.PackHandler(value, includeHandled)));
 }
Ejemplo n.º 17
0
 protected static bool IsElementPatching(NElement element) => element._isPatching;
Ejemplo n.º 18
0
 public static NElement TextOptions(this NElement self, TextHintingMode value)
 {
     return(self.Set(Properties.TextOptionsTextHintingMode, value));
 }
Ejemplo n.º 19
0
        public virtual NElement AssignProps(NElement source)
        {
            AssignProps(source, false);

            return(this);
        }
Ejemplo n.º 20
0
 public static NElement Children(this NElement self, params NElement[] children)
 {
     return(self.Set(Properties.Children, EnsureKeys(children)));
 }
Ejemplo n.º 21
0
 public static void SetRender(DependencyObject obj, NElement value)
 {
     obj.SetValue(RenderProperty, value);
 }
Ejemplo n.º 22
0
 public static NElement MouseLeftButtonUp(this NElement self, Action <object> value, bool includeHandled = false)
 {
     return(self.Set(Properties.MouseLeftButtonUp, NEventAdapter.PackHandler(value, includeHandled)));
 }
Ejemplo n.º 23
0
 public static NElement MouseLeftButtonDown(this NElement self, MouseEventHandler value, bool includeHandled = false)
 {
     return(self.Set(Properties.MouseLeftButtonDown, NEventAdapter.PackHandler(value, includeHandled)));
 }
Ejemplo n.º 24
0
 public static NElement Ref(this NElement self, Action <object> refCallback)
 {
     self._refCallback = refCallback;
     return(self);
 }
Ejemplo n.º 25
0
 public static NElement Key(this NElement self, object key)
 {
     self._key = key;
     return(self);
 }
Ejemplo n.º 26
0
 public static NElement Height(this NElement self, string value)
 {
     return(self.Set(Properties.Height, value));
 }
Ejemplo n.º 27
0
 public static NElement Ref <T>(this NElement self, Action <T> refCallback)
 {
     self._refCallback = i => refCallback((T)i);
     return(self);
 }
Ejemplo n.º 28
0
 public static NElement Width(this NElement self, string value)
 {
     return(self.Set(Properties.Width, value));
 }
Ejemplo n.º 29
0
 internal static bool ElementEquals(NElement a, NElement b)
 {
     return(a.GetXamlType() == b.GetXamlType() && Equals(a._key, b._key));
 }
Ejemplo n.º 30
0
 public static NElement Children(this NElement self, params object[] children)
 {
     return(self.Set(Properties.Children, EnsureKeys(Flatten(children).ToArray())));
 }