From e38d95c665843a5c5856e44b865f4d22e1a03c15 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 11 Sep 2019 10:49:51 +0200 Subject: [PATCH] make next elements into delegates rather than a method --- MLEM.Ui/Elements/Element.cs | 16 ++++++++-------- MLEM.Ui/Elements/Slider.cs | 11 +++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index bee99b8..ca1f6ac 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -79,6 +79,8 @@ namespace MLEM.Ui.Elements { public GenericCallback OnAreaUpdated; public OtherElementCallback OnMousedElementChanged; public OtherElementCallback OnSelectedElementChanged; + public TabNextElementCallback GetTabNextElement; + public GamepadNextElementCallback GetGamepadNextElement; private UiSystem system; public UiSystem System { @@ -145,6 +147,8 @@ namespace MLEM.Ui.Elements { this.OnMouseExit += element => this.IsMouseOver = false; this.OnSelected += element => this.IsSelected = true; this.OnDeselected += element => this.IsSelected = false; + this.GetTabNextElement = (backward, next) => next; + this.GetGamepadNextElement = (dir, next) => next; this.SetAreaDirty(); } @@ -434,14 +438,6 @@ namespace MLEM.Ui.Elements { return this.CanBeMoused && this.Area.Contains(position) ? this : null; } - public virtual Element GetTabNextElement(bool backward, Element usualNext) { - return usualNext; - } - - public virtual Element GetGamepadNextElement(Direction2 dir, Element usualNext) { - return usualNext; - } - public void AndChildren(Action action) { action(this); foreach (var child in this.Children) @@ -460,5 +456,9 @@ namespace MLEM.Ui.Elements { public delegate void DrawCallback(Element element, GameTime time, SpriteBatch batch, float alpha); + public delegate Element TabNextElementCallback(bool backward, Element usualNext); + + public delegate Element GamepadNextElementCallback(Direction2 dir, Element usualNext); + } } \ No newline at end of file diff --git a/MLEM.Ui/Elements/Slider.cs b/MLEM.Ui/Elements/Slider.cs index cb57c00..980a7db 100644 --- a/MLEM.Ui/Elements/Slider.cs +++ b/MLEM.Ui/Elements/Slider.cs @@ -8,6 +8,11 @@ namespace MLEM.Ui.Elements { public Slider(Anchor anchor, Vector2 size, int scrollerSize, float maxValue) : base(anchor, size, scrollerSize, maxValue, true) { this.CanBeSelected = true; + this.GetGamepadNextElement = (dir, next) => { + if (dir == Direction2.Left || dir == Direction2.Right) + return null; + return next; + }; } public override void Update(GameTime time) { @@ -22,11 +27,5 @@ namespace MLEM.Ui.Elements { } } - public override Element GetGamepadNextElement(Direction2 dir, Element usualNext) { - if (dir == Direction2.Left || dir == Direction2.Right) - return null; - return base.GetGamepadNextElement(dir, usualNext); - } - } } \ No newline at end of file