UI improvements. Fixes #1274.

Copybara import of the project:

--
a1297d997d0b3cc624bbd1e704ffb7fbb2c5db9d by Emo Todorov <etodorov@gmail.com>:

UI imrovements

When OpenGL buffer size is too small to hold entire UI with all sections open, older sections (as determined by latest mouse click) are automatically closed as needed.

To test this new functionality, uncomment the test near the top of mjui_resize().

UI items now have userid, which can be used for event handling.  It is set through the (new) last field of mjuiDef, called otherint.

Sections titles can now have a checkmark - in which case they are rendered differently. Set via mjuiDef.otherint: 0- none (as before), 1- rendering changed but box not shown, 2- box shown.  This can be used to label sections of special interest to the application.

--
b0405bfb3005586ef1d2656ea9cc43c608225927 by Emo Todorov <etodorov@gmail.com>:

more ui improvements

Implemented mjPRESERVE state for adding sections and separators, so you don't have to keep track of old states.

simulate.cc is now modified to use this new functionality.  I also made the separators in the Physics section collapsible. If you don't like it, change them back to state 1.

Also added functionality for handling section checkboxes.

--
10f4c49be62a6605a38b7c0c7bfae1629024ba31 by Emo Todorov <etodorov@gmail.com>:

even more ui improvements

Selection boxes that extend below the current UI height are finally rendered in full.

Sections and collapsible separators now have rounded corners. The radius can be controlled from theme spacing.

More theme color settings were added. In particular, color gradients can now be disabled (the two end colors are set independently).

--
96c2dc601a25d31c93b21f8e089d349e729e829e by Emo Todorov <etodorov@gmail.com>:

final ui improvements

Cleaned up the code a bit.

Added more control for color gradients.

--
c9eddb679f36df3f0745d37e3fa90c4e66ee6b98 by Emo Todorov <etodorov@gmail.com>:

bug fix

Fixed some rendering bugs in the new functionality.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/1749 from emotodorov:ui_improve ddfc21dbcf0482b8f0d5eacab21847c302f71440
PiperOrigin-RevId: 646060325
Change-Id: Idb27aae7cd0311d00f26387bcadf5891175e867d
This commit is contained in:
Emo Todorov
2024-06-24 05:30:25 -07:00
committed by Copybara-Service
parent e66b9a36b2
commit ee6a1dba28
10 changed files with 946 additions and 435 deletions
+24 -2
View File
@@ -26,6 +26,7 @@
#define mjMAXUIRECT 25 // maximum number of rectangles
#define mjSEPCLOSED 1000 // closed state of adjustable separator
#define mjPRESERVE 2000 // preserve section or separator state
// key codes matching GLFW (user must remap for other frameworks)
@@ -106,6 +107,13 @@ typedef enum mjtItem_ { // UI item type
} mjtItem;
typedef enum mjtSection_ { // UI section state
mjSECT_CLOSED = 0, // closed state (regular section)
mjSECT_OPEN, // open state (regular section)
mjSECT_FIXED // fixed section: always open, no title
} mjtSection;
// predicate function: set enable/disable based on item category
typedef int (*mjfItemEnable)(int category, void* data);
@@ -163,6 +171,8 @@ struct mjuiThemeSpacing_ { // UI visualization theme spacing
int scroll; // scrollbar width
int label; // label width
int section; // section gap
int cornersect; // corner radius for section
int cornersep; // corner radius for separator
int itemside; // item side gap
int itemmid; // item middle gap
int itemver; // item vertical gap
@@ -180,9 +190,14 @@ struct mjuiThemeColor_ { // UI visualization theme color
float master[3]; // master background
float thumb[3]; // scrollbar thumb
float secttitle[3]; // section title
float secttitle2[3]; // section title: bottom color
float secttitlecheck[3]; // section title with checkbox
float secttitlecheck2[3]; // section title with checkbox: bottom color
float sectfont[3]; // section font
float sectsymbol[3]; // section symbol
float sectpane[3]; // section pane
float separator[3]; // separator title
float separator2[3]; // separator title: bottom color
float shortcut[3]; // shortcut background
float fontactive[3]; // font active
float fontinactive[3]; // font inactive
@@ -236,6 +251,7 @@ struct mjuiItem_ { // UI item
void *pdata; // data pointer (type-specific)
int sectionid; // id of section containing item
int itemid; // id of item within section
int userid; // user-supplied id (for event handling)
// type-specific properties
union {
@@ -247,6 +263,7 @@ struct mjuiItem_ { // UI item
// internal
mjrRect rect; // rectangle occupied by item
int skip; // item skipped due to closed separator
};
typedef struct mjuiItem_ mjuiItem;
@@ -256,15 +273,17 @@ typedef struct mjuiItem_ mjuiItem;
struct mjuiSection_ { // UI section
// properties
char name[mjMAXUINAME]; // name
int state; // 0: closed, 1: open
int state; // section state (mjtSection)
int modifier; // 0: none, 1: control, 2: shift; 4: alt
int shortcut; // shortcut key; 0: undefined
int checkbox; // 0: none, 1: hidden, 2: unchecked, 2: checked
int nitem; // number of items in use
mjuiItem item[mjMAXUIITEM]; // preallocated array of items
// internal
mjrRect rtitle; // rectangle occupied by title
mjrRect rcontent; // rectangle occupied by content
int lastclick; // last mouse click over this section
};
typedef struct mjuiSection_ mjuiSection;
@@ -287,10 +306,12 @@ struct mjUI_ { // entire UI
int maxheight; // height when all sections open
int scroll; // scroll from top of UI
// mouse focus
// mouse focus and count
int mousesect; // 0: none, -1: scroll, otherwise 1+section
int mouseitem; // item within section
int mousehelp; // help button down: print shortcuts
int mouseclicks; // number of mouse clicks over UI
int mousesectcheck; // 0: none, otherwise 1+section
// keyboard focus and edit
int editsect; // 0: none, otherwise 1+section
@@ -315,6 +336,7 @@ struct mjuiDef_ { // table passed to mjui_add()
int state; // state
void* pdata; // pointer to data
char other[mjMAXUITEXT]; // string with type-specific properties
int otherint; // int with type-specific properties
};
typedef struct mjuiDef_ mjuiDef;