Merge branch 'ImprovementSlider' of https://github.com/ThePhantomMask/FlaxEngine into ThePhantomMask-ImprovementSlider

This commit is contained in:
2026-08-04 18:37:03 +02:00
+72
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,38 @@ 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))
{
_isSliding = true;
SlidingStart?.Invoke();
return this;
}
var SliderPosition = (Direction == SliderDirection.HorizontalRight || Direction == SliderDirection.VerticalDown) ? _keyOrGamepadPosition : - _keyOrGamepadPosition;
Value += (SliderPosition < _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 +476,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)
{
@@ -474,6 +522,18 @@ public class Slider : ContainerControl
}
}
/// <inheritdoc />
public override void OnKeyUp(KeyboardKeys key)
{
if (key == KeyboardKeys.Escape && _isSliding)
{
EndSliding();
return;
}
base.OnKeyUp(key);
}
/// <inheritdoc />
public override bool OnMouseUp(Float2 location, MouseButton button)
{
@@ -486,6 +546,18 @@ public class Slider : ContainerControl
return base.OnMouseUp(location, button);
}
/// <inheritdoc />
public override bool OnTouchUp(Float2 location, int pointerId)
{
if (base.OnTouchUp(location, pointerId) && _isSliding)
{
EndSliding();
return true;
}
return false;
}
/// <inheritdoc />
public override void OnEndMouseCapture()
{