You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
Adding image support to tutorial rich text
Improved text layout support when inserting runs/text or splitting lines on runs that were non-text (images or widgets). The text layout now inserts an extra text run when splitting a non-text run, which avoids issues where text was either being inserted into a non-text run (and vanishing), or an image run was being cloned (and appearing twice). This also fixes the cursor movement in the multiline editable text when selecting over images or widgets (the cursor would jump to the start of the document as GetTextIndexAt hadn't been implemented. Additionally, it also fixes an issue where Measure was always trying to place the cursor at the end of an image run (ignoring the values of BeginIndex and EndIndex) which made the cursor offset draw in the wrong place. These changes required the text layout to be able to create a default text run, which involved refactoring the text marshallers as the Slate text run now knows about the default text style, taking that responsibility away from the marshallers Added tutorial-specific image decorator that accepts a content-relative or engine relative image path. Added button to tutorial rich text editor to add new images. All previously-imported images should still 'work'. reviewed by Jamie.Dale,Nick.Atamas,Justin.Sargent [CL 2302278 by Thomas Sarkanen in Main branch]
This commit is contained in:
committed by
UnrealBot
parent
3d978c4fae
commit
6f1d963577
@@ -4,6 +4,8 @@
|
||||
#include "STutorialEditableText.h"
|
||||
#include "RichTextLayoutMarshaller.h"
|
||||
#include "TutorialText.h"
|
||||
#include "TutorialImageDecorator.h"
|
||||
#include "DesktopPlatformModule.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "STutorialEditableText"
|
||||
|
||||
@@ -27,8 +29,7 @@ void STutorialEditableText::Construct(const FArguments& InArgs)
|
||||
|
||||
TSharedRef<FRichTextLayoutMarshaller> RichTextMarshaller = FRichTextLayoutMarshaller::Create(
|
||||
TArray<TSharedRef<ITextDecorator>>(),
|
||||
&FEditorStyle::Get(),
|
||||
FEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("Tutorials.Content.Text")
|
||||
&FEditorStyle::Get()
|
||||
);
|
||||
|
||||
|
||||
@@ -236,6 +237,22 @@ void STutorialEditableText::Construct(const FArguments& InArgs)
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
+SHorizontalBox::Slot()
|
||||
.Padding(FMargin(4.0f, 0.0f, 0.0f, 0.0f))
|
||||
.AutoWidth()
|
||||
[
|
||||
SNew(SButton)
|
||||
.ToolTipText(LOCTEXT("ImageButtonTooltip", "Insert Image"))
|
||||
.ButtonStyle(FEditorStyle::Get(), "TutorialEditableText.Toolbar.Button")
|
||||
.OnClicked(this, &STutorialEditableText::HandleImageButtonClicked)
|
||||
.ContentPadding(1.0f)
|
||||
.Content()
|
||||
[
|
||||
SNew(SImage)
|
||||
.Image(FEditorStyle::Get().GetBrush("TutorialEditableText.Toolbar.ImageImage"))
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -547,4 +564,51 @@ EVisibility STutorialEditableText::GetExcerptVisibility() const
|
||||
return CurrentHyperlinkType.IsValid() && CurrentHyperlinkType->Type == EHyperlinkType::UDN ? EVisibility::Visible : EVisibility::Collapsed;
|
||||
}
|
||||
|
||||
FReply STutorialEditableText::HandleImageButtonClicked()
|
||||
{
|
||||
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
|
||||
if ( DesktopPlatform )
|
||||
{
|
||||
TArray<FString> OutFiles;
|
||||
const FString Extension(TEXT("png"));
|
||||
const FString Filter = FString::Printf(TEXT("%s files (*.%s)|*.%s"), *Extension, *Extension, *Extension);
|
||||
const FString DefaultPath = FEditorDirectories::Get().GetLastDirectory(ELastDirectory::GENERIC_IMPORT);
|
||||
|
||||
TSharedPtr<SWindow> ParentWindow = FSlateApplication::Get().FindWidgetWindow(AsShared());
|
||||
void* ParentWindowHandle = (ParentWindow.IsValid() && ParentWindow->GetNativeWindow().IsValid()) ? ParentWindow->GetNativeWindow()->GetOSWindowHandle() : nullptr;
|
||||
|
||||
if (DesktopPlatform->OpenFileDialog(ParentWindowHandle, FText::Format(LOCTEXT("ImagePickerDialogTitle", "Choose a {0} file"), FText::FromString(Extension)).ToString(), DefaultPath, TEXT(""), Filter, EFileDialogFlags::None, OutFiles))
|
||||
{
|
||||
check(OutFiles.Num() == 1);
|
||||
|
||||
FRunInfo RunInfo(TEXT("img"));
|
||||
|
||||
// the path to the image needs to be stored either as a 'long package name' version of itself
|
||||
// (minus png extension) or as a literal (base dir relative) path.
|
||||
FString ContentPath;
|
||||
if(FPackageName::TryConvertFilenameToLongPackageName(OutFiles[0], ContentPath))
|
||||
{
|
||||
RunInfo.MetaData.Add(TEXT("src"), ContentPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
RunInfo.MetaData.Add(TEXT("src"), OutFiles[0]);
|
||||
}
|
||||
|
||||
TSharedRef<FSlateImageRun> ImageRun = FSlateImageRun::Create(
|
||||
RunInfo,
|
||||
MakeShareable(new FString(TEXT("\x200B"))), // Zero-Width Breaking Space
|
||||
FName(*FTutorialImageDecorator::GetPathToImage(OutFiles[0])),
|
||||
0
|
||||
);
|
||||
|
||||
RichEditableTextBox->InsertRunAtCursor(ImageRun);
|
||||
|
||||
FEditorDirectories::Get().SetLastDirectory(ELastDirectory::GENERIC_IMPORT, FPaths::GetPath(OutFiles[0]));
|
||||
}
|
||||
}
|
||||
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
Reference in New Issue
Block a user