Modifying the Interface¶
When talking about modifying and getting the interface, it refers to the specific content of the interface, not the interface widgets themselves. It has been mentioned that SWidget objects are pure C++ objects, and there is no corresponding Python object that can be obtained or accessed. In TAPython, all operations on the interface are implemented through ChameleonData.
For example, in the previous example
chameleon_gallery.data.set_text(aka_name="IsPythonReadyText", text="Some Changed text"), we specify the widget name through the variable aka_name, and then pass in the new text.
Be careful not to modify the interface in a non-main thread. For example,
threading.Thread(target=target_slate) is not allowed to modify the interface content in another thread. This will trigger UE's SLATE_CROSS_THREAD_CHECK.
aka_nameneeds to be unique within a single ChameleonTool
- When setting widget content, the widget type does not need to be considered
- For example, we can use set_text to set text content for STextBlock, and also for SButton. In fact, STextBlock, SEditableText, SEditableTextBox, SMultiLineEditableText, SMultiLineEditableTextBox, SButton, etc., can all use this set_text to set text content
- Similarly, set_float_value supports both "SSlider" and "SSpinBox" widgets
In addition to getting and modifying content, we also provide corresponding APIs for some interactive widgets, such as using
scroll_to to scroll the
SMultiLineEditableTextBox to the desired position.
Similar functions include:
ScrollTo function, for scrolling the scrollbar to the specified location
Controlling Interface Visibility¶
In the Unreal editor interface, there are many dynamic interfaces that are actually implemented by controlling the visibility of widgets. If you have done GamePlayUMG, you should be able to understand this point intuitively. We will create all the interfaces needed before making the tool, and then the interface switching and other operations are actually controlling visibility (Visibility).
Slate widget visibility has the following 5 types:
|Syntax||Visible||Occupies Space||Clickable||Child Widgets Clickable|
Among the 5 Visible states above, "Visible" and "Collapsed" are the most commonly used. There are simplified calling versions for all of them. For example, in ObjectDetail, use
set_collapsed to control visibility.
We can set its state through set_visibility, for example, Shelf Tool uses it to control the visibility state of the last drag box:
he other three states are related to the response of click events, and are usually used to control which Overlay widget is in the "active" state and which responds to click events.
For example, in Shelf Tool, when the user needs to modify the text below the button, the "HitTestInvisible" state of the text widget is removed, allowing the user to drag the text cursor. Otherwise, the button below responds to the user's click event:
self.data.set_visibility(self.get_ui_text_name(i), "HitTestInvisible" if bLock else "Visible" )
In addition to modifying content and visibility, we can also change the size and position of the entire tool window, etc. For more information, refer to Controlling Other Tools