/** * Copyright (c) 2024 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dawn.h" #define MENU_HELD_TIME_INITIAL 0.5f #define MENU_HELD_TIME_REPEAT 0.2f #define MENU_ITEM_COUNT_MAX 256 typedef enum { MENU_DIRECTION_UP = 0, MENU_DIRECTION_DOWN = 1, MENU_DIRECTION_LEFT = 2, MENU_DIRECTION_RIGHT = 3 } menudirection_t; typedef struct _menu_t menu_t; typedef struct _menu_t { uint16_t x, y; uint16_t rows, columns; float_t repeatHeld; const char_t* strings[MENU_ITEM_COUNT_MAX]; // Visual things uint16_t renderOffsetX, renderOffsetY; // Callbacks void (*selectCallback)( const menu_t *menu, const uint16_t x, const uint16_t y, const char_t *str ); } menu_t; /** * Initializes the menu. * * @param menu Menu to initialize. * @param rows Number of rows in the menu. * @param columns Number of columns in the menu. */ void menuInit(menu_t *menu, const uint16_t rows, const uint16_t columns); /** * Updates the menu. Only needs to be called if the menu is active. * * @param menu Menu to update. */ void menuUpdate(menu_t *menu); /** * Updates the menu's cursor position. * * @param menu Menu to update. * @param direction Direction to update the menu. */ void menuPositionMove(menu_t *menu, const menudirection_t direction); /** * Sets the position of the cursor in the menu. * * @param menu Menu to set the cursor position. * @param x X position. * @param y Y position. */ void menuPositionSet(menu_t *menu, const uint16_t x, const uint16_t y);