public void ReleaseFocus(IFocusable target) { if (m_FocusedElement == null) { return; } if (m_FocusedElement.isDisabled || m_FocusedElement.isDestroyed) { m_FocusedElement = null; focusableIndex = -1; onFocusChanged?.Invoke(target); return; } if (m_FocusedElement == (UIElement)target) { IFocusable focusable = (IFocusable)m_FocusedElement; m_FocusedElement.style.ExitState(StyleState.Focused); focusable.Blur(); // todo -- if focus handlers added via template invoke them m_FocusedElement = null; focusableIndex = -1; onFocusChanged?.Invoke(target); } }
public bool RequestFocus(IFocusable target) { if (!(target is UIElement element && !element.isDisabled)) { return(false); } // try focus the element early to see if they accept being focused. if (!target.Focus()) { return(false); } // todo -- if focus handlers added via template invoke them if (m_FocusedElement != null) { if (m_FocusedElement == (UIElement)target) { return(true); } IFocusable focusable = (IFocusable)m_FocusedElement; m_FocusedElement.style.ExitState(StyleState.Focused); focusable.Blur(); onFocusChanged?.Invoke(target); } m_FocusedElement = (UIElement)target; m_FocusedElement.style.EnterState(StyleState.Focused); onFocusChanged?.Invoke(target); focusableIndex = -1; for (int i = 0; i < focusables.Count; i++) { if (focusables[i] == target) { focusableIndex = i; return(true); } } return(true); }