public static void SetFocus(IFocusableWidget widget, bool value = true) { WindowController.Instance.ScheduleAction(delegate { widget.SetFocused(value); }, 1); // schedule for the next frame }
internal static void UpdateFocus(IFocusableWidget widget, bool focus) { IWindowContainer window = ((WindowObject)widget).Window; if (window == null) { return; // no window, no crime } int windowHash = window.GetHashCode(); IFocusableWidget focusedWidget; s_focusedWidgets.TryGetValue(windowHash, out focusedWidget); // Nomad: PVS analyzer indicated some amount of fuzzy logic here. // I think that whole focusing and unfocusing logic should be refactored if (widget == focusedWidget) { if (!focus && focusedWidget != null) { focusedWidget.SetFocused(false); s_focusedWidgets.Remove(windowHash); WindowController.Instance.ShowKeyboard(false); } return; } if (focusedWidget != null) { IFocusableWidget oldWidget = focusedWidget; s_focusedWidgets.Remove(windowHash); oldWidget.SetFocused(false); } focusedWidget = widget; WindowController.Instance.ShowKeyboard(focus && (focusedWidget is WidgetTextEdit || focusedWidget is WidgetTextField)); if (focusedWidget == null) { s_focusedWidgets.Remove(windowHash); } else { if (focus) { focusedWidget.SetFocused(true); } s_focusedWidgets[windowHash] = focusedWidget; } }
internal static void UpdateFocus(IFocusableWidget widget, bool focus) { IWindowContainer window = ((WindowObject)widget).Window; if (window == null) { return; // no window, no crime } int windowHash = window.GetHashCode(); IFocusableWidget focusedWidget = null; s_focusedWidgets.TryGetValue(windowHash, out focusedWidget); if (!focus) { if (widget == focusedWidget) { s_focusedWidgets.Remove(windowHash); } return; } if (focus && widget == focusedWidget) { return; } if (focusedWidget != null && focus) { IFocusableWidget oldWidget = focusedWidget; s_focusedWidgets.Remove(windowHash); oldWidget.SetFocused(false); } if (focus) { focusedWidget = widget; focusedWidget.SetFocused(true); } if (focusedWidget == null) { s_focusedWidgets.Remove(windowHash); } else { s_focusedWidgets[windowHash] = focusedWidget; } }
public WidgetDecorator(Widget widget) { this.widget = widget; this.widget.ButtonPressEvent += widget_ButtonPressEvent; this.widget.FocusInEvent += widget_FocusInEvent; this.widget.FocusOutEvent += widget_FocusOutEvent; if (this.widget is IFocusableWidget) { IFocusableWidget focuswidget = (IFocusableWidget)this.widget; focuswidget.FocusOut += focuswidget_FocusOut; } HandleWidgetRealized(); }
public static bool HasFocus(IWindowContainer window) { if (window == null) { return(false); // no window, no crime } int windowHash = window.GetHashCode(); IFocusableWidget focusedWidget = null; if (s_focusedWidgets.TryGetValue(windowHash, out focusedWidget)) { return(focusedWidget != null); } return(false); }
internal static bool FocusNext(IFocusableWidget widget) { WindowObject obj = widget as WindowObject; if (obj == null) { throw new ArgumentException(nameof(widget) + " is not a WindowObject!"); } IWindowContainer window = obj.Window; if (window == null) { return(false); } List <WindowObject> focusables = new List <WindowObject>(); Window.FindChildren(window, (WindowObject arg) => arg is IFocusableWidget, focusables); WindowObject nextFocusable = null; for (int i = 0; i < focusables.Count; i++) { if (focusables[i] == widget) { nextFocusable = focusables[(i + 1) % focusables.Count]; break; } } if (nextFocusable == null || nextFocusable == widget) { return(false); // do nothing } UpdateFocus((IFocusableWidget)nextFocusable, true); return(true); }