14 unsigned int cols, rows;
15 unsigned int page_cells;
17 const struct gpf_ucode_block *block;
22static int geometry(
struct grid *self, gp_pixmap *p)
24 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
30 gpf_cell_init(&self->cell, ctx, 0);
32 self->cell.
bg = gpf_gui_back_color(gui.browser);
34 self->cols =
GPF_MAX(1u, p->w / self->cell.
w);
35 self->rows =
GPF_MAX(1u, p->h / self->cell.h);
36 self->page_cells = self->cols * self->rows;
38 gpf_cell_center(&self->cell, p, self->cols, self->rows);
41 self->first = gui.browser_page * self->page_cells;
48 gp_pixmap *p = gp_widget_pixmap_get(gui.browser);
56 idx = gpf_blocks_find(blocks, gui.code);
59 gpf_gui_sync_block(idx);
61 if (geometry(&grid, p))
64 if (gui.code < grid.block->min || gui.code > grid.block->max)
67 gui.browser_page = (gui.code - grid.block->min) / grid.page_cells;
70void gpf_browser_draw(gp_widget *self)
72 gp_pixmap *p = gp_widget_pixmap_get(self);
73 const gp_widget_render_ctx *ctx = gp_widgets_render_ctx();
80 gp_fill(p, gp_widgets_color(ctx, GP_WIDGETS_COL_BG));
85 if (gui.browser_follow) {
86 gui.browser_follow = 0;
90 if (geometry(&grid, p))
93 for (cell = 0; cell < grid.page_cells; cell++) {
94 uint32_t idx = grid.first + cell;
99 gpf_cell_draw(p, ctx, &grid.cell,
100 (cell % grid.cols) * grid.cell.w,
101 (cell / grid.cols) * grid.cell.h,
102 grid.block->min + idx);
105 gpf_cell_grid(p, ctx, &grid.cell, grid.cols,
106 (cell + grid.cols - 1) / grid.cols);
109static void redraw_browser(
void)
111 gpf_browser_draw(gui.browser);
112 gp_widget_redraw(gui.browser);
120static void move_sel(
int delta)
122 gp_pixmap *p = gp_widget_pixmap_get(gui.browser);
126 if (!p || geometry(&grid, p))
130 if (gui.code < grid.block->min || gui.code > grid.block->max)
131 idx = delta > 0 ? 0 : (long)grid.cnt - 1;
133 idx = (long)(gui.code - grid.block->min) + delta;
138 if (idx >= (
long)grid.cnt)
139 idx = (long)grid.cnt - 1;
141 gpf_gui_select(grid.block->min + idx);
149static void turn_page(
int delta)
151 gp_pixmap *p = gp_widget_pixmap_get(gui.browser);
153 long page = (long)gui.browser_page + delta;
156 if (!p || geometry(&grid, p))
159 pages = (grid.cnt + grid.page_cells - 1) / grid.page_cells;
161 if (page < 0 || page >= pages)
164 gui.browser_page = page;
169static void select_at(gp_coord x, gp_coord y)
171 gp_pixmap *p = gp_widget_pixmap_get(gui.browser);
176 if (!p || geometry(&grid, p))
179 cell = gpf_cell_at(&grid.cell, grid.cols, grid.rows, x, y);
183 idx = grid.first + cell;
186 gpf_gui_select(grid.block->min + idx);
189int gpf_browser_input(gp_event *ev)
191 gp_pixmap *p = gp_widget_pixmap_get(gui.browser);
193 unsigned int cols = 16, page = 128;
198 if (ev->type == GP_EV_REL && ev->code == GP_EV_REL_WHEEL) {
199 turn_page(ev->val < 0 ? 1 : -1);
203 if (ev->type != GP_EV_KEY || ev->code != GP_EV_KEY_DOWN)
206 if (p && !geometry(&grid, p)) {
208 page = grid.page_cells;
211 switch (ev->key.key) {
214 select_at(ev->st->cursor_x, ev->st->cursor_y);
231 case GP_KEY_PAGE_DOWN:
void gpf_browser_show_sel(void)
Turns the table to the selected glyph.
#define GPF_MAX(a, b)
Returns the larger of two values, evaluates them twice.
The editor state and the functions everything in the GUI goes through.
const struct gpf_ucode_block * gpf_gui_block(void)
The block being browsed.
const struct gpf_ucode_block * gpf_gui_blocks(void)
The block list, built on demand.
gp_pixel bg
The color the cells are drawn on, the selected one is highlighted instead.
unsigned int w
The cell size in pixels.
A unicode block description.
static uint32_t gpf_block_glyphs(const struct gpf_ucode_block *block)
Counts number of codepoints in a unicode block.