From fa34258bbefe879fb1f297a9eb5351b1e13c424a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 14 Mar 2022 16:12:51 +0100 Subject: [PATCH] Added UiControls.AutoNavModeChanged event --- CHANGELOG.md | 1 + MLEM.Ui/UiControls.cs | 79 +++++++++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29c1320..170246c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Removals ### MLEM.Ui Additions - Added Element.OnStyleInit event +- Added UiControls.AutoNavModeChanged event Improvements - Allow for checkboxes and radio buttons to be disabled diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index 4c9e636..697e7ac 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -21,36 +21,6 @@ namespace MLEM.Ui { /// The input handler that is used for querying input /// public readonly InputHandler Input; - /// - /// This value ist true if the was created by this ui controls instance, or if it was passed in. - /// If the input handler was created by this instance, its method should be called by us. - /// - protected readonly bool IsInputOurs; - /// - /// The that this ui controls instance is controlling - /// - protected readonly UiSystem System; - - /// - /// The that is currently active. - /// The active root element is the one with the highest that whose property is true. - /// - public RootElement ActiveRoot { get; protected set; } - /// - /// The that the mouse is currently over. - /// - public Element MousedElement { get; protected set; } - /// - /// The that is currently touched. - /// - public Element TouchedElement { get; protected set; } - private readonly Dictionary selectedElements = new Dictionary(); - /// - /// The element that is currently selected. - /// This is the of the . - /// - public Element SelectedElement => this.GetSelectedElement(this.ActiveRoot); - /// /// A list of , and/or that act as the buttons on the keyboard which perform the action. /// If the is held, these buttons perform . @@ -85,6 +55,25 @@ namespace MLEM.Ui { /// This can be used to easily serialize and deserialize all ui keybinds. /// public readonly Keybind[] Keybinds; + + /// + /// The that is currently active. + /// The active root element is the one with the highest that whose property is true. + /// + public RootElement ActiveRoot { get; protected set; } + /// + /// The that the mouse is currently over. + /// + public Element MousedElement { get; protected set; } + /// + /// The that is currently touched. + /// + public Element TouchedElement { get; protected set; } + /// + /// The element that is currently selected. + /// This is the of the . + /// + public Element SelectedElement => this.GetSelectedElement(this.ActiveRoot); /// /// The zero-based index of the used for gamepad input. /// If this index is lower than 0, every connected gamepad will trigger input. @@ -113,9 +102,35 @@ namespace MLEM.Ui { /// /// If this value is true, the ui controls are in automatic navigation mode. /// This means that the will be drawn around the . - /// To set this value, use or /// - public bool IsAutoNavMode { get; internal set; } + public bool IsAutoNavMode { + get => this.isAutoNavMode; + set { + if (this.isAutoNavMode != value) { + this.isAutoNavMode = value; + this.AutoNavModeChanged?.Invoke(value); + } + } + } + + /// + /// An event that is raised when is changed. + /// This can be used for custom actions like hiding the mouse cursor when automatic navigation is enabled. + /// + public event Action AutoNavModeChanged; + + /// + /// This value ist true if the was created by this ui controls instance, or if it was passed in. + /// If the input handler was created by this instance, its method should be called by us. + /// + protected readonly bool IsInputOurs; + /// + /// The that this ui controls instance is controlling + /// + protected readonly UiSystem System; + + private readonly Dictionary selectedElements = new Dictionary(); + private bool isAutoNavMode; /// /// Creates a new instance of the ui controls.