Пример #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);
        }
Пример #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);
        }
Пример #3
0
 NPropDiffer(NElement source, NElement target)
 {
     _source = source;
     _target = target;
     _type   = source.GetXamlType();
     _head   = null;
     _tail   = null;
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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
                });
            }
        }
Пример #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);
            }
        }
Пример #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);
 }
Пример #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);
        }
Пример #13
0
 public static NElement Child(this NElement self, NElement child)
 {
     return(self.Set(Properties.Child, child));
 }
Пример #14
0
 public static NElement SelectionChanged(this NElement self, Action <object> value)
 {
     return(self.Set(Properties.SelectionChanged, value));
 }
Пример #15
0
 public static NElement SelectionChanged(this NElement self, SelectionChangedEventHandler value)
 {
     return(self.Set(Properties.SelectionChanged, value));
 }
Пример #16
0
 public static NElement PointerPressed(this NElement self, PointerEventHandler value, bool includeHandled = false)
 {
     return(self.Set(Properties.PointerPressed, NEventAdapter.PackHandler(value, includeHandled)));
 }
Пример #17
0
 protected static bool IsElementPatching(NElement element) => element._isPatching;
Пример #18
0
 public static NElement TextOptions(this NElement self, TextHintingMode value)
 {
     return(self.Set(Properties.TextOptionsTextHintingMode, value));
 }
Пример #19
0
        public virtual NElement AssignProps(NElement source)
        {
            AssignProps(source, false);

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