From fac7f2beb0380a289af2fb4239ba1ee9c814bfbf Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 20 Aug 2019 21:41:22 +0200 Subject: [PATCH] propagate mouse events to children by default, except for panels that handle overflow --- MLEM.Ui/Elements/Element.cs | 6 ++---- MLEM.Ui/Elements/Panel.cs | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index ebe281b..f9aacbc 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -402,17 +402,15 @@ namespace MLEM.Ui.Elements { } } - public Element GetMousedElement() { + public virtual Element GetMousedElement() { if (this.IsHidden || this.IgnoresMouse) return null; - if (!this.Area.Contains(this.MousePos)) - return null; for (var i = this.SortedChildren.Count - 1; i >= 0; i--) { var element = this.SortedChildren[i].GetMousedElement(); if (element != null) return element; } - return this; + return this.Area.Contains(this.MousePos) ? this : null; } protected virtual void InitStyle(UiStyle style) { diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 6470720..82712d0 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -106,6 +106,13 @@ namespace MLEM.Ui.Elements { base.DrawEarly(time, batch, alpha, blendState, samplerState); } + public override Element GetMousedElement() { + // if overflow is handled, don't propagate mouse checks to hidden children + if (this.scrollOverflow && !this.Area.Contains(this.MousePos)) + return null; + return base.GetMousedElement(); + } + private Rectangle GetRenderTargetArea() { var area = this.ChildPaddedArea; area.X = this.DisplayArea.X;