Untitled
unknown
c_cpp
a year ago
3.1 kB
3
Indexable
Never
// Copyright (c) 2023 Nick Maleki, Recursion Computing, LLC #pragma once #include "CoreMinimal.h" #include "Components/EditableTextBox.h" #include "Components/MultiLineEditableText.h" #include "Framework/Text/TextLayout.h" #include "MyMultiLineEditableText.generated.h" /** Called when the cursor is moved within the text area */ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnCursorMovedRM, int32, InLineIndex, int32, InOffset); /** * Editable text box widget */ UCLASS(meta=( DisplayName="Hidden Editable Text (Multi-Line)" )) class GATEST3_API UMyMultiLineEditableText : public UMultiLineEditableText { /** Called when the cursor is moved within the text area */ DECLARE_DELEGATE_OneParam( FOnCursorMoved, const FTextLocation& ); GENERATED_BODY() /** Called when the cursor is moved within the text area */ UPROPERTY(BlueprintAssignable) FOnCursorMovedRM OnCursorMoved; virtual TSharedRef<SWidget> RebuildWidget() override; public: void HandleEditableTextCursorMoved(const FTextLocation& NewCursorPosition ) const; UFUNCTION(BlueprintCallable) void InsertTextAtCursor(FString InText) const; UFUNCTION(BlueprintCallable) void MoveCursor(const int& InLineIndex, const int& InOffset); }; #include "MyMultiLineEditableText.h" #include "Widgets/Text/SMultiLineEditableText.h" TSharedRef<SWidget> UMyMultiLineEditableText::RebuildWidget() { MyMultiLineEditableText = SNew(SMultiLineEditableText) .OnCursorMoved(BIND_UOBJECT_DELEGATE(FOnCursorMoved, HandleEditableTextCursorMoved)) .VirtualKeyboardOptions(VirtualKeyboardOptions) .OnTextChanged(BIND_UOBJECT_DELEGATE(FOnTextChanged, HandleOnTextChanged)) .OnTextCommitted(BIND_UOBJECT_DELEGATE(FOnTextCommitted, HandleOnTextCommitted)); MyMultiLineEditableText->SetTextStyle(&WidgetStyle); MyMultiLineEditableText->SetAllowContextMenu(AllowContextMenu); MyMultiLineEditableText->SetIsReadOnly(GetIsReadOnly()); MyMultiLineEditableText->SetSelectAllTextWhenFocused(GetSelectAllTextWhenFocused()); MyMultiLineEditableText->SetClearTextSelectionOnFocusLoss(GetClearTextSelectionOnFocusLoss()); MyMultiLineEditableText->SetRevertTextOnEscape(GetRevertTextOnEscape()); MyMultiLineEditableText->SetClearKeyboardFocusOnCommit(GetClearKeyboardFocusOnCommit()); MyMultiLineEditableText->SetVirtualKeyboardDismissAction(VirtualKeyboardDismissAction); return MyMultiLineEditableText.ToSharedRef(); } void UMyMultiLineEditableText::HandleEditableTextCursorMoved(const FTextLocation& NewCursorPosition) const { OnCursorMoved.Broadcast(NewCursorPosition.GetLineIndex(), NewCursorPosition.GetOffset()); } void UMyMultiLineEditableText::InsertTextAtCursor(const FString InText) const { MyMultiLineEditableText->InsertTextAtCursor(InText); } void UMyMultiLineEditableText::MoveCursor(const int& InLineIndex, const int& InOffset) { MyMultiLineEditableText->GoTo(FTextLocation(InLineIndex, InOffset)); } // FTextLocation UMyMultiLineEditableText::GetTextLocation() const { // return CaretLocation; // }