Created
May 19, 2022 16:03
-
-
Save Philtherage/d4ddd38fc9df9c961f7c64dfefc3a1fa to your computer and use it in GitHub Desktop.
Server Row Selection In C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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