User Interface
Samples in this section illustrate the use of the GUI-Related classes.
Object Frame#
This sample shows how to dynamically create and display rectangular frames around objects in the scene using the WidgetCanvas. These frames include object labels and appear only if the object is visible and is located within a certain distance from the camera.
You can also take screenshots via the Snap Screenshot button. The captured image does not include the rendered frames, but all frame metadata (including object ID, name, transform, and screen coordinates of the frame) is saved to a separate JSON file.
The bounding box of each object is computed recursively based on all its mesh components. The resulting rectangle is projected onto the screen space and checked for visibility. If visible and not occluded, a 2D frame is drawn using WidgetCanvas class.
All metadata, such as object ID, name, world-space position and rotation, as well as screen-space rectangle coordinates, is collected and saved as a structured JSON document using the Json class.
This approach is useful for creating visual overlays, annotations, or UI debug elements where object-specific data must be highlighted or preserved externally.
SDK Path: <SDK_INSTALLATION>source/user_interface/object_frame
Target Marker#
This sample demostrates how to implement a marker that always highlights the target when it is within the field of view, or displays an arrow pointing the direction to the target when it is out of sight (aligned with the screen borders).
SDK Path: <SDK_INSTALLATION>source/user_interface/target_marker
User Interface#
This sample shows how to generate a User Interface from a description stored in a .ui file (XML format) via C++ API. The sample also demonstrates how to get a UI widget by name via getWidgetByName() and subscribe to events to implement custom handling for user actions (particularly selecting File -> Reload from the main menu or entering text in the text field on the EditText tab).
SDK Path: <SDK_INSTALLATION>source/user_interface/user_interface
Canvas Widget#
This sample demonstrates how to use the WidgetCanvas class to draw vector-based shapes and text. The canvas supports adding lines, polygons, and text by defining their geometry through vertex positions. Elements are layered by draw order and colored individually.
The canvas content remains sharp regardless of scaling or rotation. In this example, the entire canvas is transformed over time, rotating and moving in 3D space while preserving the clarity of its contents. The geometry is built using helper functions that generate radial lines and regular polygons, and the layout is updated every frame using a transformation matrix.
This can be used to create clean, scalable UI elements, procedural charts, custom overlays, or dynamic data visualizations in tools or applications.
SDK Path: <SDK_INSTALLATION>source/user_interface/widget_canvas
Dialog Widget#
This sample demonstrates how to create and manage a GUI dialog system using UNIGINE's dialog widgets via the C++ API. A WidgetWindow instance contains several buttons, each opening a different type of dialog: WidgetDialogMessage, WidgetDialogFile, WidgetDialogColor, or WidgetDialogImage.
Each button is connected to an event handler that creates and configures the corresponding dialog widget. Dialogs are shown centered on screen and support user interaction through OK and Cancel buttons. A shared handler manages these responses, logs actions to the console, and deletes the dialog afterward to clean up resources.
This approach can be used to build simple and interactive GUI tools, settings panels, or development utilities that require built-in dialog interactions.
SDK Path: <SDK_INSTALLATION>source/user_interface/widget_dialogs
Widget Extern#
This sample demonstrates how to create a custom GUI widget by inheriting from WidgetExternBase via the C++ API. The custom class overrides key methods like render(), arrange(), and checkCallbacks() to implement unique visual and interactive behavior.
The widget is registered with a unique class ID using WidgetExternBase::addClassID(), and can then be instantiated using WidgetExtern::create().
This setup allows full control over widget rendering and logic directly in C++.
SDK Path: <SDK_INSTALLATION>source/user_interface/widget_extern
Widget Manipulator#
This sample demonstrates the use of manipulators. You can lock axes for transformations, and apply transformation in local or world coordinates.
SDK Path: <SDK_INSTALLATION>source/user_interface/widget_manipulators
Widget Window#
This sample demonstrates how to create a basic WidgetWindow using the C++ API and handle user interactions (edit line and button press events) through handler function connections.
The window includes a WidgetEditLine and a WidgetButton. The WidgetEditLine listens for text changes via Widget::getEventChanged() and logs the new input, while the WidgetButton uses Widget::getEventClicked() to trigger an action when pressed. Font sizes are adjusted for better readability, and the layout is arranged automatically.
This approach is suitable for building interactive UI elements directly within UNIGINE's native GUI system.
SDK Path: <SDK_INSTALLATION>source/user_interface/widget_window
Widgets#
This sample demonstrates the implementation of various UI widgets in UNIGINE. It showcases how to create, configure and manage interactive GUI elements.
The sample includes multiple widget types with event handling capabilities, demonstrating how to create and position widgets, configure visual properties, handle user interactions, etc., such as sliders, scrolls, buttons, checkboxes, drop-down lists, etc.
SDK Path: <SDK_INSTALLATION>source/user_interface/widgets
The information on this page is valid for UNIGINE 2.20 SDK.