Skip to content

Instantly share code, notes, and snippets.

@Philtherage
Created May 19, 2022 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Philtherage/d4ddd38fc9df9c961f7c64dfefc3a1fa to your computer and use it in GitHub Desktop.
Save Philtherage/d4ddd38fc9df9c961f7c64dfefc3a1fa to your computer and use it in GitHub Desktop.
Server Row Selection In C++
public:
FORCEINLINE class USessionEntryWidget* GetCurrentSelectedSessionEntry() const
{
return CurrentSelectedEntry;
}
void SetCurrentSelectedSessionEntry(USessionEntryWidget* InEntry);
private:
UPROPERTY()
class USessionEntryWidget* CurrentSelectedEntry = nullptr;
FReply USessionEntryWidget::NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
//Cache the return value of the super.
FReply Reply = Super::NativeOnMouseButtonDown(InGeometry, InMouseEvent);
if(OwningMenu != nullptr && SelectedImage != nullptr && DefaultImage != nullptr && OwningMenu->GetCurrentSelectedSessionEntry() != this)
{
//if we have an entry already selected clear that selection and set our new selection.
if(OwningMenu->GetCurrentSelectedSessionEntry() != nullptr)
{
OwningMenu->GetCurrentSelectedSessionEntry()->Image->SetBrushFromTexture(DefaultImage);
OwningMenu->SetCurrentSelectedSessionEntry(this);
this->Image->SetBrushFromTexture(SelectedImage);
}
//else if no previous selection.
else
{
OwningMenu->SetCurrentSelectedSessionEntry(this);
this->Image->SetBrushFromTexture(SelectedImage);
}
}
return Reply;
}
void USessionEntryWidget::NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
Super::NativeOnMouseEnter(InGeometry, InMouseEvent);
//if the the entry is not selected and we have a hover image set it.
if(OwningMenu->GetCurrentSelectedSessionEntry() != this && HoveredImage != nullptr)
{
Image->SetBrushFromTexture(HoveredImage);
}
}
void USessionEntryWidget::NativeOnMouseLeave(const FPointerEvent& InMouseEvent)
{
Super::NativeOnMouseLeave(InMouseEvent);
//if the the entry is not selected and we have a DefaultImage set it.
if(OwningMenu->GetCurrentSelectedSessionEntry() != this && DefaultImage != nullptr)
{
Image->SetBrushFromTexture(DefaultImage);
}
}
//COMPONENTS
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UTextBlock* SessionNameText = nullptr;
//The Image that you want to update the brush of.
UPROPERTY(BlueprintReadOnly, meta = (BindWidget))
class UBorder* Image = nullptr;
//OVERRIDES
virtual bool Initialize() override;
virtual void NativeConstruct() override;
virtual void NativeDestruct() override;
//Override these functions to handle mouse events
virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
virtual void NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override;
private:
//The Textures you want for each of your entry states.
UPROPERTY(EditDefaultsOnly)
class UTexture2D* DefaultImage = nullptr;
UPROPERTY(EditDefaultsOnly)
class UTexture2D* SelectedImage = nullptr;
UPROPERTY(EditDefaultsOnly)
class UTexture2D* HoveredImage = nullptr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment