Implement overall improvements for code stability, fallbacks and keyboard interactions
This commit is contained in:
@@ -75,13 +75,31 @@ namespace KernelPanic.UI
|
||||
region.schedule.Execute(() =>
|
||||
{
|
||||
if (focused.panel != null) return;
|
||||
// A focus choice made since the rebuild takes precedence over restoration.
|
||||
var current = region.focusController?.focusedElement as VisualElement;
|
||||
if (current != null && current != focused) return;
|
||||
|
||||
bool CanRestoreTo(VisualElement element) => element != null && element.focusable && IsAvailable(element);
|
||||
VisualElement replacement = string.IsNullOrEmpty(name) ? null : region.Q(name);
|
||||
if (!CanRestoreTo(replacement)) replacement = null;
|
||||
if (replacement == null && !string.IsNullOrEmpty(text))
|
||||
replacement = region.Query<Button>().Where(button => button.text == text && button.enabledInHierarchy).First();
|
||||
replacement ??= region.Query<Button>().Where(button => button.enabledInHierarchy).First();
|
||||
replacement = region.Query<Button>().Where(button => button.text == text && CanRestoreTo(button)).First();
|
||||
replacement ??= region.Query<Button>().Where(button => CanRestoreTo(button)).First();
|
||||
if (replacement != null) replacement.Focus();
|
||||
else { region.focusable = true; region.Focus(); }
|
||||
else if (IsAvailable(region)) { region.focusable = true; region.Focus(); }
|
||||
});
|
||||
|
||||
static bool IsAvailable(VisualElement element)
|
||||
{
|
||||
if (element.panel == null || !element.enabledInHierarchy || !element.visible) return false;
|
||||
for (var parent = element; parent != null; parent = parent.parent)
|
||||
{
|
||||
// Inline changes may precede the next style/layout update.
|
||||
if (parent.style.display == DisplayStyle.None || parent.resolvedStyle.display == DisplayStyle.None ||
|
||||
parent.style.visibility == Visibility.Hidden) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ConstrainModalFocus(VisualElement overlay)
|
||||
|
||||
Reference in New Issue
Block a user