Skip to content

Commit 286f3bf

Browse files
author
Roberto De Ioris
authored
Update Slate_API.md
1 parent 2d91906 commit 286f3bf

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

docs/Slate_API.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,59 @@ https://api.unrealengine.com/INT/API/Runtime/SlateCore/Styling/FSlateBrush/index
559559

560560
## SEditableTextBox
561561

562+
This widget allows the user to input a string:
562563

564+
```python
565+
from unreal_engine import SWindow, SEditableTextBox, SHorizontalBox, SButton
566+
from unreal_engine.classes import Object
567+
import unreal_engine as ue
568+
569+
asset_name=SEditableTextBox()
570+
571+
window = SWindow(client_size=(512, 32), title='Open Asset', sizing_rule=0)(
572+
SHorizontalBox()
573+
(
574+
asset_name
575+
)
576+
(
577+
SButton(text='Ok', on_clicked=lambda: ue.open_editor_for_asset(ue.load_object(Object, asset_name.get_text()))), auto_width=True
578+
)
579+
)
580+
```
581+
582+
![SEditableTextBox](https://github.com/20tab/UnrealEnginePython/raw/master/docs/screenshots/slate_SEditableTextBox.png)
583+
584+
The get_text() method will return the currently inserted text.
585+
586+
When the user click on 'Ok', the asset specified in the SEditableTextBox will be validated, loaded and opened in the related editor.
587+
588+
More infos (check FArguments) here:
589+
590+
https://api.unrealengine.com/INT/API/Runtime/Slate/Widgets/Input/SEditableTextBox/index.html
591+
592+
593+
## The .assign() hack
594+
595+
In the previous example we used a 'mixed' visual style to allow the SEditableTextBox to be assigned to a python variable to be able to reference it in the on_clicked event.
596+
597+
The python SWidget api supports an alternative way for assigning references to SWidget. It is indeed a hack (and honestly not very pythonic), but for big interfaces should simplify the management a lot:
598+
599+
```python
600+
from unreal_engine import SWindow, SEditableTextBox, SHorizontalBox, SButton
601+
from unreal_engine.classes import Object
602+
import unreal_engine as ue
603+
604+
asset_name=None
605+
606+
window = SWindow(client_size=(512, 32), title='Open Asset', sizing_rule=0)(
607+
SHorizontalBox()
608+
(
609+
SEditableTextBox().assign('asset_name')
610+
)
611+
(
612+
SButton(text='Ok', on_clicked=lambda: ue.open_editor_for_asset(ue.load_object(Object, asset_name.get_text()))), auto_width=True
613+
)
614+
)
615+
```
616+
617+
Basically the .assign(global_name) method, will map the SWidget to the global item specified as global_name. The .assign() method will check for validity of the passed name, so typos will not be a problem.

0 commit comments

Comments
 (0)