// Copyright Epic Games, Inc. All Rights Reserved. #include "LocateBy.h" #include "Locators/SlateWidgetLocatorByDelegate.h" #include "Locators/SlateWidgetLocatorByPath.h" #include "Locators/WidgetLocatorByFilter.h" #include "AutomationDriverTypeDefs.h" #include "Framework/Application/SlateApplication.h" #include "IApplicationElement.h" TSharedRef By::Delegate(const FLocateSlateWidgetElementDelegate& Value, FStringView DebugName) { return FSlateWidgetLocatorByDelegateFactory::Create(Value, DebugName); } TSharedRef By::Delegate(const FLocateSlateWidgetPathElementDelegate& Value, FStringView DebugName) { return FSlateWidgetLocatorByDelegateFactory::Create(Value, DebugName); } TSharedRef By::WidgetLambda(const TFunction>&)>& Value, FStringView DebugName) { return FSlateWidgetLocatorByDelegateFactory::Create(FLocateSlateWidgetElementDelegate::CreateLambda(Value), DebugName); } TSharedRef By::WidgetPathLambda(const TFunction&)>& Value, FStringView DebugName) { return FSlateWidgetLocatorByDelegateFactory::Create(FLocateSlateWidgetPathElementDelegate::CreateLambda(Value), DebugName); } TSharedRef By::Id(const FString& Value) { return FSlateWidgetLocatorByPathFactory::Create(TEXT("#") + Value); } TSharedRef By::Id(const FDriverElementRef& Root, const FString& Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, TEXT("#") + Value); } TSharedRef By::Id(const FName& Value) { return FSlateWidgetLocatorByPathFactory::Create(TEXT("#") + Value.ToString()); } TSharedRef By::Id(const FDriverElementRef& Root, const FName& Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, TEXT("#") + Value.ToString()); } TSharedRef By::Id(const TCHAR* Value) { return FSlateWidgetLocatorByPathFactory::Create(FString(TEXT("#")) + Value); } TSharedRef By::Id(const FDriverElementRef& Root, const TCHAR* Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, FString(TEXT("#")) + Value); } TSharedRef By::Id(const char* Value) { return FSlateWidgetLocatorByPathFactory::Create(FString(TEXT("#")) + Value); } TSharedRef By::Id(const FDriverElementRef& Root, const char* Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, FString(TEXT("#")) + Value); } TSharedRef By::Path(const FString& Value) { return FSlateWidgetLocatorByPathFactory::Create(Value); } TSharedRef By::Path(const FDriverElementRef& Root, const FString& Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, Value); } TSharedRef By::Path(const FName& Value) { return FSlateWidgetLocatorByPathFactory::Create(Value.ToString()); } TSharedRef By::Path(const FDriverElementRef& Root, const FName& Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, Value.ToString()); } TSharedRef By::Path(const TCHAR* Value) { return FSlateWidgetLocatorByPathFactory::Create(Value); } TSharedRef By::Path(const FDriverElementRef& Root, const TCHAR* Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, Value); } TSharedRef By::Path(const char* Value) { return FSlateWidgetLocatorByPathFactory::Create(Value); } TSharedRef By::Path(const FDriverElementRef& Root, const char* Value) { return FSlateWidgetLocatorByPathFactory::Create(Root, Value); } TSharedRef By::Cursor() { return By::WidgetPathLambda([](TArray& OutWidgetPaths) -> void { TArray> Windows; FSlateApplication::Get().GetAllVisibleWindowsOrdered(Windows); FWidgetPath WidgetPath = FSlateApplication::Get().LocateWindowUnderMouse(FSlateApplication::Get().GetCursorPos(), Windows); if (WidgetPath.IsValid()) { OutWidgetPaths.Add(WidgetPath); } }); } TSharedRef By::KeyboardFocus() { return WidgetLambda([](TArray>& OutWidgets) -> void { if (const TSharedPtr Widget = FSlateApplication::Get().GetKeyboardFocusedWidget()) { OutWidgets.Add(Widget.ToSharedRef()); } }); } TSharedRef By::UserFocus(uint32 UserIndex) { return WidgetLambda([UserIndex](TArray>& OutWidgets) -> void { if (const TSharedPtr Widget = FSlateApplication::Get().GetUserFocusedWidget(UserIndex)) { OutWidgets.Add(Widget.ToSharedRef()); } }); } TSharedRef By::TextFilter::Contains( const FElementLocatorRef& RootLocator, const FString& Value, ESearchCase::Type SearchCase, ESearchDir::Type SearchDir) { return FWidgetLocatorByFilterFactory::Create( TEXT("[By::TextFilter::Contains] ") + Value, RootLocator, [Value, SearchCase, SearchDir](const TSharedRef& Element) { return Element->GetText().ToString().Contains(Value, SearchCase, SearchDir); } ); } TSharedRef By::TextFilter::Equals( const FElementLocatorRef& RootLocator, const FString& Value, ESearchCase::Type SearchCase) { return FWidgetLocatorByFilterFactory::Create( TEXT("[By::TextFilter::Equals] ") + Value, RootLocator, [Value, SearchCase](const TSharedRef& Element) { return Element->GetText().ToString().Equals(Value, SearchCase); } ); }