An implementation for a selection grid that handles directional selection. More...
#include <tonc.h>Go to the source code of this file.
Data Structures | |
| struct | SelGridRowAttributes |
| A set of attributes to the selection grid row affecting selection grid behavior. More... | |
| struct | SelectionGridRow |
| struct | SelectionGrid |
| The core selection grid struct, represents the grid itself and its state. More... | |
Typedefs | |
| typedef POINT | Selection |
| typedef struct SelectionGridRow | SelectionGridRow |
| typedef struct SelectionGrid | SelectionGrid |
| typedef bool(* | RowOnSelectionChangedFunc) (SelectionGrid *selection_grid, int row_idx, const Selection *prev_selection, const Selection *new_selection) |
| Callback function type for handling selection changes in a SelectionGrid. | |
| typedef int(* | RowGetSizeFunc) () |
| Function pointer type for retrieving the size of a row in a selection grid. | |
| typedef void(* | RowOnKeyTransitFunc) (SelectionGrid *selection_grid, Selection *selection) |
| Callback function type for handling non-directional key presses in a selection grid row. | |
Functions | |
| void | selection_grid_process_input (SelectionGrid *selection_grid) |
| Processes user input for the selection grid. | |
| void | selection_grid_move_selection_horz (SelectionGrid *selection_grid, int direction_tribool) |
| Moves the selection horizontally within the selection grid. | |
| void | selection_grid_move_selection_vert (SelectionGrid *selection_grid, int direction_tribool) |
| Moves the selection vertically within the selection grid. | |
An implementation for a selection grid that handles directional selection.
The selection grid is not the same vertically and horizontally. It is divided into rows and each row defines its own callbacks for size, directional changes, and selection input. The idea is that it would be a more fitting simple solution for this game since it tends to be more dynamic horizontally than vertically with differing sizes of hands, jokers, etc.
Definition in file selection_grid.h.
| typedef int(* RowGetSizeFunc) () |
Function pointer type for retrieving the size of a row in a selection grid.
This is useful to allow generic row lengths e.g. when it can depend on the number of cards in hand, items in the shop, etc.
Definition at line 58 of file selection_grid.h.
| typedef void(* RowOnKeyTransitFunc) (SelectionGrid *selection_grid, Selection *selection) |
Callback function type for handling non-directional key presses in a selection grid row.
This function is invoked whenever a non-directional key transitions (either hit down or release up). The specific key and the type of transition (press/release) are not passed as parameters to the callback. Instead, the implementation must query the key state using functions like key_hit(), key_released(), etc. to determine which key triggered the event and its current state.
| selection_grid | Pointer to the SelectionGrid that contains the row receiving the key event |
| selection | Pointer to the Selection (row) that is handling the key transition. |
Definition at line 73 of file selection_grid.h.
| typedef bool(* RowOnSelectionChangedFunc) (SelectionGrid *selection_grid, int row_idx, const Selection *prev_selection, const Selection *new_selection) |
Callback function type for handling selection changes in a SelectionGrid.
This function is invoked whenever the selection cursor changes position within the grid. Used to perform custom actions based on selection changes, such as updating UI elements.
| selection_grid | Pointer to the SelectionGrid instance where the change occurred |
| row_idx | Index of the row associated with this callback. This can be used to determine whether this is the previously selected row or the newly selected row |
| prev_selection | Pointer to the Selection state before the change occurred. Contains the previous cursor position |
| new_selection | Pointer to the Selection state after the change occurred. Contains the new cursor position |
Definition at line 43 of file selection_grid.h.
| typedef POINT Selection |
Definition at line 18 of file selection_grid.h.
| typedef struct SelectionGrid SelectionGrid |
Definition at line 23 of file selection_grid.h.
| typedef struct SelectionGridRow SelectionGridRow |
Definition at line 22 of file selection_grid.h.
| void selection_grid_move_selection_horz | ( | SelectionGrid * | selection_grid, |
| int | direction_tribool | ||
| ) |
Moves the selection horizontally within the selection grid.
This function updates the current selection position by moving it horizontally based on the specified direction. This can be useful if some non-press event should update the selection grid.
| selection_grid | Pointer to the SelectionGrid structure to operate on. Must not be NULL. NULL-checks are in place and will return early. |
| direction_tribool | Direction indicator for horizontal movement behaving like tonc's tribools:
|
Definition at line 24 of file selection_grid.c.
| void selection_grid_move_selection_vert | ( | SelectionGrid * | selection_grid, |
| int | direction_tribool | ||
| ) |
Moves the selection vertically within the selection grid.
This function updates the current selection position by moving it vertically based on the specified direction. This can be useful if some non-press event should update the selection grid.
| selection_grid | Pointer to the SelectionGrid structure to operate on. Must not be NULL. NULL-checks are in place and will return early. |
| direction_tribool | Direction indicator for vertical movement behaving like tonc's tribools:
|
Definition at line 66 of file selection_grid.c.
| void selection_grid_process_input | ( | SelectionGrid * | selection_grid | ) |
Processes user input for the selection grid.
This function handles input events (such as directional controls and button presses) and updates the selection grid's state accordingly. It should be called each frame to respond to user interactions with the grid.
| selection_grid | Pointer to the SelectionGrid structure to process input for. Must not be NULL. NULL-checks are in place and will return early. |
Definition at line 116 of file selection_grid.c.