Skip to content

Commit f436b70

Browse files
committed
SlateTextRun
1 parent 99d7a91 commit f436b70

File tree

5 files changed

+113
-27
lines changed

5 files changed

+113
-27
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "JavascriptUMG.h"
2+
#include "JavascriptTextModel.h"
3+
4+
void UJavascriptTextModel::SetString(const FString& String)
5+
{
6+
if (!Model.IsValid())
7+
{
8+
Model = MakeShareable(new FString());
9+
}
10+
11+
*(Model.Get()) = String;
12+
}
13+
14+
FString UJavascriptTextModel::GetString()
15+
{
16+
if (!Model.IsValid())
17+
{
18+
return TEXT("");
19+
}
20+
21+
return *(Model.Get());
22+
}
23+
24+
FJavascriptSlateTextRun UJavascriptTextModel::CreateRun(const FTextBlockStyle& MessageTextStyle, int32 BeginIndex, int32 EndIndex)
25+
{
26+
FJavascriptSlateTextRun Run;
27+
28+
if (Model.IsValid())
29+
{
30+
Run.Run = FSlateTextRun::Create(FRunInfo(), Model.ToSharedRef(), MessageTextStyle, FTextRange(BeginIndex, EndIndex));
31+
}
32+
33+
return Run;
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "JavascriptTextModel.generated.h"
4+
5+
USTRUCT()
6+
struct FJavascriptSlateTextRun
7+
{
8+
GENERATED_BODY()
9+
10+
TSharedPtr<IRun> Run;
11+
};
12+
13+
14+
UCLASS()
15+
class JAVASCRIPTUMG_API UJavascriptTextModel : public UObject
16+
{
17+
GENERATED_BODY()
18+
19+
public:
20+
TSharedPtr<FString> Model;
21+
22+
UFUNCTION(BlueprintCallable, Category = "Scripting | Javascript")
23+
void SetString(const FString& String);
24+
25+
UFUNCTION(BlueprintCallable, Category = "Scripting | Javascript")
26+
FString GetString();
27+
28+
UFUNCTION(BlueprintCallable, Category = "Scripting | Javascript")
29+
FJavascriptSlateTextRun CreateRun(const FTextBlockStyle& MessageTextStyle, int32 BeginIndex, int32 EndIndex);
30+
};

Plugins/UnrealJS/Source/JavascriptUMG/JavascriptUMGBlueprintLibrary.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "JavascriptUMG.h"
22
#include "JavascriptUMGBlueprintLibrary.h"
3+
#include "JavascriptTextModel.h"
34

45
FSlateColor UJavascriptUMGBlueprintLibrary::SlateColor_UseForeground()
56
{
@@ -42,12 +43,19 @@ void UJavascriptUMGBlueprintLibrary::ClearLines(UPARAM(ref) FJavascriptTextLayou
4243
TextLayout.TextLayout->ClearLines();
4344
}
4445

45-
void UJavascriptUMGBlueprintLibrary::AddLine(UPARAM(ref) FJavascriptTextLayout& TextLayout, const FString& String, const FTextBlockStyle& MessageTextStyle)
46+
void UJavascriptUMGBlueprintLibrary::AddLine(UPARAM(ref) FJavascriptTextLayout& TextLayout, UJavascriptTextModel* Model, const TArray<FJavascriptSlateTextRun>& InRuns)
4647
{
47-
TSharedRef<FString> LineText(new FString(String));
48-
4948
TArray<TSharedRef<IRun>> Runs;
50-
Runs.Add(FSlateTextRun::Create(FRunInfo(), LineText, MessageTextStyle));
51-
52-
TextLayout.TextLayout->AddLine(LineText, Runs);
53-
}
49+
for (auto InRun : InRuns)
50+
{
51+
if (InRun.Run.IsValid())
52+
{
53+
Runs.Add(InRun.Run.ToSharedRef());
54+
}
55+
}
56+
57+
if (Model && Model->Model.IsValid())
58+
{
59+
TextLayout.TextLayout->AddLine(Model->Model.ToSharedRef(), Runs);
60+
}
61+
}

Plugins/UnrealJS/Source/JavascriptUMG/JavascriptUMGBlueprintLibrary.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "JavascriptMultiLineEditableTextBox.h"
44
#include "JavascriptUMGBlueprintLibrary.generated.h"
55

6+
class UJavascriptTextModel;
7+
68
/**
79
*
810
*/
@@ -28,5 +30,5 @@ class JAVASCRIPTUMG_API UJavascriptUMGBlueprintLibrary : public UBlueprintFuncti
2830
static void ClearLines(UPARAM(ref) FJavascriptTextLayout& TextLayout);
2931

3032
UFUNCTION(BlueprintCallable, Category = "Scripting | Javascript")
31-
static void AddLine(UPARAM(ref) FJavascriptTextLayout& TextLayout, const FString& String, const FTextBlockStyle& TextBlockStyle);
33+
static void AddLine(UPARAM(ref) FJavascriptTextLayout& TextLayout, UJavascriptTextModel* Model, const TArray<FJavascriptSlateTextRun>& Runs);
3234
};

Plugins/UnrealJS/Source/V8/Private/JavascriptIsolate_Private.cpp

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -377,32 +377,44 @@ class FJavascriptIsolateImplementation : public FJavascriptIsolate
377377
auto Function = *FuncIt;
378378
TFieldIterator<UProperty> It(Function);
379379

380-
// It should be a static function and have first argument to bind with.
381-
if ((Function->FunctionFlags & FUNC_Static) && It && (It->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm)
380+
// It should be a static function
381+
if ((Function->FunctionFlags & FUNC_Static) && It)
382382
{
383-
// The first argument should be type of object
384-
if (auto p = Cast<UObjectPropertyBase>(*It))
383+
// and have first argument to bind with.
384+
if ((It->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == CPF_Parm)
385385
{
386-
auto TargetClass = p->PropertyClass;
386+
// The first argument should be type of object
387+
if (auto p = Cast<UObjectPropertyBase>(*It))
388+
{
389+
auto TargetClass = p->PropertyClass;
390+
391+
// GetWorld() may fail and crash, so target class is bound to UWorld
392+
if (TargetClass == UObject::StaticClass() && (p->GetName() == TEXT("WorldContextObject") || p->GetName() == TEXT("WorldContext")))
393+
{
394+
TargetClass = UWorld::StaticClass();
395+
}
387396

388-
// GetWorld() may fail and crash, so target class is bound to UWorld
389-
if (TargetClass == UObject::StaticClass() && (p->GetName() == TEXT("WorldContextObject") || p->GetName() == TEXT("WorldContext")))
397+
BlueprintFunctionLibraryMapping.Add(TargetClass, Function);
398+
continue;
399+
}
400+
else if (auto p = Cast<UStructProperty>(*It))
390401
{
391-
TargetClass = UWorld::StaticClass();
402+
BlueprintFunctionLibraryMapping.Add(p->Struct, Function);
403+
continue;
392404
}
393-
394-
BlueprintFunctionLibraryMapping.Add(TargetClass, Function);
395-
}
396-
else if (auto p = Cast<UStructProperty>(*It))
397-
{
398-
BlueprintFunctionLibraryMapping.Add(p->Struct, Function);
399405
}
400-
}
401-
else if ((Function->FunctionFlags & FUNC_Static) && It && (It->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == (CPF_Parm | CPF_ReturnParm))
402-
{
403-
if (auto p = Cast<UStructProperty>(*It))
406+
407+
// Factory function?
408+
for (auto It2 = It; It2; ++It2)
404409
{
405-
BlueprintFunctionLibraryFactoryMapping.Add(p->Struct, Function);
410+
if ((It2->PropertyFlags & (CPF_Parm | CPF_ReturnParm)) == (CPF_Parm | CPF_ReturnParm))
411+
{
412+
if (auto p = Cast<UStructProperty>(*It2))
413+
{
414+
BlueprintFunctionLibraryFactoryMapping.Add(p->Struct, Function);
415+
break;
416+
}
417+
}
406418
}
407419
}
408420
}

0 commit comments

Comments
 (0)