Skip to content

Commit b6f4431

Browse files
author
Roberto De Ioris
committed
implemented FArguments for SEditableTextBox
1 parent 3aab7d9 commit b6f4431

3 files changed

Lines changed: 93 additions & 1 deletion

File tree

‎Source/UnrealEnginePython/Private/Slate/UEPySEditableTextBox.cpp‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,34 @@ PyTypeObject ue_PySEditableTextBoxType = {
9090
};
9191

9292
static int ue_py_seditable_text_box_init(ue_PySEditableTextBox *self, PyObject *args, PyObject *kwargs) {
93-
ue_py_snew_simple(SEditableTextBox, s_border.s_compound_widget.s_widget);
93+
ue_py_slate_setup_farguments(SEditableTextBox);
94+
95+
ue_py_slate_farguments_bool("allow_context_menu", AllowContextMenu);
96+
ue_py_slate_farguments_struct("background_color", BackgroundColor, FSlateColor);
97+
ue_py_slate_farguments_bool("clear_keyboard_focus_on_commit", ClearKeyboardFocusOnCommit);
98+
ue_py_slate_farguments_struct("font", Font, FSlateFontInfo);
99+
ue_py_slate_farguments_struct("foreground_color", ForegroundColor, FSlateColor);
100+
ue_py_slate_farguments_text("hint_text", HintText);
101+
ue_py_slate_farguments_bool("is_caret_moved_when_gain_focus", IsCaretMovedWhenGainFocus);
102+
ue_py_slate_farguments_bool("is_password", IsPassword);
103+
ue_py_slate_farguments_bool("is_read_only", IsReadOnly);
104+
ue_py_slate_farguments_float("min_desired_width", MinDesiredWidth);
105+
ue_py_slate_farguments_event("on_context_menu_opening", OnContextMenuOpening, FOnContextMenuOpening, OnContextMenuOpening);
106+
ue_py_slate_farguments_event("on_key_down_handler", OnKeyDownHandler, FOnKeyDown, OnKeyDown);
107+
ue_py_slate_farguments_event("on_text_changed", OnTextChanged, FOnTextChanged, OnTextChanged);
108+
ue_py_slate_farguments_event("on_text_committed", OnTextCommitted, FOnTextCommitted, OnTextCommitted);
109+
ue_py_slate_farguments_struct("padding", Padding, FMargin);
110+
ue_py_slate_farguments_struct("read_only_foreground_color", ReadOnlyForegroundColor, FSlateColor);
111+
ue_py_slate_farguments_bool("revert_text_on_escape", RevertTextOnEscape);
112+
ue_py_slate_farguments_bool("select_all_text_on_commit", SelectAllTextOnCommit);
113+
ue_py_slate_farguments_bool("select_all_text_when_focused", SelectAllTextWhenFocused);
114+
ue_py_slate_farguments_optional_struct_ptr("style", Style, FEditableTextBoxStyle);
115+
ue_py_slate_farguments_text("text", Text);
116+
ue_py_slate_farguments_optional_enum("text_flow_direction", TextFlowDirection, ETextFlowDirection);
117+
ue_py_slate_farguments_optional_enum("text_shaping_method", TextShapingMethod, ETextShapingMethod);
118+
ue_py_slate_farguments_enum("virtual_keyboard_type", VirtualKeyboardType, EKeyboardType);
119+
120+
ue_py_snew(SEditableTextBox, s_border.s_compound_widget.s_widget);
94121
return 0;
95122
}
96123

‎Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ FReply UPythonSlateDelegate::OnMouseEvent(const FGeometry &geometry, const FPoin
3131
return FReply::Handled();
3232
}
3333

34+
FReply UPythonSlateDelegate::OnKeyDown(const FGeometry &geometry, const FKeyEvent &key_event) {
35+
FScopePythonGIL gil;
36+
37+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"OO", py_ue_new_uscriptstruct(FGeometry::StaticStruct(), (uint8 *)&geometry), py_ue_new_uscriptstruct(FKeyEvent::StaticStruct(), (uint8 *)&key_event));
38+
if (!ret) {
39+
unreal_engine_py_log_error();
40+
return FReply::Unhandled();
41+
}
42+
43+
if (ret == Py_False) {
44+
Py_DECREF(ret);
45+
return FReply::Unhandled();
46+
}
47+
Py_DECREF(ret);
48+
return FReply::Handled();
49+
}
50+
3451
FReply UPythonSlateDelegate::OnClicked() {
3552
FScopePythonGIL gil;
3653

@@ -48,6 +65,28 @@ FReply UPythonSlateDelegate::OnClicked() {
4865
return FReply::Handled();
4966
}
5067

68+
void UPythonSlateDelegate::OnTextChanged(const FText& text) {
69+
FScopePythonGIL gil;
70+
71+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"s", TCHAR_TO_UTF8(*text.ToString()));
72+
if (!ret) {
73+
unreal_engine_py_log_error();
74+
return;
75+
}
76+
Py_DECREF(ret);
77+
}
78+
79+
void UPythonSlateDelegate::OnTextCommitted(const FText& text, ETextCommit::Type commit_type) {
80+
FScopePythonGIL gil;
81+
82+
PyObject *ret = PyObject_CallFunction(py_callable, (char *)"si", TCHAR_TO_UTF8(*text.ToString()), (int)commit_type);
83+
if (!ret) {
84+
unreal_engine_py_log_error();
85+
return;
86+
}
87+
Py_DECREF(ret);
88+
}
89+
5190
void UPythonSlateDelegate::CheckBoxChanged(ECheckBoxState state) {
5291
FScopePythonGIL gil;
5392

@@ -107,6 +146,26 @@ TSharedPtr<SWidget> UPythonSlateDelegate::OnGetAssetContextMenu(const TArray<FAs
107146
}
108147
#endif
109148

149+
TSharedPtr<SWidget> UPythonSlateDelegate::OnContextMenuOpening() {
150+
FScopePythonGIL gil;
151+
152+
PyObject *ret = PyObject_CallFunction(py_callable, nullptr);
153+
if (!ret) {
154+
unreal_engine_py_log_error();
155+
return nullptr;
156+
}
157+
158+
ue_PySWidget *s_widget = py_ue_is_swidget(ret);
159+
if (!s_widget) {
160+
Py_DECREF(ret);
161+
UE_LOG(LogPython, Error, TEXT("returned value is not a SWidget"));
162+
return nullptr;
163+
}
164+
TSharedPtr<SWidget> value = s_widget->s_widget;
165+
Py_DECREF(ret);
166+
return value;
167+
}
168+
110169
void UPythonSlateDelegate::SimpleExecuteAction() {
111170
FScopePythonGIL gil;
112171

‎Source/UnrealEnginePython/Private/Slate/UEPySlate.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ class UPythonSlateDelegate : public UPythonDelegate
332332
FReply OnMouseEvent(const FGeometry &geometry, const FPointerEvent &pointer_event);
333333
FReply OnClicked();
334334

335+
FReply OnKeyDown(const FGeometry &geometry, const FKeyEvent &key_event);
336+
void OnTextChanged(const FText &text);
337+
void OnTextCommitted(const FText &text, ETextCommit::Type commit_type);
338+
335339
TSharedRef<SDockTab> SpawnPythonTab(const FSpawnTabArgs& args);
336340

337341
TSharedRef<ITableRow> GenerateRow(TSharedPtr<FPythonItem> InItem, const TSharedRef<STableViewBase>& OwnerTable);
@@ -343,6 +347,8 @@ class UPythonSlateDelegate : public UPythonDelegate
343347
void OnAssetSelected(const FAssetData& AssetData);
344348
#endif
345349

350+
TSharedPtr<SWidget> OnContextMenuOpening();
351+
346352
void SimpleExecuteAction();
347353
void ExecuteAction(PyObject *py_obj);
348354

0 commit comments

Comments
 (0)