diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ae77ce..b681821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Fixes - Fixed images not updating their hidden state properly when the displayed texture changes - Fixed AutoInline elements overflowing into their parent if it's taller - Fixed Paragraph and Checkbox not reacting to SquishingGroup sizing properly +- Fixed TextInput and Slider still reacting to input when they are selected, but not part of the active root ## 6.1.0 diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index e003314..7d9f55a 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -320,9 +320,15 @@ namespace MLEM.Ui.Elements { public bool IsMouseOver => this.Controls.MousedElement == this || this.Controls.TouchedElement == this; /// /// Returns whether this element is its 's . + /// Note that, unlike , this property will be even if this element's is not the . /// public bool IsSelected => this.Root.SelectedElement == this; /// + /// Returns whether this element is its 's . + /// Note that can be used to query whether this element is its 's instead. + /// + public bool IsSelectedActive => this.Controls.SelectedElement == this; + /// /// Returns whether this element's method has been recently called and its area has not been updated since then using or . /// public bool AreaDirty { get; private set; } diff --git a/MLEM.Ui/Elements/Slider.cs b/MLEM.Ui/Elements/Slider.cs index c6b1972..31be823 100644 --- a/MLEM.Ui/Elements/Slider.cs +++ b/MLEM.Ui/Elements/Slider.cs @@ -29,7 +29,7 @@ namespace MLEM.Ui.Elements { public override void Update(GameTime time) { base.Update(time); - if (this.IsSelected) { + if (this.IsSelectedActive) { if (this.CurrentValue > 0 && this.Controls.LeftButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) { this.CurrentValue -= this.StepPerScroll; } else if (this.CurrentValue < this.MaxValue && this.Controls.RightButtons.TryConsumePressed(this.Input, this.Controls.GamepadIndex)) { diff --git a/MLEM.Ui/Elements/TextField.cs b/MLEM.Ui/Elements/TextField.cs index 307fae5..40fb0f7 100644 --- a/MLEM.Ui/Elements/TextField.cs +++ b/MLEM.Ui/Elements/TextField.cs @@ -192,7 +192,7 @@ namespace MLEM.Ui.Elements { this.SetText(this.Multiline ? result : result.Replace('\n', ' '), true); }; this.OnTextInput += (element, key, character) => { - if (this.IsSelected && !this.IsHidden) + if (this.IsSelectedActive && !this.IsHidden) this.textInput.OnTextInput(key, character); }; this.OnDeselected += e => this.CaretPos = 0; @@ -209,7 +209,7 @@ namespace MLEM.Ui.Elements { /// public override void Update(GameTime time) { base.Update(time); - if (this.IsSelected && !this.IsHidden) + if (this.IsSelectedActive && !this.IsHidden) this.textInput.Update(time, this.Input); }