This example demonstrates MultiWidgets::ViewWidget. ViewWidgets can be used as viewports or cameras. They can be placed like normal widgets, but as their content they can display another part of the widget hierarchy.
ViewWidget is created like a normal widget, but they take an additional widget as scene parameter. The scene is the widget that is visualized inside the view. It can be though of as a target object the viewport or camera is looking at. In this example, we create a ViewWidget and point it to the main layer of the application:
ViewWidgets also support additional transformation that is applied when visualizing the scene widget. This is called the view transform. In this example, we want the entire content of the main layer to be visible in the view so we use MultiWidgets::ViewWidget::frameRect function to calculate the transform for us:
What this does is create a view transform where the given rectangle is framed by the viewport.
As the ViewWidget itself is a child of the application main layer and the target scene of the ViewWidget is the main layer, this example produces a recursive view. The ViewWidget is looking at itself. To avoid infinite loops, Luminous::RenderContext provides a limit for the recursion depth. It can be adjusted using the Luminous::RenderContext::setRecursionLimit function.
Typically the ViewWidgets are used to create live previews to parts of applications. Recursion is rarely required.
The full source code for the example is listed below: