public FocusNode _sortAndFindInitial(FocusNode currentNode, bool vertical = false, bool first = false) { IEnumerable <FocusNode> nodes = currentNode.nearestScope.traversalDescendants; List <FocusNode> sorted = nodes.ToList(); FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => { if (vertical) { if (first) { return(a.rect.top.CompareTo(b.rect.top)); } else { return(b.rect.bottom.CompareTo(a.rect.bottom)); } } else { if (first) { return(a.rect.left.CompareTo(b.rect.left)); } else { return(b.rect.right.CompareTo(a.rect.right)); } } }); if (sorted.isNotEmpty()) { return(sorted.First()); } return(null); }
public FocusableActionDetector( Key key = null, bool?enabled = true, FocusNode focusNode = null, bool?autofocus = false, Dictionary <LogicalKeySet, Intent> shortcuts = null, Dictionary <LocalKey, ActionFactory> actions = null, ValueChanged <bool> onShowFocusHighlight = null, ValueChanged <bool> onShowHoverHighlight = null, ValueChanged <bool> onFocusChange = null, Widget child = null ) : base(key: key) { D.assert(enabled != null); D.assert(autofocus != null); D.assert(child != null); this.enabled = enabled.Value; this.focusNode = focusNode; this.autofocus = autofocus.Value; this.shortcuts = shortcuts; this.actions = actions; this.onShowFocusHighlight = onShowFocusHighlight; this.onShowHoverHighlight = onShowHoverHighlight; this.onFocusChange = onFocusChange; this.child = child; }
public IEnumerable <FocusNode> _sortAndFilterHorizontally( TraversalDirection direction, Rect target, FocusNode nearestScope) { D.assert(direction == TraversalDirection.left || direction == TraversalDirection.right); IEnumerable <FocusNode> nodes = nearestScope.traversalDescendants; D.assert(!nodes.Contains(nearestScope)); List <FocusNode> sorted = nodes.ToList(); FocusTravesalUtils.mergeSort <FocusNode>(sorted, compare: (FocusNode a, FocusNode b) => a.rect.center.dx.CompareTo(b.rect.center.dx)); IEnumerable <FocusNode> result = new List <FocusNode>(); switch (direction) { case TraversalDirection.left: result = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dx <= target.left)); break; case TraversalDirection.right: result = LinqUtils <FocusNode> .WhereList(sorted, ((FocusNode node) => node.rect != target && node.rect.center.dx >= target.right)); break; case TraversalDirection.up: case TraversalDirection.down: break; } return(result); }
public SelectableText(TextSpan textSpan, Key key = null, TextStyle style = null, TextAlign?textAlign = null, bool?softWrap = null, TextOverflow?overflow = null, float?textScaleFactor = null, int?maxLines = null, FocusNode focusNode = null, Color selectionColor = null, GestureTapDownCallback onTapDown = null, GestureTapUpCallback onTapUp = null, GestureTapCancelCallback onTapCancel = null) : base(key) { D.assert(textSpan != null); this.textSpan = textSpan; this.data = null; this.style = style; this.textAlign = textAlign; this.softWrap = softWrap; this.overflow = overflow; this.textScaleFactor = textScaleFactor; this.maxLines = maxLines; this.focusNode = focusNode ?? new FocusNode(); this.selectionColor = selectionColor; this.onTapDown = onTapDown; this.onTapUp = onTapUp; this.onTapCancel = onTapCancel; }
public _ReadingOrderSortData(FocusNode node) { D.assert(node != null); this.node = node; rect = node.rect; directionality = _findDirectionality(node.context); }
public static SelectableText rich(TextSpan textSpan, Key key = null, TextStyle style = null, TextAlign?textAlign = null, bool?softWrap = null, TextOverflow?overflow = null, float?textScaleFactor = null, int?maxLines = null, FocusNode focusNode = null, Color selectionColor = null, GestureTapDownCallback onTapDown = null, GestureTapUpCallback onTapUp = null, GestureTapCancelCallback onTapCancel = null) { return(new SelectableText( textSpan, key, style, textAlign, softWrap, overflow, textScaleFactor, maxLines, focusNode, selectionColor, onTapDown, onTapUp, onTapCancel)); }
public _DirectionalPolicyDataEntry( TraversalDirection direction, FocusNode node) { this.direction = direction; this.node = node; }
internal void _willDisposeFocusNode(FocusNode node) { D.assert(node != null); if (this._currentFocus == node) { this._currentFocus = null; } }
public override void invoke(FocusNode node, Intent intent) { intent = (DirectionalFocusIntent)intent; if (!((DirectionalFocusIntent)intent).ignoreTextFields || !(node.context.widget is EditableText)) { node.focusInDirection(((DirectionalFocusIntent)intent).direction); } }
public static void _focusAndEnsureVisible( FocusNode node, ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicitPolicy ) { node.requestFocus(); Scrollable.ensureVisible(node.context, alignment: 1.0f, alignmentPolicy: alignmentPolicy); }
public override void initState() { base.initState(); focusNode = new FocusNode( canRequestFocus: false, skipTraversal: true, debugLabel: "FocusTraversalGroup" ); }
public _OrderedFocusInfo( FocusNode node = null, FocusOrder order = null) { D.assert(node != null); D.assert(order != null); this.order = order; this.node = node; }
public void autofocus(FocusNode node) { D.assert(node != null); if (this._focus == null) { node._hasKeyboardToken = true; this._setFocus(node); } }
public EditableText(TextEditingController controller, FocusNode focusNode, TextStyle style, Color cursorColor, bool obscureText = false, bool autocorrect = false, TextAlign textAlign = TextAlign.left, TextDirection?textDirection = null, float?textScaleFactor = null, int?maxLines = 1, bool autofocus = false, Color selectionColor = null, TextSelectionControls selectionControls = null, TextInputType keyboardType = null, TextInputAction?textInputAction = null, TextCapitalization textCapitalization = TextCapitalization.none, ValueChanged <string> onChanged = null, VoidCallback onEditingComplete = null, ValueChanged <string> onSubmitted = null, SelectionChangedCallback onSelectionChanged = null, List <TextInputFormatter> inputFormatters = null, bool rendererIgnoresPointer = false, EdgeInsets scrollPadding = null, bool unityTouchKeyboard = false, Key key = null) : base(key) { D.assert(controller != null); D.assert(focusNode != null); D.assert(style != null); D.assert(cursorColor != null); D.assert(maxLines == null || maxLines > 0); this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); this.controller = controller; this.focusNode = focusNode; this.obscureText = obscureText; this.autocorrect = autocorrect; this.style = style; this.textAlign = textAlign; this.textDirection = textDirection; this.textScaleFactor = textScaleFactor; this.textInputAction = textInputAction; this.textCapitalization = textCapitalization; this.cursorColor = cursorColor; this.maxLines = maxLines; this.autofocus = autofocus; this.selectionColor = selectionColor; this.onChanged = onChanged; this.onSubmitted = onSubmitted; this.onSelectionChanged = onSelectionChanged; this.onEditingComplete = onEditingComplete; this.rendererIgnoresPointer = rendererIgnoresPointer; this.selectionControls = selectionControls; this.unityTouchKeyboard = unityTouchKeyboard; if (maxLines == 1) { this.inputFormatters = new List <TextInputFormatter>(); this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter); if (inputFormatters != null) { this.inputFormatters.AddRange(inputFormatters); } } else { this.inputFormatters = inputFormatters; } }
internal void _setFocus(FocusNode node) { D.assert(node != null); D.assert(node._parent == null); D.assert(this._focus == null); this._focus = node; this._focus._parent = this; this._focus._manager = this._manager; this._focus._hasKeyboardToken = true; this._didChangeFocusChain(); }
public _FocusTraversalGroupMarker( FocusTraversalPolicy policy = null, FocusNode focusNode = null, Widget child = null ) : base(child: child) { D.assert(policy != null); D.assert(focusNode != null); this.policy = policy; this.focusNode = focusNode; }
public bool invokeAction(UiWidgetAction action, Intent intent, FocusNode focusNode = null) { D.assert(action != null); D.assert(intent != null); focusNode = focusNode ?? FocusManagerUtils.primaryFocus; if (action != null && intent.isEnabled(focusNode.context)) { action.invoke(focusNode, intent); return(true); } return(false); }
public void reparent(FocusNode parent = null) { D.assert(_node != null); if (isAttached) { D.assert(_node.context != null); parent = parent ?? Focus.of(_node.context, nullOk: true, scopeOk: true); parent = parent ?? _node.context.owner.focusManager.rootScope; D.assert(parent != null); parent._reparent(_node); } }
internal void _resignFocus(FocusNode node) { D.assert(node != null); if (this._focus != node) { return; } this._focus._parent = null; this._focus._manager = null; this._focus = null; this._didChangeFocusChain(); }
public void reparentIfNeeded(FocusNode node) { D.assert(node != null); if (node._parent == null || node._parent == this) { return; } node.unfocus(); D.assert(node._parent == null); if (this._focus == null) { this._setFocus(node); } }
public RawKeyboardListener( Key key = null, FocusNode focusNode = null, bool autofocus = false, ValueChanged <RawKeyEvent> onKey = null, Widget child = null ) : base(key: key) { D.assert(focusNode != null); D.assert(child != null); this.focusNode = focusNode; this.autofocus = autofocus; this.onKey = onKey; this.child = child; }
public override void changedScope(FocusNode node = null, FocusScopeNode oldScope = null) { base.changedScope(node: node, oldScope: oldScope); if (oldScope != null) { var delEntries = LinqUtils <_DirectionalPolicyDataEntry> .WhereList(_policyData[oldScope]?.history, ((_DirectionalPolicyDataEntry entry) => { return(entry.node == node); })); foreach (var delEntry in delEntries) { _policyData[oldScope]?.history?.Remove(delEntry); } } }
public virtual FocusNode findFirstFocus(FocusNode currentNode) { D.assert(currentNode != null); FocusScopeNode scope = currentNode.nearestScope; FocusNode candidate = scope.focusedChild; if (candidate == null && scope.descendants.Any()) { IEnumerable <FocusNode> sorted = _sortAllDescendants(scope); candidate = sorted.Any() ? sorted.First() : null; } candidate = candidate ?? currentNode; return(candidate); }
public void requestFocus(FocusNode node) { D.assert(node != null); if (this._focus == node) { return; } if (this._focus != null) { this._focus.unfocus(); } node._hasKeyboardToken = true; this._setFocus(node); }
public void _markNextFocus(FocusNode newFocus) { if (_manager != null) { // If we have a manager, then let it handle the focus change. _manager._markNextFocus(this); return; } newFocus?._setAsFocusedChildForScope(); newFocus?._notify(); if (newFocus != this) { _notify(); } }
public void _reparent(FocusNode child) { D.assert(child != null); D.assert(child != this, () => "Tried to make a child into a parent of itself."); if (child._parent == this) { D.assert(_children.Contains(child), () => "Found a node that says it's a child, but doesn't appear in the child list."); // The child is already a child of this parent. return; } D.assert(_manager == null || child != _manager.rootScope, () => "Reparenting the root node isn't allowed."); D.assert(!ancestors.Contains(child), () => "The supplied child is already an ancestor of this node. Loops are not allowed."); FocusScopeNode oldScope = child.enclosingScope; bool hadFocus = child.hasFocus; child._parent?._removeChild(child, removeScopeFocus: oldScope != nearestScope); _children.Add(child); child._parent = this; child._ancestors = null; child._updateManager(_manager); foreach (FocusNode ancestor in child.ancestors) { ancestor._descendants = null; } if (hadFocus) { _manager?.primaryFocus?._setAsFocusedChildForScope(); } if (oldScope != null && child.context != null && child.enclosingScope != oldScope) { //UnityEngine.Debug.Log("FocusTraversalGroup.of(child.context, nullOk: true)?.changedScope(node: child, oldScope: oldScope);"); FocusTraversalGroup.of(child.context, nullOk: true)?.changedScope(node: child, oldScope: oldScope); } if (child._requestFocusWhenReparented) { child._doRequestFocus(findFirstFocus: true); child._requestFocusWhenReparented = false; } }
public void requestFocus(FocusNode node = null) { if (node != null) { if (node._parent == null) { _reparent(node); } D.assert(node.ancestors.Contains(this), () => "Focus was requested for a node that is not a descendant of the scope from which it was requested."); node._doRequestFocus(findFirstFocus: true); return; } _doRequestFocus(findFirstFocus: true); }
public void _initNode() { if (widget.focusNode == null) { _internalNode = _internalNode ?? _createNode(); } if (widget.skipTraversal != null) { focusNode.skipTraversal = widget.skipTraversal.Value; } if (widget.canRequestFocus != null) { focusNode.canRequestFocus = widget.canRequestFocus.Value; } _canRequestFocus = focusNode.canRequestFocus; _hasPrimaryFocus = focusNode.hasPrimaryFocus; _focusAttachment = focusNode.attach(context, onKey: widget.onKey); focusNode.addListener(_handleFocusChanged); }
public override FocusNode findFirstFocusInDirection(FocusNode currentNode, TraversalDirection direction) { D.assert(direction != null); D.assert(currentNode != null); switch (direction) { case TraversalDirection.up: return(_sortAndFindInitial(currentNode, vertical: true, first: false)); case TraversalDirection.down: return(_sortAndFindInitial(currentNode, vertical: true, first: true)); case TraversalDirection.left: return(_sortAndFindInitial(currentNode, vertical: false, first: false)); case TraversalDirection.right: return(_sortAndFindInitial(currentNode, vertical: false, first: true)); } return(null); }
public void _setAsFocusedChildForScope() { FocusNode scopeFocus = this; foreach (var ancestor in ancestors) { if (ancestor is FocusScopeNode) { D.assert(scopeFocus != ancestor, () => "Somehow made a loop by setting focusedChild to its scope."); D.assert(FocusManagerUtils._focusDebug($"Setting {scopeFocus} as focused child for scope:", new List <string> { ancestor.ToString() })); ((FocusScopeNode)ancestor)._focusedChildren.Remove(scopeFocus); ((FocusScopeNode)ancestor)._focusedChildren.Add(scopeFocus); scopeFocus = ancestor; } } }