Skip to content

Commit

Permalink
added setting to resize window
Browse files Browse the repository at this point in the history
  • Loading branch information
pasotee committed Sep 24, 2023
1 parent 9e69ef0 commit 1ad1a7a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
11 changes: 11 additions & 0 deletions Source/SpotlightSearch/Private/QuickMenuSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ const TArray<FString>& UQuickMenuSettings::GetRecentCommands() const
return RecentCommands;
}

void UQuickMenuSettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);

const FName PropertyName = PropertyChangedEvent.Property ? PropertyChangedEvent.MemberProperty->GetFName() : NAME_None;
if (PropertyName == GET_MEMBER_NAME_CHECKED(UQuickMenuSettings, WindowSize))
{
OnWindowSizeChanged.Broadcast(WindowSize);
}
}

FName UQuickMenuSettings::GetContainerName() const
{
return TEXT("Editor");
Expand Down
11 changes: 10 additions & 1 deletion Source/SpotlightSearch/Private/QuickMenuSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class QUICKMENU_API UQuickMenuSettings : public UDeveloperSettings
*/
UPROPERTY(EditAnywhere, Category = Customization, config, meta = (UIMin = "0.0", UIMax = "100.0"))
float FuzzySearchMatchPercentage = 75.0f;
/**
* @brief Matching percentage required for an entry to show up as a fuzzy search.
*/
UPROPERTY(EditAnywhere, Category = Customization, config)
FVector2D WindowSize = FVector2D(680.f, 430.f);
/**
* @brief Registers a command on top of the Recent Commands list and saves the config.
* @param CommandName Unique name used to identify the command that was executed
Expand All @@ -46,7 +51,10 @@ class QUICKMENU_API UQuickMenuSettings : public UDeveloperSettings
* @return Ordered list of the most recent ran commands
*/
const TArray<FString>& GetRecentCommands() const;

/**
* @brief Callback executed when the WindowSize property is changed
*/
TMulticastDelegate<void(FVector2D NewSize)> OnWindowSizeChanged;
protected:
/**
* @brief Recently executed commands
Expand All @@ -62,6 +70,7 @@ class QUICKMENU_API UQuickMenuSettings : public UDeveloperSettings

private:
// Begin UDeveloperSettings interface
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
virtual FName GetContainerName() const override;
virtual FName GetCategoryName() const override;
virtual FName GetSectionName() const override;
Expand Down
23 changes: 21 additions & 2 deletions Source/SpotlightSearch/Private/SQuickMenuWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "QuickMenuHelpers.h"
#include "QuickMenuSettings.h"
#include "QuickMenuStyle.h"
#include "HAL/PlatformApplicationMisc.h"

#define LOCTEXT_NAMESPACE "FQuickMenuModule"

Expand All @@ -23,12 +24,13 @@ namespace

void SQuickMenuWindow::Construct(const FArguments& InArgs)
{
UQuickMenuSettings* Settings = GetMutableDefault<UQuickMenuSettings>();

// clang-format off
SWindow::Construct(SWindow::FArguments()
.Style(&FAppStyle::Get().GetWidgetStyle<FWindowStyle>("NotificationWindow"))
.CreateTitleBar(false)
.SizingRule(ESizingRule::FixedSize)
.ClientSize(FVector2D(680.f, 430.f))
.ClientSize(Settings->WindowSize)
.SupportsMaximize(false)
.SupportsMinimize(false)
.IsPopupWindow(true)
Expand Down Expand Up @@ -99,6 +101,8 @@ void SQuickMenuWindow::Construct(const FArguments& InArgs)
]);
// clang-format on

Settings->OnWindowSizeChanged.AddSP(this, &SQuickMenuWindow::OnWindowSizeSettingsChanged);

RegisterActiveTimer(0.0f, FWidgetActiveTimerDelegate::CreateSP(this, &SQuickMenuWindow::SetFocusPostConstruct));
}

Expand Down Expand Up @@ -220,6 +224,21 @@ void SQuickMenuWindow::GetRecentCommands(TArray<FQuickMenuItem>& AvailableAction
}
}

void SQuickMenuWindow::OnWindowSizeSettingsChanged(FVector2D NewSize)
{
const float DPIScale = FPlatformApplicationMisc::GetDPIScaleFactorAtPoint(0, 0);
const FVector2D ScaledSize = GetWindowSizeFromClientSize(NewSize * DPIScale, DPIScale);
Resize(ScaledSize);

const FSlateRect AutoCenterRect = FSlateApplicationBase::Get().GetPreferredWorkArea();

const FVector2D DisplayTopLeft( AutoCenterRect.Left, AutoCenterRect.Top );
const FVector2D DisplaySize( AutoCenterRect.Right - AutoCenterRect.Left, AutoCenterRect.Bottom - AutoCenterRect.Top );

const FVector2D ScreenCenter = DisplayTopLeft + (DisplaySize - ScaledSize) * 0.5f;
MoveWindowTo(ScreenCenter);
}

void SQuickMenuWindow::GetAbbreviationsCommands(TArray<FQuickMenuItem>& AvailableActions, TArray<FQuickMenuItem>& OutResult, const FString& FilterText)
{
for (auto It = AvailableActions.CreateIterator(); It; ++It)
Expand Down
4 changes: 4 additions & 0 deletions Source/SpotlightSearch/Private/SQuickMenuWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class SQuickMenuWindow : public SWindow
* @param OutResult Output list we will add the matching commands to
*/
void GetRecentCommands(TArray<FQuickMenuItem>& AvailableActions, TArray<FQuickMenuItem>& OutResult);
/**
* Callback executed when the QuickMenu settings -> WindowSize property is changed
*/
void OnWindowSizeSettingsChanged(FVector2D NewSize);
/**
* @brief Filters out the commands with matching abbreviations from AvailableActions and constructs a list of them in OutResult
* @param AvailableActions Input list we will remove the matching commands from
Expand Down
1 change: 1 addition & 0 deletions Source/SpotlightSearch/QuickMenu.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public QuickMenu(ReadOnlyTargetRules Target) : base(Target)
});

PrivateDependencyModuleNames.AddRange(new string[] {
"ApplicationCore",
"CoreUObject",
"DeveloperSettings",
"EditorStyle",
Expand Down

0 comments on commit 1ad1a7a

Please sign in to comment.