Skip to content

Commit 2250cc6

Browse files
author
Roberto De Ioris
committed
2 parents a1472f8 + bbc68c0 commit 2250cc6

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

docs/Slate_API.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,99 @@ window = SWindow(client_size=(512, 32), title='Open Asset', sizing_rule=0)(
615615
```
616616

617617
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.
618+
619+
## SCheckBox
620+
621+
Very useful for managing boolean values:
622+
623+
```python
624+
from unreal_engine import SWindow, SEditableTextBox, SHorizontalBox, SButton, SCheckBox, STextBlock
625+
from unreal_engine.classes import Object
626+
from unreal_engine.enums import EVerticalAlignment
627+
import unreal_engine as ue
628+
629+
asset_name=None
630+
checkbox_bool=False
631+
632+
def open_or_validate(path, only_validate):
633+
try:
634+
asset = ue.load_object(Object, path)
635+
except:
636+
ue.message_dialog_open(ue.APP_MSG_TYPE_OK, 'invalid path')
637+
return
638+
639+
if only_validate:
640+
ue.message_dialog_open(ue.APP_MSG_TYPE_OK, 'path is valid')
641+
else:
642+
ue.open_editor_for_asset(asset)
643+
644+
window = SWindow(client_size=(512, 32), title='Open Asset', sizing_rule=0)(
645+
SHorizontalBox()
646+
(
647+
SEditableTextBox().assign('asset_name')
648+
)
649+
(
650+
STextBlock(text='only validate path'), auto_width=True, v_align=EVerticalAlignment.VAlign_Center
651+
)
652+
(
653+
SCheckBox().assign('checkbox_bool'), auto_width=True
654+
)
655+
(
656+
SButton(text='Ok', on_clicked=lambda: open_or_validate(asset_name.get_text(), checkbox_bool.is_checked())), auto_width=True
657+
)
658+
)
659+
```
660+
661+
![SCheckBox](https://github.com/20tab/UnrealEnginePython/raw/master/docs/screenshots/slate_SCheckBox.png)
662+
663+
## OOP refactoring
664+
665+
Time to refactor the code to be more elegant, and to allow the reuse of custom/complex widgets:
666+
667+
```python
668+
from unreal_engine import SWindow, SEditableTextBox, SHorizontalBox, SButton, SCheckBox, STextBlock, SVerticalBox
669+
from unreal_engine.classes import Object
670+
from unreal_engine.enums import EVerticalAlignment
671+
import unreal_engine as ue
672+
673+
class AssetOpener(SHorizontalBox):
674+
675+
def __init__(self):
676+
super().__init__(self)
677+
self.asset_name_picker = SEditableTextBox()
678+
self.only_validate_path = SCheckBox()
679+
680+
self.add_slot(self.asset_name_picker)
681+
self.add_slot(STextBlock(text='only validate path'), auto_width=True, v_align=EVerticalAlignment.VAlign_Center)
682+
self.add_slot(self.only_validate_path, auto_width=True)
683+
self.add_slot(SButton(text='Ok', on_clicked=self.open_or_validate), auto_width=True)
684+
685+
def open_or_validate(self):
686+
try:
687+
asset = ue.load_object(Object, self.asset_name_picker.get_text())
688+
print(asset)
689+
except:
690+
ue.message_dialog_open(ue.APP_MSG_TYPE_OK, 'invalid path')
691+
return
692+
693+
if self.only_validate_path.is_checked():
694+
ue.message_dialog_open(ue.APP_MSG_TYPE_OK, 'path is valid')
695+
else:
696+
ue.open_editor_for_asset(asset)
697+
698+
699+
700+
window = SWindow(client_size=(512, 64), title='Open Asset', sizing_rule=0)(
701+
SVerticalBox()
702+
(
703+
STextBlock(text='OOP widget below')
704+
)
705+
(
706+
AssetOpener()
707+
)
708+
)
709+
```
710+
711+
![OOP](https://github.com/20tab/UnrealEnginePython/raw/master/docs/screenshots/slate_OOP.png)
712+
713+
As you can see, you can inherit from SWidget. Obviously you can mix 'visual' style, with fully procedural one, but the use of classes will simplify 'context' management.

0 commit comments

Comments
 (0)