Esempio n. 1
0
        public override IEnumerable <FocusNode> sortDescendants(IEnumerable <FocusNode> descendants)
        {
            FocusTraversalPolicy     secondaryPolicy   = secondary ?? new ReadingOrderTraversalPolicy();
            IEnumerable <FocusNode>  sortedDescendants = secondaryPolicy.sortDescendants(descendants);
            List <FocusNode>         unordered         = new List <FocusNode>();
            List <_OrderedFocusInfo> ordered           = new List <_OrderedFocusInfo>();

            foreach (FocusNode node in sortedDescendants)
            {
                FocusOrder order = FocusTraversalOrder.of(node.context, nullOk: true);
                if (order != null)
                {
                    ordered.Add(new _OrderedFocusInfo(node: node, order: order));
                }
                else
                {
                    unordered.Add(node);
                }
            }
            FocusTravesalUtils.mergeSort <_OrderedFocusInfo>(ordered, compare: (_OrderedFocusInfo a, _OrderedFocusInfo b) => {
                D.assert(
                    a.order.GetType() == b.order.GetType(), () =>
                    $"When sorting nodes for determining focus order, the order ({a.order}) of " +
                    $"node {a.node}, isn't the same type as the order ({b.order}) of {b.node}. " +
                    "Incompatible order types can't be compared.  Use a FocusTraversalGroup to group " +
                    "similar orders together."
                    );
                return(a.order.CompareTo(b.order));
            });
            return(LinqUtils <FocusNode, _OrderedFocusInfo> .SelectList(ordered, ((_OrderedFocusInfo info) => info.node)).Concat(unordered));
        }
Esempio n. 2
0
        public static FocusOrder of(BuildContext context, bool nullOk = false)
        {
            D.assert(context != null);
            FocusTraversalOrder marker = context.getElementForInheritedWidgetOfExactType <FocusTraversalOrder>()?.widget as FocusTraversalOrder;
            FocusOrder          order  = marker?.order;

            if (order == null && !nullOk)
            {
                throw new UIWidgetsError("FocusTraversalOrder.of() was called with a context that " +
                                         "does not contain a TraversalOrder widget. No TraversalOrder widget " +
                                         "ancestor could be found starting from the context that was passed to " +
                                         "FocusTraversalOrder.of().\n" +
                                         "The context used was:\n" +
                                         $"  {context}");
            }
            return(order);
        }