Skip to content

Commit

Permalink
Merge branch '4.22'
Browse files Browse the repository at this point in the history
  • Loading branch information
goncasmage1 committed Jun 28, 2019
2 parents 89e9c30 + 1294d25 commit 5ed9671
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
25 changes: 13 additions & 12 deletions Source/UINavigation/Private/UINavSlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ void UUINavSlider::NativeConstruct()
}

if (!Slider->OnValueChanged.IsBound()) Slider->OnValueChanged.AddDynamic(this, &UUINavSlider::HandleOnSliderValueChanged);
Slider->StepSize = Interval / (MaxValue - MinValue);

MaxOption = ((MaxValue - MinValue) / Interval);
Difference = MaxValue - MinValue;
Slider->StepSize = Interval / Difference;

MaxOptionIndex = (Difference / Interval);
HandleDefaultColor = Slider->SliderHandleColor;
BarDefaultColor = Slider->SliderBarColor;

Expand All @@ -46,13 +48,15 @@ void UUINavSlider::NativeConstruct()

void UUINavSlider::Update()
{
Slider->SetValue((float)OptionIndex / (float)MaxOption);
Slider->SetValue((float)OptionIndex / (float)MaxOptionIndex);
FNumberFormattingOptions FormatOptions;
FormatOptions.MaximumFractionalDigits = MaxDecimalDigits;
FormatOptions.MinimumFractionalDigits = MinDecimalDigits;
float Value = MinValue + Slider->Value * MaxValue;

float Value = MinValue + Slider->Value * Difference;
FText ValueText = FText::AsNumber(Value, &FormatOptions);
if (!bUseComma) ValueText = FText::FromString(ValueText.ToString().Replace(TEXT(","),TEXT(".")));

if (NavText != nullptr) NavText->SetText(ValueText);
if (NavSpinBox != nullptr) NavSpinBox->SetValue(Value);
}
Expand All @@ -75,6 +79,7 @@ void UUINavSlider::NavigateLeft()
{
OptionIndex--;
}
else if (bLoopOptions) OptionIndex = MaxOptionIndex;

Update();

Expand All @@ -83,15 +88,11 @@ void UUINavSlider::NavigateLeft()

void UUINavSlider::NavigateRight()
{
if (OptionIndex < MaxOption)
if (OptionIndex < MaxOptionIndex)
{
OptionIndex++;
}
else
{
OnNavigateRight();
return;
}
else if (bLoopOptions) OptionIndex = 0;

Update();

Expand All @@ -113,11 +114,11 @@ void UUINavSlider::HandleOnSpinBoxValueChanged(float InValue, ETextCommit::Type
float UUINavSlider::IndexFromPercent(float Value)
{
float Div = Value / Slider->StepSize;
if (Div > MaxOption) Div = MaxOption;
if (Div > MaxOptionIndex) Div = MaxOptionIndex;

int FlatDiv = (int)Div;
float Decimal = Div - FlatDiv;
return Decimal < 0.5 ? FlatDiv : (FlatDiv + 1 <= MaxOption ? FlatDiv + 1 : MaxOption);
return Decimal < 0.5 ? FlatDiv : (FlatDiv + 1 <= MaxOptionIndex ? FlatDiv + 1 : MaxOptionIndex);
}

float UUINavSlider::IndexFromValue(float Value)
Expand Down
12 changes: 7 additions & 5 deletions Source/UINavigation/Public/UINavSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ class UINAVIGATION_API UUINavSlider : public UUINavHorizontalComponent
int MinDecimalDigits = 0;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin="0"))
bool bUseComma = false;
int MaxOption = 0;

FLinearColor HandleDefaultColor;
FLinearColor BarDefaultColor;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin = "0"))
int MaxOptionIndex = 0;
float Difference = 0.0f;

FLinearColor HandleDefaultColor = FColor::Black;
FLinearColor BarDefaultColor = FColor::Black;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavSlider, meta = (ClampMin = "0"))
FLinearColor HandleHoverColor;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = UINavSlider, meta = (ClampMin = "0"))
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavSlider, meta = (ClampMin = "0"))
FLinearColor BarHoverColor;

virtual void NativeConstruct() override;
Expand Down
2 changes: 1 addition & 1 deletion UINavigation.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "2.5.0",
"VersionName": "2.5.2",
"FriendlyName": "UI Navigation",
"Description": "A plugin that allows you to easily setup mouse, keyboard and controller navigation in UMG, among other things.",
"Category": "Plugins",
Expand Down

0 comments on commit 5ed9671

Please sign in to comment.