using Microsoft.Xna.Framework;
using MLEM.Misc;
namespace MLEM.Ui.Elements {
///
/// A slider element for use inside of a .
/// A slider is a horizontal whose value can additionally be controlled using the and .
///
public class Slider : ScrollBar {
///
/// Creates a new slider with the given settings
///
/// The slider's anchor
/// The slider's size
/// The size of the slider's scroller indicator
/// The slider's maximum value
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) {
base.Update(time);
if (this.IsSelected) {
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)) {
this.CurrentValue += this.StepPerScroll;
}
}
}
}
}