GBAlatro
A Demake of Balatro for the GBA
Loading...
Searching...
No Matches
selection_grid.h File Reference

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.
 

Detailed Description

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 Documentation

◆ RowGetSizeFunc

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.

Returns
int The number of elements in the row.

Definition at line 58 of file selection_grid.h.

◆ RowOnKeyTransitFunc

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.

Parameters
selection_gridPointer to the SelectionGrid that contains the row receiving the key event
selectionPointer to the Selection (row) that is handling the key transition.

Definition at line 73 of file selection_grid.h.

◆ RowOnSelectionChangedFunc

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.

Parameters
selection_gridPointer to the SelectionGrid instance where the change occurred
row_idxIndex 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_selectionPointer to the Selection state before the change occurred. Contains the previous cursor position
new_selectionPointer to the Selection state after the change occurred. Contains the new cursor position
Returns
false if the selection change needs to be aborted, true if can proceed.

Definition at line 43 of file selection_grid.h.

◆ Selection

typedef POINT Selection

Definition at line 18 of file selection_grid.h.

◆ SelectionGrid

typedef struct SelectionGrid SelectionGrid

Definition at line 23 of file selection_grid.h.

◆ SelectionGridRow

Definition at line 22 of file selection_grid.h.

Function Documentation

◆ selection_grid_move_selection_horz()

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.

Parameters
selection_gridPointer to the SelectionGrid structure to operate on. Must not be NULL. NULL-checks are in place and will return early.
direction_triboolDirection indicator for horizontal movement behaving like tonc's tribools:
  • Negative value: move left
  • Zero: no movement
  • Positive value: move right

Definition at line 24 of file selection_grid.c.

◆ selection_grid_move_selection_vert()

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.

Parameters
selection_gridPointer to the SelectionGrid structure to operate on. Must not be NULL. NULL-checks are in place and will return early.
direction_triboolDirection indicator for vertical movement behaving like tonc's tribools:
  • Negative value: move up
  • Zero: no movement
  • Positive value: move down

Definition at line 66 of file selection_grid.c.

◆ selection_grid_process_input()

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.

Parameters
selection_gridPointer 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.