Files
UnrealEngineUWP/Engine/Source/Editor/TranslationEditor/Private/TranslationPickerWidget.cpp
Joe Conley f73acb7852 Translation Picker:
- Improve picking of text in slate widgets that are hittest invisible by searching recursively all children of the deepest widget returned by the hittest.
- Added scrolling support to accomodate the large number of texts this may return as a result in some cases.
- Changes in the layout to make fields easier to read.

[CL 2518631 by Joe Conley in Main branch]
2015-04-20 21:16:03 -04:00

148 lines
4.1 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "TranslationEditorPrivatePCH.h"
#include "TranslationPickerWidget.h"
#include "TranslationPickerEditWindow.h"
#define LOCTEXT_NAMESPACE "TranslationPicker"
void STranslationWidgetPicker::Construct(const FArguments& InArgs)
{
// Mimicking a toolbar button look
// Icon for the picker widget button
TSharedRef< SWidget > IconWidget =
SNew(SImage)
.Image(FEditorStyle::GetBrush("TranslationEditor.TranslationPicker"));
// Style settings
FName StyleSet = FEditorStyle::GetStyleSetName();
FName StyleName = "Toolbar";
FText ToolTip = LOCTEXT("TranslationPickerTooltip", "Open the Translation Picker");
// Create the content for our button
TSharedRef< SWidget > ButtonContent =
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.FillWidth(1)
.VAlign(VAlign_Center)
[
SNew(SVerticalBox)
// Icon image
+ SVerticalBox::Slot()
.AutoHeight()
.HAlign(HAlign_Center) // Center the icon horizontally, so that large labels don't stretch out the artwork
[
IconWidget
]
// Label text
+ SVerticalBox::Slot().AutoHeight()
.HAlign(HAlign_Center) // Center the label text horizontally
[
SNew(STextBlock)
.Text(LOCTEXT("TranslationPicker", "Translation Picker"))
.TextStyle(FEditorStyle::Get(), FName("ToolBar.Label")) // Smaller font for tool tip labels
.ShadowOffset(FVector2D::UnitVector)
]
];
FName CheckboxStyle = ISlateStyle::Join(StyleName, ".SToolBarButtonBlock.CheckBox.Padding");
ChildSlot
[
// Create a check box
SNew(SCheckBox)
// Use the tool bar style for this check box
.Style(FEditorStyle::Get(), "ToolBar.ToggleButton")
// User will have set the focusable attribute for the block, honor it
.IsFocusable(false)
// Pass along the block's tool-tip string
.ToolTip(SNew(SToolTip).Text(ToolTip))
[
ButtonContent
]
// Bind the button's "on checked" event to our object's method for this
.OnCheckStateChanged(this, &STranslationWidgetPicker::OnCheckStateChanged)
// Bind the check box's "checked" state to our user interface action
.IsChecked(this, &STranslationWidgetPicker::IsChecked)
.Padding(FEditorStyle::Get().GetMargin(CheckboxStyle))
];
}
ECheckBoxState STranslationWidgetPicker::IsChecked() const
{
return TranslationPickerManager::IsPickerWindowOpen() ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
}
void STranslationWidgetPicker::OnCheckStateChanged(const ECheckBoxState NewCheckedState)
{
if (TranslationPickerManager::IsPickerWindowOpen())
{
TranslationPickerManager::ClosePickerWindow();
}
else
{
TranslationPickerManager::OpenPickerWindow();
}
}
TSharedPtr<SWindow> TranslationPickerManager::PickerWindow = TSharedPtr<SWindow>();
TSharedPtr<STranslationPickerFloatingWindow> TranslationPickerManager::PickerWindowWidget = TSharedPtr<STranslationPickerFloatingWindow>();
bool TranslationPickerManager::OpenPickerWindow()
{
// Not picking previously, launch a picker window
if (!PickerWindow.IsValid())
{
TSharedRef<SWindow> NewWindow = SWindow::MakeCursorDecorator();
NewWindow->SetSizingRule(ESizingRule::FixedSize);
// The Edit window and Floating window should be roughly the same size, so it isn't too distracting switching between them
NewWindow->Resize(FVector2D(STranslationPickerEditWindow::DefaultEditWindowWidth, STranslationPickerEditWindow::DefaultEditWindowHeight));
NewWindow->MoveWindowTo(FSlateApplication::Get().GetCursorPos());
PickerWindow = NewWindow;
NewWindow->SetContent(
SAssignNew(PickerWindowWidget, STranslationPickerFloatingWindow)
.ParentWindow(NewWindow)
);
TSharedPtr<SWindow> RootWindow = FGlobalTabmanager::Get()->GetRootWindow();
if (RootWindow.IsValid())
{
FSlateApplication::Get().AddWindowAsNativeChild(NewWindow, RootWindow.ToSharedRef());
}
else
{
FSlateApplication::Get().AddWindow(NewWindow);
}
return true;
}
return false;
}
void TranslationPickerManager::ClosePickerWindow()
{
if (FSlateApplication::IsInitialized())
{
FSlateApplication::Get().RequestDestroyWindow(PickerWindow.ToSharedRef());
}
PickerWindow.Reset();
PickerWindowWidget.Reset();
}
#undef LOCTEXT_NAMESPACE