Table of Contents
include/nilorea/n_gui_grid.h
A virtualised grid of cells for N_GUI, scrolled vertically. More...
Structures
| Name | |
|---|---|
| struct | N_GUI_GRID_CALLBACKS What the grid asks of its caller. |
Detailed Description
A virtualised grid of cells for N_GUI, scrolled vertically.
Author: Castagnier Mickael
Version: 1.0
Date: 24/09/2026
An icon view: a file manager, an asset browser, a sprite picker. Cells of one size are laid out in as many columns as the width holds and as many rows as the count needs, and only the cells on screen are drawn, so ten thousand cells cost what thirty do.
The grid owns the geometry and the scrolling: the columns, the scroll offset (in pixels, so a view can stop anywhere, and clamped so it never shows past the end), the wheel (one row a notch), a vertical scrollbar it places beside itself and shows only when the rows do not fit, "scroll so this cell is visible", and which cell is under a point.
The caller owns everything that is about the content, through callbacks: what a cell looks like, including any cursor or selection it wants to show, what is drawn behind the cells or when there are none, what to prepare when a range becomes visible, and what a press on a cell does. Keys are the caller's too: move a cursor, then n_gui_grid_scroll_to().
Built on a custom widget with n_gui_custom_set_mouse() and n_gui_custom_set_destroy(); the grid's state is the widget's.
Source code
/*
* Nilorea Library
* Copyright (C) 2005-2026 Castagnier Mickael
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __NILOREA_GUI_GRID__
#define __NILOREA_GUI_GRID__
/* Allegro only: the grid is N_GUI widgets. */
#ifdef HAVE_ALLEGRO
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include "nilorea/n_gui.h"
typedef struct N_GUI_GRID_CALLBACKS {
void (*draw_cell)(int widget_id, size_t index, float x, float y, float w, float h, void* user_data);
void (*draw_background)(int widget_id, float x, float y, float w, float h, void* user_data);
void (*visible)(int widget_id, size_t first, size_t last, void* user_data);
void (*press)(int widget_id, size_t index, int button, float x, float y, void* user_data);
int (*wheel)(int widget_id, int dz, int modifiers, void* user_data);
} N_GUI_GRID_CALLBACKS;
int n_gui_grid_new(N_GUI_CTX* ctx, int window_id, const N_GUI_GRID_CALLBACKS* callbacks, void* user_data);
void n_gui_grid_set_rect(N_GUI_CTX* ctx, int widget_id, float x, float y, float w, float h, float bar_w);
void n_gui_grid_set_cell_size(N_GUI_CTX* ctx, int widget_id, float cell_w, float cell_h, float gap);
void n_gui_grid_set_count(N_GUI_CTX* ctx, int widget_id, size_t count);
void n_gui_grid_set_visible(N_GUI_CTX* ctx, int widget_id, int visible);
int n_gui_grid_columns(N_GUI_CTX* ctx, int widget_id);
float n_gui_grid_get_scroll(N_GUI_CTX* ctx, int widget_id);
void n_gui_grid_set_scroll(N_GUI_CTX* ctx, int widget_id, float scroll);
void n_gui_grid_scroll_to(N_GUI_CTX* ctx, int widget_id, size_t index);
int n_gui_grid_index_at(N_GUI_CTX* ctx, int widget_id, float x, float y, size_t* index);
int n_gui_grid_cell_rect(N_GUI_CTX* ctx, int widget_id, size_t index, float* x, float* y, float* w, float* h);
int n_gui_grid_scrollbar(N_GUI_CTX* ctx, int widget_id);
int n_gui_grid_scrollbar_showing(N_GUI_CTX* ctx, int widget_id);
#ifdef __cplusplus
}
#endif
#endif /* HAVE_ALLEGRO */
#endif /* __NILOREA_GUI_GRID__ */
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB