Refactored to use selection grid during round (#348)

* Added wrapping to selection grid

* Added return value to on_selection_changed to allow aborting on wrap

* Extracted button code to button.c/.h

* Bounds checking changes for selection_grid_move_selection_horz()

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Rickey <ric@rf3.xyz>
This commit is contained in:
MeirGavish
2026-01-15 20:32:09 +02:00
committed by GitHub
co-authored by Copilot Rickey
parent b7cc3ec5d6
commit 5300846f73
5 changed files with 553 additions and 322 deletions
+39 -11
View File
@@ -23,22 +23,35 @@ static void selection_grid_process_directional_input(SelectionGrid* selection_gr
void selection_grid_move_selection_horz(SelectionGrid* selection_grid, int direction_tribool)
{
if (selection_grid == NULL)
if (selection_grid == NULL || selection_grid->selection.y < 0 ||
selection_grid->selection.y >= selection_grid->num_rows)
{
return;
}
Selection new_selection = selection_grid->selection;
new_selection.x += direction_tribool;
if (selection_grid->selection.y >= 0 &&
selection_grid->selection.y < selection_grid->num_rows && new_selection.x >= 0 &&
new_selection.x < selection_grid->rows[new_selection.y].get_size())
int row_size = selection_grid->rows[new_selection.y].get_size();
bool wrap_enabled = selection_grid->rows[new_selection.y].attributes.wrap;
if (wrap_enabled)
{
selection_grid->rows[new_selection.y].on_selection_changed(
new_selection.x = wrap(new_selection.x, 0, row_size);
}
if (wrap_enabled || (new_selection.x >= 0 && new_selection.x < row_size))
{
bool proceed_selection = selection_grid->rows[new_selection.y].on_selection_changed(
selection_grid,
new_selection.y,
&selection_grid->selection,
&new_selection
);
selection_grid->selection = new_selection;
if (proceed_selection)
{
selection_grid->selection = new_selection;
}
}
}
@@ -66,14 +79,29 @@ void selection_grid_move_selection_vert(SelectionGrid* selection_grid, int direc
// The operations are equivalent to fixed point if all the numbers were converted
new_selection.x = fx2int(selection.x * ((int2fx(new_row_size) / old_row_size)));
bool proceed_selection = true;
if (selection.y >= 0 && selection.y < selection_grid->num_rows)
{
selection_grid->rows[selection.y]
.on_selection_changed(selection_grid, selection.y, &selection, &new_selection);
proceed_selection =
selection_grid->rows[selection.y]
.on_selection_changed(selection_grid, selection.y, &selection, &new_selection);
}
if (proceed_selection)
{
proceed_selection = selection_grid->rows[new_selection.y].on_selection_changed(
selection_grid,
new_selection.y,
&selection,
&new_selection
);
}
if (proceed_selection)
{
selection_grid->selection = new_selection;
}
selection_grid->rows[new_selection.y]
.on_selection_changed(selection_grid, new_selection.y, &selection, &new_selection);
selection_grid->selection = new_selection;
}
}