0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WidgetInteractionでホバーしているWidgetがスクロール可能か調べる

0
Posted at

UWidgetInteractionComponentでホバーしているWidgetがスクロール可能な状態か調べるコードを試してみたのでメモしておきます。

試した環境

  • UnrealEngine 5.6.1

試したコード

以下のようなコードでスクロール可能な状態か判定できそうです。
Build.csのModuleにはUMG、Slate、SlateCoreを追加してみています。

bool UWidgetHelperUtils::IsHoveringScrollableWidget(const UWidgetInteractionComponent* InteractionComponent)
{
	if (!InteractionComponent)
	{
		return false;
	}

	const FWeakWidgetPath& HoveredPath = InteractionComponent->GetHoveredWidgetPath();

	if (!HoveredPath.IsValid())
	{
		return false;
	}

	for (int32 i = HoveredPath.Widgets.Num() - 1; i >= 0; --i)
	{
		TSharedPtr<SWidget> Widget = HoveredPath.Widgets[i].Pin();
		FName WidgetType = Widget->GetType();
		FString WidgetTypeString = WidgetType.ToString();


		if (WidgetType == "SScrollBox")
		{
			TSharedRef<SScrollBox> ScrollBox = StaticCastSharedRef<SScrollBox>(Widget.ToSharedRef());

			return ScrollBox->GetScrollOffsetOfEnd() > 0.0f;
		}

		if (WidgetType == "SListView" ||
			WidgetType == "STileView" ||
			WidgetType == "STreeView" ||
			WidgetTypeString.StartsWith("ListViewT") ||
			WidgetTypeString.StartsWith("TreeViewT") ||
			WidgetTypeString.StartsWith("TileViewT"))
		{
			return Widget->GetDesiredSize().Y > Widget->GetTickSpaceGeometry().GetLocalSize().Y;
		}
	}

	return false;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?