Skip to content

Commit

Permalink
Fixed hover is flickering for 2D widget: simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSeliv committed Jun 4, 2023
1 parent 5d6e0fa commit 1e57288
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
29 changes: 1 addition & 28 deletions Source/CustomShapeButton/Private/SCustomShapeButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ void SCustomShapeButton::SetCanHover(bool bAllow)
TryDetectOnHovered();
}

void SCustomShapeButton::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
SButton::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);

TickDetectMouseLeave(InDeltaTime);
}

FReply SCustomShapeButton::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
UpdateMouseData(MyGeometry, MouseEvent);
Expand Down Expand Up @@ -103,10 +96,7 @@ void SCustomShapeButton::OnMouseLeave(const FPointerEvent& MouseEvent)
{
SButton::OnMouseLeave(MouseEvent);

if (!IsAlphaPixelHovered())
{
SetCanHover(false);
}
SetCanHover(false);
}

void SCustomShapeButton::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
Expand Down Expand Up @@ -210,23 +200,6 @@ void SCustomShapeButton::TryUpdateRawColorsOnce()
});
}

// Try register leaving the button (e.g. another widget opens above)
void SCustomShapeButton::TickDetectMouseLeave(float DeltaTime)
{
if (bCanHover
&& CurrentGeometry.GetLocalSize().IsZero())
{
// Current data is zero, so widget is not hovered anymore
OnMouseLeave(CurrentMouseEvent);
}

// Reset data every tick, it will actualised during OnMouseMove
// so if data is empty, then Mouse Move did not happen
// and widget is not hovered anymore
static const FGeometry EmptyGeometry{};
CurrentGeometry = EmptyGeometry;
}

// Try register On Hovered and On Unhovered events
void SCustomShapeButton::TryDetectOnHovered()
{
Expand Down
4 changes: 0 additions & 4 deletions Source/CustomShapeButton/Public/SCustomShapeButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class CUSTOMSHAPEBUTTON_API SCustomShapeButton : public SButton
/** Contains cached information about the mouse event. */
FPointerEvent CurrentMouseEvent;

virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
Expand All @@ -52,9 +51,6 @@ class CUSTOMSHAPEBUTTON_API SCustomShapeButton : public SButton
/** Set once on render thread the buffer data about all pixels of current texture if was not set before. */
virtual void TryUpdateRawColorsOnce();

/** Try register leaving the button (e.g. another widget opens above). */
virtual void TickDetectMouseLeave(float DeltaTime);

/** Try register On Hovered and On Unhovered events. */
virtual void TryDetectOnHovered();

Expand Down

0 comments on commit 1e57288

Please sign in to comment.