Implementation:Google deepmind Mujoco UI Main Header
| Knowledge Sources | |
|---|---|
| Domains | User Interface, GUI, Rendering |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Header declaring the public API for MuJoCo's immediate-mode UI system including theme retrieval, widget definition, layout computation, event handling, and rendering.
Description
This header provides the function declarations for MuJoCo's built-in UI framework. It exposes eight MJAPI functions: theme spacing and color retrieval (mjui_themeSpacing, mjui_themeColor), UI definition addition (mjui_add, mjui_addToSection), layout computation (mjui_resize), state update (mjui_update), event handling (mjui_event), and rendering (mjui_render). The header is the minimal public interface for the full UI implementation in ui_main.c.
Usage
Included by the simulate viewer and any application that uses MuJoCo's built-in UI panels. Applications define UI items using mjuiDef arrays, add them to an mjUI structure, and then call the event and render functions each frame.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/ui/ui_main.h
- Lines: 1-53
Key Functions
// Get builtin UI theme spacing (ind: 0-1)
MJAPI mjuiThemeSpacing mjui_themeSpacing(int ind);
// Get builtin UI theme color (ind: 0-3)
MJAPI mjuiThemeColor mjui_themeColor(int ind);
// Add definitions to UI
MJAPI void mjui_add(mjUI* ui, const mjuiDef* def);
// Add definitions to a specific UI section
MJAPI void mjui_addToSection(mjUI* ui, int sect, const mjuiDef* def);
// Compute UI sizes
MJAPI void mjui_resize(mjUI* ui, const mjrContext* con);
// Update specific section/item; -1: update all
MJAPI void mjui_update(int section, int item, const mjUI* ui,
const mjuiState* state, const mjrContext* con);
// Handle UI event, return pointer to changed item, NULL if no change
MJAPI mjuiItem* mjui_event(mjUI* ui, mjuiState* state, const mjrContext* con);
// Copy UI image to current buffer
MJAPI void mjui_render(mjUI* ui, const mjuiState* state, const mjrContext* con);
Import
#include "ui/ui_main.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| ui | mjUI* | Yes | UI structure containing sections and items |
| def | const mjuiDef* | Yes (for add) | Array of UI item definitions |
| state | mjuiState* | Yes (for event/render) | Current input state (mouse, keyboard) |
| con | const mjrContext* | Yes | Rendering context with font data |
| ind | int | Yes (for theme) | Theme index (0-1 spacing, 0-3 color) |
| section, item | int | Yes (for update) | Section and item indices; -1 for all |
Outputs
| Name | Type | Description |
|---|---|---|
| mjuiItem* | pointer | Changed UI item after event processing, or NULL if unchanged |
| mjuiThemeSpacing | struct | Theme spacing configuration |
| mjuiThemeColor | struct | Theme color configuration |