Skip to content

raisin::tcp_viewer::ViewerWidget ​

class · #include <rayrai/TcpViewerWidget.hpp>

The TCP viewer inside a window of another ImGui application.

The viewer runs in an ImGui context of its own (it restyles and re-fonts its context and lays its panes out as top-level windows) and is rendered into a texture that is drawn as an image in the host window. The host's mouse input reaches the viewer only while a press that started on the image is held or the image is hovered, and keys and text only while the host window has focus. A text field of the viewer that has keyboard focus sets the host's io.WantTextInput, and the viewer's clipboard is the host's.

The host's OpenGL context must be current in every call, and the host's ImGui context with the OpenGL3 renderer backend in draw() and drawHidden(). The viewer renders with the host's context: draw(), drawHidden() and shutdown() keep the host's framebuffers, viewport, clear color, pixel pack and unpack state, active texture unit with its 2D texture, program (while it still exists) and vertex array, but not the rest of the GL state (other texture units, buffer bindings, depth, blend, cull), which a host that renders after them sets for itself, as ImGui's renderer backend does.

Constructors & destructor ​

ViewerWidget ​

cpp
explicit ViewerWidget(ViewerAppConfig config)
cpp
ViewerWidget(const ViewerWidget &) = delete

~ViewerWidget ​

cpp
~ViewerWidget()

Calls shutdown() if the host did not.

Public member functions ​

operator= ​

cpp
ViewerWidget &operator=(const ViewerWidget &) = delete

draw ​

cpp
void draw(const ImVec2 &size, bool forwardKeyboard=true)

Runs one viewer frame and draws it at the cursor of the current host window. The viewer is created by the first call.

Parameters

ParameterDescription
sizeImage size in host points; the viewer's display has this size.
forwardKeyboardFalse while the host uses the keyboard for something else; a text field of the viewer that has keyboard focus still gets the keys.

drawHidden ​

cpp
void drawHidden()

Runs one viewer frame without input at the last size, for a host window that is collapsed or hidden: connections, recordings and local simulations keep running.

ok ​

cpp
bool ok() const

False once the viewer failed to initialize; draw() then shows a message instead.

shutdown ​

cpp
void shutdown()

Releases the viewer and its image. The host must not call it between drawing the widget and rendering that frame's draw data, which still refers to the image: a window that is closed in its frame skips draw() instead.

RaiSim — physics for robotics and AI.