using System; using System.Reactive.Concurrency; using System.Reactive.Linq; using System.Reactive.Subjects; using System.Threading; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Input.Platform; using Avalonia.Threading; using DryIoc; namespace Artemis.UI.Shared; /// /// Static UI helpers. /// public static class UI { private static readonly BehaviorSubject MicaEnabledSubject = new(false); public static EventLoopScheduler BackgroundScheduler = new(ts => new Thread(ts)); static UI() { KeyBindingsEnabled = InputElement.GotFocusEvent.Raised.Select(e => e.Item2.Source is not TextBox).StartWith(true); MicaEnabled = MicaEnabledSubject.AsObservable(); } /// /// Gets the current IoC locator. /// public static IContainer Locator { get; set; } = null!; /// /// Gets the clipboard. /// public static IClipboard Clipboard { get; set; } = null!; /// /// Gets a boolean indicating whether hotkeys are to be disabled. /// public static IObservable KeyBindingsEnabled { get; } /// /// Gets a boolean indicating whether the Mica effect should be enabled. /// public static IObservable MicaEnabled { get; } /// /// Changes whether Mica should be enabled. /// /// public static void SetMicaEnabled(bool enabled) { if (MicaEnabledSubject.Value != enabled) Dispatcher.UIThread.Invoke(() => MicaEnabledSubject.OnNext(enabled)); } internal static void ClearCache() { DeviceVisualizer.BitmapCache.Clear(); } }