GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_grid.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2021 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
17#ifndef GP_WIDGET_GRID_H
18#define GP_WIDGET_GRID_H
19
20#include <stdint.h>
21
31
32/* row/column cell sizes, offsets and fill coefs */
33struct gp_widget_grid_cell {
34 unsigned int size;
35 unsigned int off;
36 uint8_t fill;
37};
38
39/* row/column border padding and fill coefs */
40struct gp_widget_grid_border {
41 uint8_t padd;
42 uint8_t fill;
43};
44
45struct gp_widget_grid {
46 unsigned int cols, rows;
47
48 unsigned int focused_col;
49 unsigned int focused_row;
50
51 /* if set a widget in a grid is focused */
52 int focused:1;
53 /* if set frame is rendered around the grid */
54 int frame:1;
55 /* if set the grid all columns and all rows have the same size */
56 int uniform:1;
57
58 /* cell column sizes offsets and fill coefs */
59 struct gp_widget_grid_cell *col_s;
60 /* cell row sizes offsets and fill coefs */
61 struct gp_widget_grid_cell *row_s;
62
63 /* column border padding and fill coefs */
64 struct gp_widget_grid_border *col_b;
65 /* row border padding and fill coefs */
66 struct gp_widget_grid_border *row_b;
67
68 gp_widget **widgets;
69};
70
80gp_widget *gp_widget_grid_new(unsigned int cols, unsigned int rows, int flags);
81
92gp_widget *gp_widget_grid_put(gp_widget *self, unsigned int col, unsigned int row,
93 gp_widget *child);
94
104gp_widget *gp_widget_grid_rem(gp_widget *self, unsigned int col, unsigned int row);
105
115gp_widget *gp_widget_grid_get(gp_widget *self, unsigned int col, unsigned int row);
116
124static inline void gp_widget_grid_del(gp_widget *self, unsigned col, unsigned int row)
125{
126 gp_widget *ret = gp_widget_grid_rem(self, col, row);
127
128 gp_widget_free(ret);
129}
130
138void gp_widget_grid_rows_ins(gp_widget *self, unsigned int row, unsigned int rows);
139
146static inline void gp_widget_grid_row_ins(gp_widget *self, unsigned int row)
147{
148 gp_widget_grid_rows_ins(self, row, 1);
149}
150
159unsigned int gp_widget_grid_rows_append(gp_widget *self, unsigned int rows);
160
168static inline unsigned int gp_widget_grid_row_append(gp_widget *self)
169{
170 return gp_widget_grid_rows_append(self, 1);
171}
172
179void gp_widget_grid_rows_prepend(gp_widget *self, unsigned int rows);
180
186static inline void gp_widget_grid_row_prepend(gp_widget *self)
187{
188 return gp_widget_grid_rows_prepend(self, 1);
189}
190
201void gp_widget_grid_rows_del(gp_widget *self, unsigned int row, unsigned int rows);
202
212static inline void gp_widget_grid_row_del(gp_widget *self, unsigned int row)
213{
214 gp_widget_grid_rows_del(self, row, 1);
215}
216
224void gp_widget_grid_cols_ins(gp_widget *self, unsigned int col, unsigned int cols);
225
232static inline void gp_widget_grid_col_ins(gp_widget *self, unsigned int col)
233{
234 gp_widget_grid_cols_ins(self, col, 1);
235}
236
245unsigned int gp_widget_grid_cols_append(gp_widget *self, unsigned int cols);
246
254static inline unsigned int gp_widget_grid_col_append(gp_widget *self)
255{
256 return gp_widget_grid_cols_append(self, 1);
257}
258
265void gp_widget_grid_cols_prepend(gp_widget *self, unsigned int cols);
266
272static inline void gp_widget_grid_col_prepend(gp_widget *self)
273{
274 return gp_widget_grid_cols_prepend(self, 1);
275}
276
287void gp_widget_grid_cols_del(gp_widget *self, unsigned int col, unsigned int cols);
288
298static inline void gp_widget_grid_col_del(gp_widget *self, unsigned int col)
299{
300 gp_widget_grid_cols_del(self, col, 1);
301}
302
303
312void gp_widget_grid_border_set(gp_widget *self, enum gp_widget_border border,
313 int padd, int fill);
314
322static inline void gp_widget_grid_no_border(gp_widget *self)
323{
324 gp_widget_grid_border_set(self, GP_WIDGET_BORDER_ALL, 0, 0);
325}
326
334void gp_widget_grid_col_fill_set(gp_widget *self, unsigned int col, uint8_t fill);
335
343void gp_widget_grid_row_fill_set(gp_widget *self, unsigned int row, uint8_t fill);
344
345#endif /* GP_WIDGET_GRID_H */
static void gp_widget_grid_row_prepend(gp_widget *self)
Prepends a new (empty) row at the top of the grid.
gp_widget * gp_widget_grid_put(gp_widget *self, unsigned int col, unsigned int row, gp_widget *child)
Puts a child widget into a frame widget.
void gp_widget_grid_rows_ins(gp_widget *self, unsigned int row, unsigned int rows)
Inserts new (empty) rows to the grid.
void gp_widget_grid_cols_prepend(gp_widget *self, unsigned int cols)
Prepends a new (empty) columns at the left side of the grid.
void gp_widget_grid_rows_del(gp_widget *self, unsigned int row, unsigned int rows)
Delete rows from the grid.
void gp_widget_grid_cols_ins(gp_widget *self, unsigned int col, unsigned int cols)
Inserts new (empty) columns to the grid.
unsigned int gp_widget_grid_rows_append(gp_widget *self, unsigned int rows)
Appends a new (empty) rows at the bottom of the grid.
static void gp_widget_grid_col_del(gp_widget *self, unsigned int col)
Delete column from the grid.
static void gp_widget_grid_del(gp_widget *self, unsigned col, unsigned int row)
Deletes a child widget at col, row from a grid.
static void gp_widget_grid_row_ins(gp_widget *self, unsigned int row)
Inserts new (empty) row to the grid.
static unsigned int gp_widget_grid_col_append(gp_widget *self)
Appends a new (empty) colum at the right side of the grid.
gp_widget * gp_widget_grid_new(unsigned int cols, unsigned int rows, int flags)
Allocates and initializes a widget grid.
gp_widget_grid_flags
A widget grid flags.
@ GP_WIDGET_GRID_FRAME
@ GP_WIDGET_GRID_UNIFORM
static void gp_widget_grid_col_ins(gp_widget *self, unsigned int col)
Inserts new (empty) column to the grid.
void gp_widget_grid_rows_prepend(gp_widget *self, unsigned int rows)
Prepends a new (empty) rows at the top of the grid.
static void gp_widget_grid_col_prepend(gp_widget *self)
Prepends a new (empty) column at the left side of the grid.
void gp_widget_grid_col_fill_set(gp_widget *self, unsigned int col, uint8_t fill)
Sets grid cell column fill coeficient.
static void gp_widget_grid_no_border(gp_widget *self)
Disables grid padd and fill.
static unsigned int gp_widget_grid_row_append(gp_widget *self)
Appends a new (empty) row at the bottom of the grid.
unsigned int gp_widget_grid_cols_append(gp_widget *self, unsigned int cols)
Appends a new (empty) colums at the right side of the grid.
gp_widget * gp_widget_grid_rem(gp_widget *self, unsigned int col, unsigned int row)
Removes child widget at col, row from a grid.
void gp_widget_grid_row_fill_set(gp_widget *self, unsigned int row, uint8_t fill)
Sets grid cell row fill coeficient.
gp_widget * gp_widget_grid_get(gp_widget *self, unsigned int col, unsigned int row)
Returns a pointer to a widget at col, row.
void gp_widget_grid_cols_del(gp_widget *self, unsigned int col, unsigned int cols)
Delete columns from the grid.
static void gp_widget_grid_row_del(gp_widget *self, unsigned int row)
Removes row from the grid.
void gp_widget_grid_border_set(gp_widget *self, enum gp_widget_border border, int padd, int fill)
Sets border padd or fill coeficients.