Add RefreshFocussedStyle method to allow runtime changes to widget style

This commit is contained in:
Steve Streeting 2022-01-21 16:44:48 +00:00
parent 51a57c35ef
commit 05a1c1ab46
4 changed files with 32 additions and 5 deletions

View File

@ -31,11 +31,16 @@ TSharedRef<SWidget> UFocusableButton::RebuildWidget()
Cast<UButtonSlot>(GetContentSlot())->BuildSlot(MyButton.ToSharedRef());
}
RefreshFocussedStyle();
return MyButton.ToSharedRef();
}
void UFocusableButton::RefreshFocussedStyle_Implementation()
{
// Copy Widget style but make normal same as hovered
FocussedStyle = WidgetStyle;
FocussedStyle.Normal = FocussedStyle.Hovered;
return MyButton.ToSharedRef();
}
void UFocusableButton::SlateHandleFocusReceived()

View File

@ -24,14 +24,20 @@ TSharedRef<SWidget> UFocusableCheckBox::RebuildWidget()
MyCheckbox->SetContent(GetContentSlot()->Content ? GetContentSlot()->Content->TakeWidget() : SNullWidget::NullWidget);
}
RefreshFocussedStyle();
return MyCheckbox.ToSharedRef();
}
void UFocusableCheckBox::RefreshFocussedStyle_Implementation()
{
// Copy Widget style but make normal same as hovered
FocussedStyle = WidgetStyle;
FocussedStyle.UncheckedImage = FocussedStyle.UncheckedHoveredImage;
FocussedStyle.CheckedImage = FocussedStyle.CheckedHoveredImage;
FocussedStyle.UndeterminedImage = FocussedStyle.UndeterminedHoveredImage;
return MyCheckbox.ToSharedRef();
}
void UFocusableCheckBox::SlateHandleFocusReceived()

View File

@ -51,4 +51,11 @@ protected:
void SlateHandleUnhovered();
virtual TSharedRef<SWidget> RebuildWidget() override;
/// Update the focussed style based on changes made to the default widget style.
/// Call this if you make runtime changes to the base style of this button.
/// Needed because we can't override SetStyle
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void RefreshFocussedStyle();
};

View File

@ -55,5 +55,14 @@ protected:
void SlateHandleUnhovered();
virtual TSharedRef<SWidget> RebuildWidget() override;
public:
/// Update the focussed style based on changes made to the default widget style.
/// Call this if you make runtime changes to the base style of this checkbox.
/// Needed because we can't override SetStyle
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void RefreshFocussedStyle();
};