UE4 自定义widget

B站教学链接:https://space.bilibili.com/449549424?spm_id_from=333.1007.0.0


一、前言

    Slate是虚幻引擎的自定义UI编程框架。编辑器的大部分界面都是使用 Slate 构建的。UMG也是基于Slate的。

     所有的Slate部件都继承自SWidget,SWidget继承自FSlateControlledConstruction和TSharedFromThis。SWidget分为SCompoundWidget、SEditableText、SLeafWidget、SMultiLineEditableText、SPanel、SRichTextBlock、SWeakWidget。

二、虚幻继承的基类

  在用C++写UMG的时候,我们会继承自UUserWidget做一个自己的基类来写,在Slate中,我们通常会根据插槽来判断继承的父类,Slot概念很重要, 插槽就是说我们在他(控件)下面可以添加多少个子控件,下面有三个我们写Slate会经常继承的类。

    2.1基类:SUserWidget或者是SCompoundWidget

      单个Slot的类,单个插槽。SUserWidget 或者 SCompoundWidget有一个插槽,固定一个 比如 SCheckBox,SButton, SBox,SUserWidget是继承自SCompoundWidget,这两个我们都可以继承,引擎更多的是继承自SCompoundWidget。其实引擎推荐我们自己写的单个插槽类的时候是继承自SUserWidget。

   2.2基类:SPanel

     多个Slot的类,多个插槽。SPanel: 多个插槽 比如SVerticalBox, SHorizontalBox,SScrollBox,可以添加多个控件按钮。

   2..3基类:SLeafWidget

   没有插槽,比如STextBlock

三、SNew和SAssignNew

如果我们要新建一个Button,分别用SNew和SAssignNew

TSharedRef<SButton> MyButton = SNew(SButton);

TSharedPtr<SButton> MyButton;
SAssignNew( MyButton, SButton );

两者之间的区别在于:

SNew:
1.返回值不同:返回共享引用
SAssignNew:
1.返回值不同:返回共享指针
2.使用方式不同:链式编程中直接获取值,直接赋值,在链式编程中想获取值就用SAssignNew

四、函数介绍

TSharedPtr<STextBlock> MyTextBlock;

  4.1 RebuildWidget() :重新构建widget,生成我们所需要的widget

if (bWrapWithInvalidationPanel && !IsDesignTime())
	{
		TSharedPtr<SWidget> RetWidget = SNew(SInvalidationPanel)
			[
				SAssignNew(MyTextBlock, STextBlock)
			];
		return RetWidget.ToSharedRef();
	}
	else
	{
		MyTextBlock = SNew(STextBlock);
		return MyTextBlock.ToSharedRef();

	}

	MyTextBlock = SNew(STextBlock);
	return MyTextBlock.ToSharedRef();

  4.2 SynchronizeProperties():编译时会调用该函数,使得属性能够同步到UI控件上。

Super::SynchronizeProperties();
	if (IsValid(UGameplayStatics::GetGameInstance(this)))//判断GameInstance是否有效
	{
		UEditorGameInstance* ins = Cast<UEditorGameInstance>(UGameplayStatics::GetGameInstance(this));//将自身添加到UCEditorGameInstance中的text列表
		ins->EditorTextList.Add(this);
	}
	


		//UKismetSystemLibrary::PrintString(this, FString(TEXT("创建")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);

	//	TAttribute<FText> TextBinding = OPTIONAL_BINDING(FText, Text); //委托属性,委托变量的名字是 名称+Delegate
	TAttribute<FSlateColor> ColorAndOpacityBinding = OPTIONAL_BINDING(FSlateColor, ColorAndOpacity);
	TAttribute<FLinearColor> ShadowColorAndOpacityBinding = OPTIONAL_BINDING(FLinearColor, ShadowColorAndOpacity);

	if (MyTextBlock.IsValid())
	{

		if (!NoTranslation)
		{
			MyTextBlock->SetText(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(Text.ToString(), this)));
		}
		else
		{
			MyTextBlock->SetText(Text);
		}

		MyTextBlock->SetFont(Font);
		if (OpenSystemColor)
		{
			if (AntiSystemColor)
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextAntiColor(ColorAndOpacityBinding.Get(), this));
			}
			else
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextColor(ColorAndOpacityBinding.Get(), this));
			}
		}
		else
		{
			MyTextBlock->SetColorAndOpacity(ColorAndOpacityBinding);
		}
		MyTextBlock->SetShadowOffset(ShadowOffset);
		MyTextBlock->SetShadowColorAndOpacity(ShadowColorAndOpacityBinding);
		MyTextBlock->SetMinDesiredWidth(MinDesiredWidth);

		Super::SynchronizeTextLayoutProperties(*MyTextBlock);
	}

   4.3 ReleaseSlateResources(bool bReleaseChildren):如果有指向 Slate 控件的智能指针,需要在这里释放,否则可能会导致控件被释放时出现意外的错误

Super::ReleaseSlateResources(bReleaseChildren);

	//

	if (IsValid(GetWorld()))
	{
		if (IsValid(UGameplayStatics::GetGameInstance(this)))
		{
			UEditorGameInstance* ins = Cast<UEditorGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));//
		

		}
	}
	//	UKismetSystemLibrary::PrintString(this, FString(TEXT("移除")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);
	MyTextBlock.Reset();

五、属性介绍

    对于一些其他的属性,比如设置字体,设置颜色,设置大小,设置文本内容都可以通过重写函数来实现。

/**
	* Sets the color and opacity of the text in this text block
	*
	* @param InColorAndOpacity		The new text color and opacity
	*/
		UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetColorAndOpacity(FSlateColor InColorAndOpacity);

	/**
	* Sets the opacity of the text in this text block
	*
	* @param InOpacity		The new text opacity
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetOpacity(float InOpacity);

	/**
	* Sets the color and opacity of the text drop shadow
	* Note: if opacity is zero no shadow will be drawn
	*
	* @param InShadowColorAndOpacity		The new drop shadow color and opacity
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetShadowColorAndOpacity(FLinearColor InShadowColorAndOpacity);

	/**
	* Sets the offset that the text drop shadow should be drawn at
	*
	* @param InShadowOffset		The new offset
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetShadowOffset(FVector2D InShadowOffset);

	/**
	* Dynamically set the font info for this text block
	*
	* @param InFontInfo THe new font info
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetFont(FSlateFontInfo InFontInfo);

	/**
	*  Set the text justification for this text block
	*
	*  @param Justification new justification
	*/


	/** The color of the text */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FSlateColor ColorAndOpacity;

	/** A bindable delegate for the ColorAndOpacity. */
	UPROPERTY()
		FGetSlateColor ColorAndOpacityDelegate;

	/** The font to render the text with */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FSlateFontInfo Font;

	/** The direction the shadow is cast */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FVector2D ShadowOffset;

	/** The color of the shadow */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance, meta = (DisplayName = "Shadow Color"))
		FLinearColor ShadowColorAndOpacity;

	/** A bindable delegate for the ShadowColorAndOpacity. */
	UPROPERTY()
		FGetLinearColor ShadowColorAndOpacityDelegate;

	/** The minimum desired size for the text */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		float MinDesiredWidth;

	/** If true, it will automatically wrap this text widget with an invalidation panel */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Performance, AdvancedDisplay)
		bool bWrapWithInvalidationPanel;

六、案例介绍

  实现自定义一个文本

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Components/TextWidgetTypes.h"
#include "C_TextBox.generated.h"

/**
 * 
 */
UCLASS(meta = (DisplayName = "LabelBlock"))
class RUNTIMEINUE4_API UC_TextBox : public UTextLayoutWidget
{
	GENERATED_UCLASS_BODY()
		/**
	* Sets the color and opacity of the text in this text block
	*
	* @param InColorAndOpacity		The new text color and opacity
	*/
		UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetColorAndOpacity(FSlateColor InColorAndOpacity);

	/**
	* Sets the opacity of the text in this text block
	*
	* @param InOpacity		The new text opacity
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetOpacity(float InOpacity);

	/**
	* Sets the color and opacity of the text drop shadow
	* Note: if opacity is zero no shadow will be drawn
	*
	* @param InShadowColorAndOpacity		The new drop shadow color and opacity
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetShadowColorAndOpacity(FLinearColor InShadowColorAndOpacity);

	/**
	* Sets the offset that the text drop shadow should be drawn at
	*
	* @param InShadowOffset		The new offset
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetShadowOffset(FVector2D InShadowOffset);

	/**
	* Dynamically set the font info for this text block
	*
	* @param InFontInfo THe new font info
	*/
	UFUNCTION(BlueprintCallable, Category = "Appearance")
		void SetFont(FSlateFontInfo InFontInfo);

	/**
	*  Set the text justification for this text block
	*
	*  @param Justification new justification
	*/
	

public:
	/** The text to display */
	UPROPERTY(EditAnywhere, Category = Content, meta = (MultiLine = "true"))
		FText Text;


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Content, meta = (MultiLine = "true"))
		bool OpenSystemColor;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Content, meta = (MultiLine = "true"))
		bool AntiSystemColor;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Content, meta = (MultiLine = "true"))
		bool NoTranslation;

	//	/** A bindable delegate to allow logic to drive the text of the widget */
	//	 UPROPERTY()
	//		FGetText TextDelegate;

		/** The color of the text */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FSlateColor ColorAndOpacity;

	/** A bindable delegate for the ColorAndOpacity. */
	UPROPERTY()
		FGetSlateColor ColorAndOpacityDelegate;

	/** The font to render the text with */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FSlateFontInfo Font;

	/** The direction the shadow is cast */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		FVector2D ShadowOffset;

	/** The color of the shadow */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance, meta = (DisplayName = "Shadow Color"))
		FLinearColor ShadowColorAndOpacity;

	/** A bindable delegate for the ShadowColorAndOpacity. */
	UPROPERTY()
		FGetLinearColor ShadowColorAndOpacityDelegate;

	/** The minimum desired size for the text */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Appearance)
		float MinDesiredWidth;

	/** If true, it will automatically wrap this text widget with an invalidation panel */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Performance, AdvancedDisplay)
		bool bWrapWithInvalidationPanel;

	UFUNCTION(BlueprintCallable, Category = "Widget")
		void UpDateLanguage();

	UFUNCTION(BlueprintCallable, Category = "Widget")
		void UpDateColor();

	///** Called when this text is double clicked */
	//SLATE_EVENT(FOnClicked, OnDoubleClicked)

	/**
	* Gets the widget text
	* @return The widget text
	*/
	UFUNCTION(BlueprintCallable, Category = "Widget", meta = (DisplayName = "GetText (Text)"))
		FText GetText() const;

	/**
	* Directly sets the widget text.
	* Warning: This will wipe any binding created for the Text property!
	* @param InText The text to assign to the widget
	*/
	UFUNCTION(BlueprintCallable, Category = "Widget", meta = (DisplayName = "SetText (Text)"))
		void SetText(FText InText);

	//~ Begin UWidget Interface
	virtual void SynchronizeProperties() override;
	//~ End UWidget Interface

	//~ Begin UVisual Interface
	virtual void ReleaseSlateResources(bool bReleaseChildren) override;

	//~ End UVisual Interface



	virtual void RemoveFromParent()override;

	//	virtual void OnClosed() override;

#if WITH_EDITOR
	//~ Begin UWidget Interface
	virtual const FText GetPaletteCategory() override;
	virtual void OnCreationFromPalette() override;
	//~ End UWidget Interface

	virtual FString GetLabelMetadata() const override;

	void HandleTextCommitted(const FText& InText, ETextCommit::Type CommitteType);

#endif

protected:
	//~ Begin UWidget Interface
	virtual TSharedRef<SWidget> RebuildWidget() override;
	virtual void OnBindingChanged(const FName& Property) override;

protected:

	TSharedPtr<STextBlock> MyTextBlock;
	
};
// Fill out your copyright notice in the Description page of Project Settings.


#include "C_TextBox.h"
#include "EditorGameInstance.h"
#include "UMG.h"
#include "Widgets/SInvalidationPanel.h"
#include "ExtendedFunctionLibrary.h"
#include "UMGStyle.h"

DECLARE_LOG_CATEGORY_EXTERN(LogUMG, Log, All);

#define LOCTEXT_NAMESPACE "UMG"


UC_TextBox::UC_TextBox(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	bIsVariable = false;
	bWrapWithInvalidationPanel = false;
	ShadowOffset = FVector2D(1.0f, 1.0f);
	ColorAndOpacity = FLinearColor::White;
	ShadowColorAndOpacity = FLinearColor::Transparent;

	if (!IsRunningDedicatedServer())
	{
		static ConstructorHelpers::FObjectFinder<UFont> RobotoFontObj(TEXT("/Engine/EngineFonts/Roboto"));
		Font = FSlateFontInfo(RobotoFontObj.Object, 24, FName("Bold"));
	}
}



//void UC_TextBox::RemoveFromParent()
//{
//	Super::RemoveFromParent();
//
//
//}


/*

void UC_TextBox::BeginDestroy()
{
	Super::BeginDestroy();


	if (IsValid(UGameplayStatics::GetGameInstance(this)))//判断GameInstance是否有效
	{
		UCEditorGameInstance* ins = Cast<UCEditorGameInstance>(UGameplayStatics::GetGameInstance(this));//
		ins->EditorTextList.Remove(this);
	}

//	UKismetSystemLibrary::PrintString(this, FString(TEXT("移除")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);

}

*/

//移除事件
void UC_TextBox::ReleaseSlateResources(bool bReleaseChildren)
{
	Super::ReleaseSlateResources(bReleaseChildren);

	//

	if (IsValid(GetWorld()))
	{
		if (IsValid(UGameplayStatics::GetGameInstance(this)))
		{
			UEditorGameInstance* ins = Cast<UEditorGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));//
		

		}
	}
	//	UKismetSystemLibrary::PrintString(this, FString(TEXT("移除")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);
	MyTextBlock.Reset();
}

void UC_TextBox::RemoveFromParent()
{
	Super::RemoveFromParent();
}

void UC_TextBox::SetColorAndOpacity(FSlateColor InColorAndOpacity)
{

	if (OpenSystemColor)
	{
		if (AntiSystemColor)
		{
			ColorAndOpacity = UExtendedFunctionLibrary::GetSystemTextAntiColor(InColorAndOpacity, this);
		}
		else
		{
			ColorAndOpacity = UExtendedFunctionLibrary::GetSystemTextColor(InColorAndOpacity, this);
		}
	}
	else
	{
		ColorAndOpacity = InColorAndOpacity;
	}


	if (MyTextBlock.IsValid())
	{

		if (OpenSystemColor)
		{
			if (AntiSystemColor)
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextAntiColor(InColorAndOpacity, this));
			}
			else
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextColor(InColorAndOpacity, this));
			}
		}
		else
		{
			MyTextBlock->SetColorAndOpacity(InColorAndOpacity);
		}
	}
}

void UC_TextBox::SetOpacity(float InOpacity)
{
	FLinearColor CurrentColor = ColorAndOpacity.GetSpecifiedColor();
	CurrentColor.A = InOpacity;

	SetColorAndOpacity(FSlateColor(CurrentColor));
}

void UC_TextBox::SetShadowColorAndOpacity(FLinearColor InShadowColorAndOpacity)
{
	ShadowColorAndOpacity = InShadowColorAndOpacity;
	if (MyTextBlock.IsValid())
	{
		MyTextBlock->SetShadowColorAndOpacity(InShadowColorAndOpacity);
	}
}

void UC_TextBox::SetShadowOffset(FVector2D InShadowOffset)
{
	ShadowOffset = InShadowOffset;
	if (MyTextBlock.IsValid())
	{
		MyTextBlock->SetShadowOffset(ShadowOffset);
	}
}

void UC_TextBox::SetFont(FSlateFontInfo InFontInfo)
{
	Font = InFontInfo;
	if (MyTextBlock.IsValid())
	{
		MyTextBlock->SetFont(Font);
	}
}


//构建Widget
TSharedRef<SWidget> UC_TextBox::RebuildWidget()
{
	if (bWrapWithInvalidationPanel && !IsDesignTime())
	{
		TSharedPtr<SWidget> RetWidget = SNew(SInvalidationPanel)
			[
				SAssignNew(MyTextBlock, STextBlock)
			];
		return RetWidget.ToSharedRef();
	}
	else
	{
		MyTextBlock = SNew(STextBlock);
		return MyTextBlock.ToSharedRef();

	}

	MyTextBlock = SNew(STextBlock);
	return MyTextBlock.ToSharedRef();
	
}

void UC_TextBox::OnBindingChanged(const FName& Property)
{

	Super::OnBindingChanged(Property);

	//UKismetSystemLibrary::PrintString(this, FString(TEXT("触发OnBindingChanged")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);

	if (MyTextBlock.IsValid())
	{
		//	static const FName TextProperty(TEXT("TextDelegate"));
		static const FName ColorAndOpacityProperty(TEXT("ColorAndOpacityDelegate"));
		static const FName ShadowColorAndOpacityProperty(TEXT("ShadowColorAndOpacityDelegate"));

		/*
		if (Property == TextProperty)
		{
			TAttribute<FText> TextBinding = OPTIONAL_BINDING(FText, Text);
			//MyTextBlock->SetText(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(TextBinding.Get().ToString(), this)));
			MyTextBlock->SetText(TextBinding);
		}
		*/
		if (Property == ColorAndOpacityProperty)
		{
			TAttribute<FSlateColor> ColorAndOpacityBinding = OPTIONAL_BINDING(FSlateColor, ColorAndOpacity);

			if (OpenSystemColor)
			{
				if (AntiSystemColor)
				{
					MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextAntiColor(ColorAndOpacityBinding.Get(), this));
				}
				else
				{
					MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextColor(ColorAndOpacityBinding.Get(), this));
				}
			}
			else
			{
				MyTextBlock->SetColorAndOpacity(ColorAndOpacityBinding);
			}
		}
		else if (Property == ShadowColorAndOpacityProperty)
		{
			TAttribute<FLinearColor> ShadowColorAndOpacityBinding = OPTIONAL_BINDING(FLinearColor, ShadowColorAndOpacity);
			MyTextBlock->SetShadowColorAndOpacity(ShadowColorAndOpacityBinding);
		}
	}


}



void UC_TextBox::UpDateLanguage()
{
	if (!NoTranslation)
	{
		MyTextBlock->SetText(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(Text.ToString(), this)));
	}
}



void UC_TextBox::UpDateColor()
{

	if (OpenSystemColor)
	{
		if (AntiSystemColor)
		{
			MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextAntiColor(ColorAndOpacity, this));
		}
		else
		{
			MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextColor(ColorAndOpacity, this));
		}
	}

}



void UC_TextBox::SynchronizeProperties()
{
	Super::SynchronizeProperties();
	if (IsValid(UGameplayStatics::GetGameInstance(this)))//判断GameInstance是否有效
	{
		UEditorGameInstance* ins = Cast<UEditorGameInstance>(UGameplayStatics::GetGameInstance(this));//将自身添加到UCEditorGameInstance中的text列表
		ins->EditorTextList.Add(this);
	}
	


		//UKismetSystemLibrary::PrintString(this, FString(TEXT("创建")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);

	//	TAttribute<FText> TextBinding = OPTIONAL_BINDING(FText, Text); //委托属性,委托变量的名字是 名称+Delegate
	TAttribute<FSlateColor> ColorAndOpacityBinding = OPTIONAL_BINDING(FSlateColor, ColorAndOpacity);
	TAttribute<FLinearColor> ShadowColorAndOpacityBinding = OPTIONAL_BINDING(FLinearColor, ShadowColorAndOpacity);

	if (MyTextBlock.IsValid())
	{

		if (!NoTranslation)
		{
			MyTextBlock->SetText(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(Text.ToString(), this)));
		}
		else
		{
			MyTextBlock->SetText(Text);
		}

		MyTextBlock->SetFont(Font);
		if (OpenSystemColor)
		{
			if (AntiSystemColor)
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextAntiColor(ColorAndOpacityBinding.Get(), this));
			}
			else
			{
				MyTextBlock->SetColorAndOpacity(UExtendedFunctionLibrary::GetSystemTextColor(ColorAndOpacityBinding.Get(), this));
			}
		}
		else
		{
			MyTextBlock->SetColorAndOpacity(ColorAndOpacityBinding);
		}
		MyTextBlock->SetShadowOffset(ShadowOffset);
		MyTextBlock->SetShadowColorAndOpacity(ShadowColorAndOpacityBinding);
		MyTextBlock->SetMinDesiredWidth(MinDesiredWidth);

		Super::SynchronizeTextLayoutProperties(*MyTextBlock);
	}



}

FText UC_TextBox::GetText() const
{
	/*
	if (MyTextBlock.IsValid())
	{
		return MyTextBlock->GetText();
	}
	*/

	return Text;
}

void UC_TextBox::SetText(FText InText)
{
	Text = InText;
	if (MyTextBlock.IsValid())
	{
		if (!NoTranslation)
		{
			MyTextBlock->SetText(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(Text.ToString(), this)));//(FText::FromString(UExtendedFunctionLibrary::LanguageConversion(Text.ToString(), this)));
		}
		else
		{
			MyTextBlock->SetText(InText);
		}
	}
}

#if WITH_EDITOR

FString UC_TextBox::GetLabelMetadata() const
{
	const int32 MaxSampleLength = 15;

	FString TextStr = Text.ToString();
	TextStr = TextStr.Len() <= MaxSampleLength ? TextStr : TextStr.Left(MaxSampleLength - 2) + TEXT("..");
	return TEXT(" \"") + TextStr + TEXT("\"");
}

void UC_TextBox::HandleTextCommitted(const FText& InText, ETextCommit::Type CommitteType)
{
	//TODO UMG How will this migrate to the template?  Seems to me we need the previews to have access to their templates!
	//TODO UMG How will the user click the editable area?  There is an overlay blocking input so that other widgets don't get them.
	//     Need a way to recognize one particular widget and forward things to them!
}

const FText UC_TextBox::GetPaletteCategory()
{
	return LOCTEXT("Extended", "Extended");
}

void UC_TextBox::OnCreationFromPalette()
{
	Text = LOCTEXT("TextBlockDefaultValue", "Text Block");
}



/*
void UC_TextBox::OnClosed()
{
	Super::OnClosed();
	UKismetSystemLibrary::PrintString(this, FString(TEXT("gb")), true, true, FLinearColor(0.0, 0.66, 1.0), 2.f);

}
*/

#endif

/

#undef LOCTEXT_NAMESPACE

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞起的猪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值