Пример #1
0
        public RootVisual(CoreServices coreServices)
        {
            _coreServices = coreServices ?? throw new System.ArgumentNullException(nameof(coreServices));
            //Uno specific - flag as VisualTreeRoot for interop with existing logic
            IsVisualTreeRoot = true;

            PointerPressed  += RootVisual_PointerPressed;
            PointerReleased += RootVisual_PointerReleased;
            PointerCanceled += RootVisual_PointerCanceled;
        }
Пример #2
0
        public RootVisual(CoreServices coreServices)
        {
            _coreServices = coreServices ?? throw new System.ArgumentNullException(nameof(coreServices));
            //Uno specific - flag as VisualTreeRoot for interop with existing logic
            IsVisualTreeRoot = true;
#if __WASM__
            //Uno WASM specific - set tabindex to 0 so the RootVisual is "native focusable"
            SetAttribute("tabindex", "0");
#endif

#if HAS_UNO
            AddHandler(
                PointerReleasedEvent,
                new PointerEventHandler((snd, args) => ProcessPointerUp(args)),
                handledEventsToo: true);
#endif
        }
Пример #3
0
 public ContentRoot(ContentRootType type, Color backgroundColor, UIElement?rootElement, CoreServices coreServices)
 {
     //TODO Uno: Does not match WinUI exactly, additional logic can be ported later.
     _coreServices = coreServices ?? throw new ArgumentNullException(nameof(coreServices));
     VisualTree    = new VisualTree(coreServices, backgroundColor, rootElement, this);
     FocusManager  = new FocusManager(this);
     InputManager  = new InputManager(this);
     //TODO Uno: We may want to create a custom version of adapter and observer specific to Uno.
     FocusAdapter = new FocusAdapter(this);
     FocusManager.SetFocusObserver(new FocusObserver(this));
     switch (type)
     {
     case ContentRootType.CoreWindow:
         MUX_ASSERT(coreServices.ContentRootCoordinator.CoreWindowContentRoot == null);
         coreServices.ContentRootCoordinator.CoreWindowContentRoot = this;
         break;
     }
 }
Пример #4
0
        public VisualTree(CoreServices coreServices, Color backgroundColor, UIElement?rootElement, ContentRoot contentRoot)
        {
            //TODO Uno: Adjust to match WinUI
            _coreServices = coreServices ?? throw new ArgumentNullException(nameof(coreServices));
            ContentRoot   = contentRoot ?? throw new ArgumentNullException(nameof(contentRoot));

            if (rootElement != null)
            {
                RootElement = rootElement;
            }
            else
            {
                RootVisual = new RootVisual(coreServices);
                RootVisual.AssociatedVisualTree = this;
                RootVisual.SetBackgroundColor(backgroundColor);
                RootElement = RootVisual;

                _focusInputHandler = new UnoFocusInputHandler(RootVisual);
            }
        }
Пример #5
0
    private void GetNodeByValue(
        object value,
        DependencyObject parent,
        Uno.UI.Xaml.Core.CoreServices core,
        out RPNode ppNode)
    {
        // Here we will have either a valueString which corresponds to the name
        // of the element we are looking for, or a valueObject of type UIElement
        // which is a direct reference to said element.
        if (value is string)
        {
            string name = null;
            if (value is string valueString)
            {
                name = valueString;
            }

            if (!string.IsNullOrEmpty(name))
            {
                foreach (RPNode node in m_nodes)
                {
                    if (name.Equals(node.GetName()))
                    {
                        ppNode = node;
                        return;
                    }
                }

                // If there is no match within the children, the target might
                // actually be a deferred element. If that's the case, we will
                // create a node for this deferred element and inject it into
                // the graph.
                // TODO Uno: We don't support a concept of deferred elements yet.
                //var deferredElement = core.GetDeferredElementIfExists(name, namescopeOwner, nameScopeType);

                //if (deferredElement && deferredElement.GetParent() == parent)
                //{
                //	*ppNode = &(*m_nodes.emplace_after(it, deferredElement));
                //	return S_OK;
                //}

                // If there is truly no matching node in the end, then we must
                // throw an InvalidOperationException. We will fail fast here
                // and let the CRelativePanel handle the rest.
                throw new InvalidOperationException("No matching node found");
            }
        }
        else
        {
            UIElement valueAsUIElement = null;
            if (value is UIElement)
            {
                valueAsUIElement = value as UIElement;
            }
            else if (value is ElementNameSubject elementNameSubject)             // TODO Uno specific: We get ElementNameSubject instead of string here
            {
                valueAsUIElement = elementNameSubject.ElementInstance as UIElement;
            }

            if (valueAsUIElement != null)
            {
                foreach (RPNode node in m_nodes)
                {
                    if (node.GetElement() == valueAsUIElement)
                    {
                        ppNode = node;
                        return;
                    }
                }

                // If there is no match, we must throw an InvalidOperationException.
                // We will fail fast here and let the CRelativePanel handle the rest.
                throw new InvalidOperationException("Node reference not found");
            }
        }

        ppNode = null;
        return;
    }
Пример #6
0
    internal void ResolveConstraints(
        DependencyObject parent,
        Uno.UI.Xaml.Core.CoreServices core)
    {
        foreach (var node in m_nodes)
        {
            object value;

            node.GetLeftOfValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var leftOfNode);
                node.SetLeftOfConstraint(leftOfNode);
            }

            node.GetAboveValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var aboveNode);
                node.SetAboveConstraint(aboveNode);
            }

            node.GetRightOfValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var rightOfNode);
                node.SetRightOfConstraint(rightOfNode);
            }

            node.GetBelowValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var belowNode);
                node.SetBelowConstraint(belowNode);
            }

            node.GetAlignHorizontalCenterWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignHorizontalCenterWithNode);
                node.SetAlignHorizontalCenterWithConstraint(alignHorizontalCenterWithNode);
            }

            node.GetAlignVerticalCenterWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignVerticalCenterWithNode);
                node.SetAlignVerticalCenterWithConstraint(alignVerticalCenterWithNode);
            }

            node.GetAlignLeftWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignLeftWithNode);
                node.SetAlignLeftWithConstraint(alignLeftWithNode);
            }

            node.GetAlignTopWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignTopWithNode);
                node.SetAlignTopWithConstraint(alignTopWithNode);
            }

            node.GetAlignRightWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignRightWithNode);
                node.SetAlignRightWithConstraint(alignRightWithNode);
            }

            node.GetAlignBottomWithValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                GetNodeByValue(value, parent, core, out var alignBottomWithNode);
                node.SetAlignBottomWithConstraint(alignBottomWithNode);
            }

            node.GetAlignLeftWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignLeftWithPanelConstraint((bool)value);
            }

            node.GetAlignTopWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignTopWithPanelConstraint((bool)value);
            }

            node.GetAlignRightWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignRightWithPanelConstraint((bool)value);
            }

            node.GetAlignBottomWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignBottomWithPanelConstraint((bool)value);
            }

            node.GetAlignHorizontalCenterWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignHorizontalCenterWithPanelConstraint((bool)value);
            }

            node.GetAlignVerticalCenterWithPanelValue(out value);
            if (value != null && value != DependencyProperty.UnsetValue)
            {
                node.SetAlignVerticalCenterWithPanelConstraint((bool)value);
            }
        }
    }
Пример #7
0
 public ContentRootCoordinator(CoreServices coreServices)
 {
     _coreServices = coreServices ?? throw new ArgumentNullException(nameof(coreServices));
 }