Implementation:Google deepmind Mujoco UI Main
| Knowledge Sources | |
|---|---|
| Domains | User Interface, OpenGL, GUI, Rendering |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Core UI rendering and event handling implementation providing themed widget drawing, layout computation, input processing, and UI state management for MuJoCo's immediate-mode GUI system.
Description
This file implements MuJoCo's complete UI framework including default theme definitions (spacing and color configurations for tight/wide layouts and four color schemes), widget rendering (text fields, sliders, radio buttons, checkboxes, separators), section-based layout management, keyboard shortcut parsing, mouse interaction handling, and UI-to-image rendering. The system uses an immediate-mode approach where UI definitions (mjuiDef) are added to sections and rendered each frame based on the current mjuiState.
Usage
Used by the MuJoCo simulate viewer and any application that builds a GUI using MuJoCo's built-in UI system. Themes are retrieved via mjui_themeSpacing and mjui_themeColor, definitions are added via mjui_add, and the event loop calls mjui_event and mjui_render each frame.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/ui/ui_main.c
- Lines: 1-2992
Key Functions
// Get builtin UI theme spacing (ind: 0-1)
mjuiThemeSpacing mjui_themeSpacing(int ind);
// Get builtin UI theme color (ind: 0-3)
mjuiThemeColor mjui_themeColor(int ind);
// Add definitions to UI
void mjui_add(mjUI* ui, const mjuiDef* def);
// Add definitions to a specific UI section
void mjui_addToSection(mjUI* ui, int sect, const mjuiDef* def);
// Compute UI sizes based on current content
void mjui_resize(mjUI* ui, const mjrContext* con);
// Update specific section/item; -1 updates all
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)
mjuiItem* mjui_event(mjUI* ui, mjuiState* state, const mjrContext* con);
// Copy UI image to current buffer
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, items, and layout state |
| def | const mjuiDef* | Yes (for add) | Array of UI item definitions terminated by an end marker |
| state | mjuiState* | Yes | Current UI input state (mouse position, key presses, modifiers) |
| con | const mjrContext* | Yes | Rendering context with font data and OpenGL resources |
| ind | int | Yes (for theme) | Theme index: 0-1 for spacing, 0-3 for color |
Outputs
| Name | Type | Description |
|---|---|---|
| mjuiItem* | pointer | Pointer to the changed UI item after event processing, or NULL |
| mjuiThemeSpacing | struct | Theme spacing configuration (total width, label width, margins) |
| mjuiThemeColor | struct | Theme color configuration (section titles, fonts, backgrounds, controls) |
| (rendered output) | OpenGL framebuffer | Fully rendered UI panels drawn to the active framebuffer |