mGUI: Add read-only menu items

This commit is contained in:
Vicki Pfau 2022-01-09 15:05:57 -08:00
parent 899fbdf1e4
commit 27d59e5ed6
3 changed files with 23 additions and 20 deletions

View File

@ -61,6 +61,7 @@ struct GUIMenuItem {
const struct GUIVariant* stateMappings; const struct GUIVariant* stateMappings;
unsigned nStates; unsigned nStates;
struct GUIMenu* submenu; struct GUIMenu* submenu;
bool readonly;
}; };
DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem); DECLARE_VECTOR(GUIMenuItemList, struct GUIMenuItem);

View File

@ -21,7 +21,7 @@ void mGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct
size_t i; size_t i;
*GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) {
.title = "Game keys:", .title = "Game keys:",
.data = GUI_V_V, .readonly = true,
}; };
for (i = 0; i < map->info->nKeys; ++i) { for (i = 0; i < map->info->nKeys; ++i) {
*GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) {
@ -35,7 +35,7 @@ void mGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct
} }
*GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) { *GUIMenuItemListAppend(&menu.items) = (struct GUIMenuItem) {
.title = "Interface keys:", .title = "Interface keys:",
.data = GUI_V_V, .readonly = true,
}; };
for (i = 0; i < params->keyMap.info->nKeys; ++i) { for (i = 0; i < params->keyMap.info->nKeys; ++i) {
if (!params->keyMap.info->keyId[i]) { if (!params->keyMap.info->keyId[i]) {

View File

@ -122,7 +122,7 @@ static enum GUIMenuExitReason GUIMenuPollInput(struct GUIParams* params, struct
} }
if (newInput & (1 << GUI_INPUT_LEFT)) { if (newInput & (1 << GUI_INPUT_LEFT)) {
struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index); struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index);
if (item->validStates) { if (item->validStates && !item->readonly) {
_itemPrev(item, false); _itemPrev(item, false);
} else if (menu->index >= pageSize) { } else if (menu->index >= pageSize) {
menu->index -= pageSize; menu->index -= pageSize;
@ -132,7 +132,7 @@ static enum GUIMenuExitReason GUIMenuPollInput(struct GUIParams* params, struct
} }
if (newInput & (1 << GUI_INPUT_RIGHT)) { if (newInput & (1 << GUI_INPUT_RIGHT)) {
struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index); struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index);
if (item->validStates) { if (item->validStates && !item->readonly) {
_itemNext(item, false); _itemNext(item, false);
} else if (menu->index + pageSize < GUIMenuItemListSize(&menu->items)) { } else if (menu->index + pageSize < GUIMenuItemListSize(&menu->items)) {
menu->index += pageSize; menu->index += pageSize;
@ -184,17 +184,19 @@ static enum GUIMenuExitReason GUIMenuPollInput(struct GUIParams* params, struct
} }
if (newInput & (1 << GUI_INPUT_SELECT) || (state->cursorOverItem == 2 && state->cursor == GUI_CURSOR_CLICKED)) { if (newInput & (1 << GUI_INPUT_SELECT) || (state->cursorOverItem == 2 && state->cursor == GUI_CURSOR_CLICKED)) {
struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index); struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, menu->index);
if (item->submenu) { if (!item->readonly) {
// Selected menus get shown inline if (item->submenu) {
state->resultItem = item; // Selected menus get shown inline
return GUI_MENU_ENTER; state->resultItem = item;
} else if (item->validStates && GUIVariantIsString(item->data)) { return GUI_MENU_ENTER;
// Selected items with multiple (named) states get scrolled through } else if (item->validStates && GUIVariantIsString(item->data)) {
_itemNext(item, true); // Selected items with multiple (named) states get scrolled through
} else { _itemNext(item, true);
// Otherwise tell caller item was accepted } else {
state->resultItem = item; // Otherwise tell caller item was accepted
return GUI_MENU_EXIT_ACCEPT; state->resultItem = item;
return GUI_MENU_EXIT_ACCEPT;
}
} }
} }
if (state->cursorOverItem == 1 && (state->cursor == GUI_CURSOR_UP || state->cursor == GUI_CURSOR_NOT_PRESENT)) { if (state->cursorOverItem == 1 && (state->cursor == GUI_CURSOR_UP || state->cursor == GUI_CURSOR_NOT_PRESENT)) {
@ -229,12 +231,12 @@ static void GUIMenuDraw(struct GUIParams* params, const struct GUIMenu* menu, co
size_t i; size_t i;
for (i = state->start; i < GUIMenuItemListSize(&menu->items); ++i) { for (i = state->start; i < GUIMenuItemListSize(&menu->items); ++i) {
int color = 0xE0A0A0A0; int color = 0xE0A0A0A0;
if (i == menu->index) {
color = 0xFFFFFFFF;
GUIFontDrawIcon(params->font, lineHeight * 0.8f, y, GUI_ALIGN_BOTTOM | GUI_ALIGN_RIGHT, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_POINTER);
}
const struct GUIMenuItem* item = GUIMenuItemListGetConstPointer(&menu->items, i); const struct GUIMenuItem* item = GUIMenuItemListGetConstPointer(&menu->items, i);
GUIFontPrint(params->font, lineHeight, y, GUI_ALIGN_LEFT, color, item->title); if (i == menu->index) {
color = item->readonly ? 0xD0909090 : 0xFFFFFFFF;
GUIFontDrawIcon(params->font, lineHeight * 0.8f, y, GUI_ALIGN_BOTTOM | GUI_ALIGN_RIGHT, GUI_ORIENT_0, color, GUI_ICON_POINTER);
}
GUIFontPrint(params->font, item->readonly ? lineHeight * 3 / 2 : lineHeight, y, GUI_ALIGN_LEFT, color, item->title);
if (item->validStates && item->validStates[item->state]) { if (item->validStates && item->validStates[item->state]) {
GUIFontPrintf(params->font, params->width - right - 8, y, GUI_ALIGN_RIGHT, color, "%s ", item->validStates[item->state]); GUIFontPrintf(params->font, params->width - right - 8, y, GUI_ALIGN_RIGHT, color, "%s ", item->validStates[item->state]);
} }