Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_gui_grid.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
48
49#ifndef __NILOREA_GUI_GRID__
50#define __NILOREA_GUI_GRID__
51
52/* Allegro only: the grid is N_GUI widgets. */
53#ifdef HAVE_ALLEGRO
54
55#ifdef __cplusplus
56extern "C" {
57#endif
58
63
64#include <stddef.h>
65
66#include "nilorea/n_gui.h"
67
69typedef struct N_GUI_GRID_CALLBACKS {
72 void (*draw_cell)(int widget_id, size_t index, float x, float y, float w, float h, void* user_data);
75 void (*draw_background)(int widget_id, float x, float y, float w, float h, void* user_data);
78 void (*visible)(int widget_id, size_t first, size_t last, void* user_data);
81 void (*press)(int widget_id, size_t index, int button, float x, float y, void* user_data);
87 int (*wheel)(int widget_id, int dz, int modifiers, void* user_data);
89
102int n_gui_grid_new(N_GUI_CTX* ctx, int window_id, const N_GUI_GRID_CALLBACKS* callbacks, void* user_data);
103
120void n_gui_grid_set_rect(N_GUI_CTX* ctx, int widget_id, float x, float y, float w, float h, float bar_w);
121
134void n_gui_grid_set_cell_size(N_GUI_CTX* ctx, int widget_id, float cell_w, float cell_h, float gap);
135
143void n_gui_grid_set_count(N_GUI_CTX* ctx, int widget_id, size_t count);
144
152void n_gui_grid_set_visible(N_GUI_CTX* ctx, int widget_id, int visible);
153
162int n_gui_grid_columns(N_GUI_CTX* ctx, int widget_id);
163
172float n_gui_grid_get_scroll(N_GUI_CTX* ctx, int widget_id);
173
181void n_gui_grid_set_scroll(N_GUI_CTX* ctx, int widget_id, float scroll);
182
190void n_gui_grid_scroll_to(N_GUI_CTX* ctx, int widget_id, size_t index);
191
206int n_gui_grid_index_at(N_GUI_CTX* ctx, int widget_id, float x, float y, size_t* index);
207
222int n_gui_grid_cell_rect(N_GUI_CTX* ctx, int widget_id, size_t index, float* x, float* y, float* w, float* h);
223
232int n_gui_grid_scrollbar(N_GUI_CTX* ctx, int widget_id);
233
242int n_gui_grid_scrollbar_showing(N_GUI_CTX* ctx, int widget_id);
243
245
246#ifdef __cplusplus
247}
248#endif
249#endif /* HAVE_ALLEGRO */
250#endif /* __NILOREA_GUI_GRID__ */
static N_GUI_MOUSE_EVENT last
the last event the widget was told of, and how many
static void visible(int widget_id, size_t first, size_t last, void *user_data)
the range to prepare
Definition ex_gui_grid.c:86
The top-level GUI context that holds all windows.
Definition n_gui.h:1669
void(* draw_background)(int widget_id, float x, float y, float w, float h, void *user_data)
Draw behind the cells, over the whole grid, before any cell; with no cells, the only thing drawn.
Definition n_gui_grid.h:75
void(* press)(int widget_id, size_t index, int button, float x, float y, void *user_data)
A press of button (1 or 2) on cell index, at screen x, y.
Definition n_gui_grid.h:81
void(* draw_cell)(int widget_id, size_t index, float x, float y, float w, float h, void *user_data)
Draw cell index in the box at x, y, w by h, on screen.
Definition n_gui_grid.h:72
int(* wheel)(int widget_id, int dz, int modifiers, void *user_data)
A wheel turn of dz notches over the grid, positive away from the user, with the modifier keys held (A...
Definition n_gui_grid.h:87
void(* visible)(int widget_id, size_t first, size_t last, void *user_data)
Called after each draw with the cells drawn and one row beyond, first included and last excluded: wha...
Definition n_gui_grid.h:78
void n_gui_grid_set_rect(N_GUI_CTX *ctx, int widget_id, float x, float y, float w, float h, float bar_w)
Place the grid and its scrollbar in a rectangle of the window.
Definition n_gui_grid.c:321
void n_gui_grid_set_scroll(N_GUI_CTX *ctx, int widget_id, float scroll)
Set the scroll offset, clamped to the content.
Definition n_gui_grid.c:373
int n_gui_grid_new(N_GUI_CTX *ctx, int window_id, const N_GUI_GRID_CALLBACKS *callbacks, void *user_data)
Add a grid, and its scrollbar, to a window.
Definition n_gui_grid.c:281
int n_gui_grid_index_at(N_GUI_CTX *ctx, int widget_id, float x, float y, size_t *index)
Which cell is at a point on screen.
Definition n_gui_grid.c:400
void n_gui_grid_set_count(N_GUI_CTX *ctx, int widget_id, size_t count)
Set how many cells there are.
Definition n_gui_grid.c:343
int n_gui_grid_columns(N_GUI_CTX *ctx, int widget_id)
How many cells a row holds at the grid's width.
Definition n_gui_grid.c:361
int n_gui_grid_cell_rect(N_GUI_CTX *ctx, int widget_id, size_t index, float *x, float *y, float *w, float *h)
Where a cell is on screen, whether or not it is scrolled into view.
Definition n_gui_grid.c:411
void n_gui_grid_scroll_to(N_GUI_CTX *ctx, int widget_id, size_t index)
Scroll the least that brings a cell's whole row into view.
Definition n_gui_grid.c:383
int n_gui_grid_scrollbar_showing(N_GUI_CTX *ctx, int widget_id)
Whether the scrollbar is shown, which is whether the rows overflow.
Definition n_gui_grid.c:434
float n_gui_grid_get_scroll(N_GUI_CTX *ctx, int widget_id)
The scroll offset, in pixels from the top of the content.
Definition n_gui_grid.c:367
void n_gui_grid_set_cell_size(N_GUI_CTX *ctx, int widget_id, float cell_w, float cell_h, float gap)
Set the size of a cell and the gap around cells.
Definition n_gui_grid.c:333
void n_gui_grid_set_visible(N_GUI_CTX *ctx, int widget_id, int visible)
Show or hide the grid and its scrollbar together.
Definition n_gui_grid.c:351
int n_gui_grid_scrollbar(N_GUI_CTX *ctx, int widget_id)
The grid's scrollbar widget.
Definition n_gui_grid.c:428
What the grid asks of its caller.
Definition n_gui_grid.h:69
GUI system: buttons, sliders, text areas, checkboxes, scrollbars, dropdown menus, windows.