![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
A virtualised grid of cells for N_GUI, scrolled vertically. More...
#include <math.h>#include <stdlib.h>#include <string.h>#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_gui_grid.h"Go to the source code of this file.
Data Structures | |
| struct | _N_GUI_GRID |
| a grid's state, owned by its custom widget More... | |
Functions | |
| static void | _grid_clamp (_N_GUI_GRID *g) |
| helper: keep the view inside the content | |
| static int | _grid_columns_for (const _N_GUI_GRID *g, float w) |
| helper: cells across a width | |
| static float | _grid_content_h_for (const _N_GUI_GRID *g, float w) |
| helper: content height at a width: the gap above the first row, then each row with its gap | |
| static void | _grid_destroy (void *user_data) |
| the widget's destroy callback. | |
| static void | _grid_draw (N_GUI_WIDGET *widget, float x, float y, ALLEGRO_FONT *font, void *user_data) |
| custom draw callback | |
| static int | _grid_index_local (const _N_GUI_GRID *g, float w, float lx, float ly, size_t *index) |
| helper: the cell at a widget-local point, the rules of n_gui_grid_index_at | |
| static int | _grid_mouse (int widget_id, const N_GUI_MOUSE_EVENT *ev, void *user_data) |
| custom mouse callback | |
| static _N_GUI_GRID * | _grid_of (N_GUI_CTX *ctx, int widget_id) |
| helper: find a grid's state behind a widget id, or NULL | |
| static void | _grid_on_bar (int widget_id, double pos, void *user_data) |
| the scrollbar's callback: the view follows a drag of the bar | |
| static void | _grid_place (_N_GUI_GRID *g) |
| helper: decide whether the bar shows, and place the grid and the bar | |
| static size_t | _grid_rows_for (const _N_GUI_GRID *g, int columns) |
| helper: rows the cells make at a column count | |
| static float | _grid_step (const _N_GUI_GRID *g) |
| helper: one row and the gap below it | |
| static void | _grid_sync_bar (_N_GUI_GRID *g) |
| helper: tell the scrollbar where the view is | |
| 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. | |
| int | n_gui_grid_columns (N_GUI_CTX *ctx, int widget_id) |
| How many cells a row holds at the grid's width. | |
| float | n_gui_grid_get_scroll (N_GUI_CTX *ctx, int widget_id) |
| The scroll offset, in pixels from the top of the content. | |
| 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. | |
| 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. | |
| 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. | |
| int | n_gui_grid_scrollbar (N_GUI_CTX *ctx, int widget_id) |
| The grid's scrollbar widget. | |
| int | n_gui_grid_scrollbar_showing (N_GUI_CTX *ctx, int widget_id) |
| Whether the scrollbar is shown, which is whether the rows overflow. | |
| 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. | |
| void | n_gui_grid_set_count (N_GUI_CTX *ctx, int widget_id, size_t count) |
| Set how many cells there are. | |
| 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. | |
| void | n_gui_grid_set_scroll (N_GUI_CTX *ctx, int widget_id, float scroll) |
| Set the scroll offset, clamped to the content. | |
| void | n_gui_grid_set_visible (N_GUI_CTX *ctx, int widget_id, int visible) |
| Show or hide the grid and its scrollbar together. | |
A virtualised grid of cells for N_GUI, scrolled vertically.
Definition in file n_gui_grid.c.
| struct _N_GUI_GRID |
a grid's state, owned by its custom widget
Definition at line 39 of file n_gui_grid.c.
| Data Fields | ||
|---|---|---|
| int | bar | its scrollbar |
| int | bar_showing | whether the bar is shown |
| float | bar_w | width of the scrollbar's strip |
| N_GUI_GRID_CALLBACKS | cb | what the caller asked for |
| float | cell_h | cell height |
| float | cell_w | cell width |
| size_t | count | how many cells |
| N_GUI_CTX * | ctx | the context, for the callbacks that are handed only an id |
| float | gap | gap between and around cells |
| int | id | the grid widget |
| float | inner_w | the grid's own width, the strip taken off when the bar shows |
| float | outer_h | |
| float | outer_w | |
| float | outer_x | the rectangle n_gui_grid_set_rect() was given, scrollbar included |
| float | outer_y | |
| int | placing | set while the bar is being told where it is, so its callback is not taken for a drag |
| float | scroll | pixels from the top of the content to the top of the view |
| void * | user_data | handed back to the callbacks |
| int | visible | whether the caller wants it shown |
|
static |
helper: keep the view inside the content
Definition at line 99 of file n_gui_grid.c.
References _grid_content_h_for(), _N_GUI_GRID::inner_w, _N_GUI_GRID::outer_h, and _N_GUI_GRID::scroll.
Referenced by _grid_mouse(), _grid_on_bar(), _grid_place(), n_gui_grid_scroll_to(), and n_gui_grid_set_scroll().
|
static |
helper: cells across a width
Definition at line 76 of file n_gui_grid.c.
References _N_GUI_GRID::cell_w, and _N_GUI_GRID::gap.
Referenced by _grid_content_h_for(), _grid_draw(), _grid_index_local(), n_gui_grid_cell_rect(), n_gui_grid_columns(), and n_gui_grid_scroll_to().
|
static |
helper: content height at a width: the gap above the first row, then each row with its gap
Definition at line 94 of file n_gui_grid.c.
References _grid_columns_for(), _grid_rows_for(), _grid_step(), and _N_GUI_GRID::gap.
Referenced by _grid_clamp(), _grid_place(), and _grid_sync_bar().
|
static |
the widget's destroy callback.
The scrollbar is a widget of the same window and is only ever destroyed with it, by n_gui_destroy_ctx(), which calls no scrollbar callback, so nothing reaches the state once it is freed.
Definition at line 265 of file n_gui_grid.c.
Referenced by n_gui_grid_new().
|
static |
custom draw callback
Definition at line 144 of file n_gui_grid.c.
References _grid_columns_for(), _grid_rows_for(), _grid_step(), _N_GUI_GRID::cb, _N_GUI_GRID::cell_h, _N_GUI_GRID::cell_w, _N_GUI_GRID::count, N_GUI_GRID_CALLBACKS::draw_background, N_GUI_GRID_CALLBACKS::draw_cell, font, _N_GUI_GRID::gap, N_GUI_WIDGET::h, _N_GUI_GRID::id, last, row(), _N_GUI_GRID::scroll, _N_GUI_GRID::user_data, N_GUI_GRID_CALLBACKS::visible, and N_GUI_WIDGET::w.
Referenced by _grid_of(), and n_gui_grid_new().
|
static |
helper: the cell at a widget-local point, the rules of n_gui_grid_index_at
Definition at line 199 of file n_gui_grid.c.
References _grid_columns_for(), _grid_step(), _N_GUI_GRID::cell_w, _N_GUI_GRID::count, _N_GUI_GRID::gap, row(), and _N_GUI_GRID::scroll.
Referenced by _grid_mouse(), and n_gui_grid_index_at().
|
static |
custom mouse callback
Definition at line 217 of file n_gui_grid.c.
References _grid_clamp(), _grid_index_local(), _grid_step(), _grid_sync_bar(), N_GUI_MOUSE_EVENT::button, _N_GUI_GRID::cb, _N_GUI_GRID::ctx, N_GUI_MOUSE_EVENT::dz, N_GUI_MOUSE_EVENT::modifiers, n_gui_get_widget(), n_gui_mark_dirty(), N_GUI_MOUSE_DOWN, N_GUI_MOUSE_WHEEL, n_gui_widget_screen_rect(), N_GUI_GRID_CALLBACKS::press, _N_GUI_GRID::scroll, N_GUI_MOUSE_EVENT::type, _N_GUI_GRID::user_data, N_GUI_WIDGET::w, N_GUI_GRID_CALLBACKS::wheel, N_GUI_MOUSE_EVENT::x, and N_GUI_MOUSE_EVENT::y.
Referenced by n_gui_grid_new().
|
static |
helper: find a grid's state behind a widget id, or NULL
Definition at line 270 of file n_gui_grid.c.
References _grid_draw(), N_GUI_WIDGET::data, N_GUI_CUSTOM_DATA::draw, n_gui_get_widget(), N_GUI_TYPE_CUSTOM, N_GUI_WIDGET::type, and N_GUI_CUSTOM_DATA::user_data.
Referenced by n_gui_grid_cell_rect(), n_gui_grid_columns(), n_gui_grid_get_scroll(), n_gui_grid_index_at(), n_gui_grid_scroll_to(), n_gui_grid_scrollbar(), n_gui_grid_scrollbar_showing(), n_gui_grid_set_cell_size(), n_gui_grid_set_count(), n_gui_grid_set_rect(), n_gui_grid_set_scroll(), and n_gui_grid_set_visible().
|
static |
the scrollbar's callback: the view follows a drag of the bar
Definition at line 249 of file n_gui_grid.c.
References _grid_clamp(), _N_GUI_GRID::ctx, n_gui_mark_dirty(), _N_GUI_GRID::placing, and _N_GUI_GRID::scroll.
Referenced by n_gui_grid_new().
|
static |
helper: decide whether the bar shows, and place the grid and the bar
Definition at line 117 of file n_gui_grid.c.
References _grid_clamp(), _grid_content_h_for(), _grid_sync_bar(), _N_GUI_GRID::bar, _N_GUI_GRID::bar_showing, _N_GUI_GRID::bar_w, _N_GUI_GRID::count, _N_GUI_GRID::ctx, _N_GUI_GRID::id, _N_GUI_GRID::inner_w, n_gui_mark_dirty(), n_gui_set_widget_visible(), n_gui_widget_set_rect(), _N_GUI_GRID::outer_h, _N_GUI_GRID::outer_w, _N_GUI_GRID::outer_x, _N_GUI_GRID::outer_y, _N_GUI_GRID::scroll, and _N_GUI_GRID::visible.
Referenced by n_gui_grid_set_cell_size(), n_gui_grid_set_count(), and n_gui_grid_set_rect().
|
static |
helper: rows the cells make at a column count
Definition at line 83 of file n_gui_grid.c.
References _N_GUI_GRID::count.
Referenced by _grid_content_h_for(), and _grid_draw().
|
static |
helper: one row and the gap below it
Definition at line 88 of file n_gui_grid.c.
References _N_GUI_GRID::cell_h, and _N_GUI_GRID::gap.
Referenced by _grid_content_h_for(), _grid_draw(), _grid_index_local(), _grid_mouse(), n_gui_grid_cell_rect(), and n_gui_grid_scroll_to().
|
static |
helper: tell the scrollbar where the view is
Definition at line 108 of file n_gui_grid.c.
References _grid_content_h_for(), _N_GUI_GRID::bar, _N_GUI_GRID::bar_showing, _N_GUI_GRID::ctx, _N_GUI_GRID::inner_w, n_gui_scrollbar_set_pos(), n_gui_scrollbar_set_sizes(), _N_GUI_GRID::outer_h, _N_GUI_GRID::placing, and _N_GUI_GRID::scroll.
Referenced by _grid_mouse(), _grid_place(), n_gui_grid_scroll_to(), and n_gui_grid_set_scroll().