|
| 1 | +# Menu API Reference |
| 2 | + |
| 3 | +Integrate custom menus below the mods menu item and create custom windows with interactive controls using the `libmcpelauncher_menu.so` library. |
| 4 | + |
| 5 | +## `MenuEntryABI` Structure |
| 6 | + |
| 7 | +Defines a single menu entry with potential subentries. |
| 8 | + |
| 9 | +```cpp |
| 10 | +struct MenuEntryABI { |
| 11 | + const char* name; // Name shown in the UI |
| 12 | + void* user; // Custom user data passed to callbacks |
| 13 | + bool (*selected)(void* user); // Selection callback |
| 14 | + void (*click)(void* user); // Click callback |
| 15 | + size_t length; // Number of subentries |
| 16 | + MenuEntryABI* subentries; // Pointer to array of subentries |
| 17 | +}; |
| 18 | +``` |
| 19 | +
|
| 20 | +--- |
| 21 | +
|
| 22 | +## `void mcpelauncher_addmenu(size_t length, MenuEntryABI* entries);` |
| 23 | +
|
| 24 | +Adds a group of menu entries to the launcher. |
| 25 | +
|
| 26 | +- `length`: Number of items in `entries` |
| 27 | +- `entries`: Pointer to array of `MenuEntryABI` |
| 28 | +
|
| 29 | +--- |
| 30 | +
|
| 31 | +## `control` Structure |
| 32 | +
|
| 33 | +Represents a UI control embedded in a window. |
| 34 | +
|
| 35 | +```cpp |
| 36 | +struct control { |
| 37 | + int type; // Enum-like control type |
| 38 | + union { |
| 39 | + struct { |
| 40 | + const char* label; |
| 41 | + void* user; |
| 42 | + void (*onClick)(void* user); |
| 43 | + } button; |
| 44 | +
|
| 45 | + struct { |
| 46 | + const char* label; |
| 47 | + int min; |
| 48 | + int def; |
| 49 | + int max; |
| 50 | + void* user; |
| 51 | + void (*onChange)(void* user, int value); |
| 52 | + } sliderint; |
| 53 | +
|
| 54 | + struct { |
| 55 | + const char* label; |
| 56 | + float min; |
| 57 | + float def; |
| 58 | + float max; |
| 59 | + void* user; |
| 60 | + void (*onChange)(void* user, float value); |
| 61 | + } sliderfloat; |
| 62 | +
|
| 63 | + struct { |
| 64 | + const char* label; |
| 65 | + int size; // 0 = normal, 1 = small title |
| 66 | + } text; |
| 67 | +
|
| 68 | + struct { |
| 69 | + const char* label; |
| 70 | + const char* def; |
| 71 | + const char* placeholder; |
| 72 | + void* user; |
| 73 | + void (*onChange)(void* user, const char* value); |
| 74 | + } textinput; |
| 75 | + } data; |
| 76 | +}; |
| 77 | +``` |
| 78 | + |
| 79 | +### Control Types |
| 80 | + |
| 81 | +Set `type` to match the control structure being used: |
| 82 | +- `0`: Button |
| 83 | +- `1`: Slider (integer) |
| 84 | +- `2`: Slider (float) |
| 85 | +- `3`: Static text |
| 86 | +- `4`: Text input |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## `void mcpelauncher_show_window(...)` |
| 91 | + |
| 92 | +Displays a window populated with interactive controls. |
| 93 | + |
| 94 | +```cpp |
| 95 | +void mcpelauncher_show_window( |
| 96 | + const char* title, |
| 97 | + int isModal, |
| 98 | + void* user, |
| 99 | + void (*onClose)(void* user), |
| 100 | + int count, |
| 101 | + control* controls |
| 102 | +); |
| 103 | +``` |
| 104 | + |
| 105 | +### Parameters |
| 106 | + |
| 107 | +- `title`: Title displayed on the window |
| 108 | +- `isModal`: Modal flag (non-zero blocks other inputs) |
| 109 | +- `user`: Custom user data passed to callbacks |
| 110 | +- `onClose`: Callback called when window closes |
| 111 | +- `count`: Number of controls |
| 112 | +- `controls`: Pointer to array of `control` structs |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## `void mcpelauncher_close_window(const char* title);` |
| 117 | + |
| 118 | +Closes the window with the specified title. |
0 commit comments