From 08e28cb95ba05e603f6ba5e0029da3d3afb8892f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 18 Jul 2022 15:53:26 +0200 Subject: [PATCH] Allow manually setting a RootElement as CanBeActive --- CHANGELOG.md | 1 + MLEM.Ui/UiControls.cs | 4 ++-- MLEM.Ui/UiSystem.cs | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cf4d5..5dcb498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ Improvements - Don't query a paragraph's text callback in the constructor - Allow manually hiding a paragraph without its text overriding the hidden state - Added optional isKeybindAllowed parameter to KeybindButton +- Allow manually setting a RootElement as CanBeActive Fixes - Fixed auto-nav tooltip displaying on the selected element even when not in auto-nav mode diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index a279e5e..8f47cf4 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -57,7 +57,7 @@ namespace MLEM.Ui { /// /// The that is currently active. - /// The active root element is the one with the highest that whose property is true. + /// The active root element is the one with the highest that . /// public RootElement ActiveRoot { get; protected set; } /// @@ -155,7 +155,7 @@ namespace MLEM.Ui { public virtual void Update() { if (this.IsInputOurs) this.Input.Update(); - this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => !root.Element.IsHidden && root.CanSelectContent); + this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanBeActive); // MOUSE INPUT if (this.HandleMouse) { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index d9325ac..9176fbb 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -508,7 +508,6 @@ namespace MLEM.Ui { /// The that this root element is a part of. /// public readonly UiSystem System; - private float scale = 1; /// /// The scale of this root element. /// Note that, to change the scale of every root element, you can use @@ -522,7 +521,6 @@ namespace MLEM.Ui { this.Element.ForceUpdateArea(); } } - private int priority; /// /// The priority of this root element. /// A higher priority means the element will be updated first, as well as rendered on top. @@ -539,7 +537,6 @@ namespace MLEM.Ui { /// This is a combination of this root element's as well as the ui system's . /// public float ActualScale => this.System.GlobalScale * this.Scale; - /// /// The transformation that this root element (and all of its children) has. /// This transform is applied both to input, as well as to rendering. @@ -549,7 +546,6 @@ namespace MLEM.Ui { /// An inversion of /// public Matrix InvTransform => Matrix.Invert(this.Transform); - /// /// The child element of this root element that is currently selected. /// If there is no selected element in this root, this value will be null. @@ -557,9 +553,17 @@ namespace MLEM.Ui { public Element SelectedElement => this.System.Controls.GetSelectedElement(this); /// /// Determines whether this root element contains any children that . - /// This value is automatically calculated. + /// This value is automatically calculated, and used in . /// public bool CanSelectContent => this.Element.CanBeSelected || this.Element.GetChildren(c => c.CanBeSelected, true).Any(); + /// + /// Determines whether this root element can become the . + /// This property returns if is and the is not hidden, or if it has been set to manually. + /// + public bool CanBeActive { + get => this.canBeActive || (!this.Element.IsHidden && this.CanSelectContent); + set => this.canBeActive = value; + } /// /// Event that is invoked when a is added to this root element or any of its children. @@ -578,6 +582,10 @@ namespace MLEM.Ui { /// public event Action OnRemovedFromUi; + private float scale = 1; + private bool canBeActive; + private int priority; + internal RootElement(string name, Element element, UiSystem system) { this.Name = name; this.Element = element;