Initial Keyboard and Gamepad support on Slider Control

This commit is contained in:
Phantom
2026-05-15 00:00:05 +02:00
parent ec73cc6b0d
commit 356228d4d4
+50
View File
@@ -1,6 +1,7 @@
// Copyright (c) Wojciech Figat. All rights reserved.
using System;
using System.Collections.Generic;
namespace FlaxEngine.GUI;
@@ -408,6 +409,40 @@ public class Slider : ContainerControl
base.OnLostFocus();
}
/// <inheritdoc />
public override Control OnNavigate(NavDirection direction, Float2 location, Control caller, List<Control> visited)
{
bool _isHorizontal = Direction is SliderDirection.HorizontalRight or SliderDirection.HorizontalLeft;
float keyOrGamepadPosition = _isHorizontal ? location.X : location.Y;
if (_thumbRect.Contains(ref location))
{
// Start sliding
_isSliding = true;
SlidingStart?.Invoke();
return this;
}
else
{
Value += (keyOrGamepadPosition < _thumbCenter ? -1 : 1) * 10;
}
return base.OnNavigate(direction, location, caller, visited);
}
/// <inheritdoc />
public override bool OnKeyDown(KeyboardKeys key)
{
if (key == KeyboardKeys.Escape)
{
Defocus();
return true;
}
return base.OnKeyDown(key);
}
/// <inheritdoc />
public override bool OnMouseDown(Float2 location, MouseButton button)
{
@@ -443,6 +478,21 @@ public class Slider : ContainerControl
return base.OnMouseDown(location, button);
}
/// <inheritdoc />
public override bool OnTouchDown(Float2 location, int pointerId)
{
if (base.OnTouchDown(location, pointerId))
return true;
if (!new Rectangle(Float2.Zero, Size).Contains(ref location))
{
Defocus();
return true;
}
return false;
}
/// <inheritdoc />
public override void OnMouseMove(Float2 location)
{