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-2024 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
81#ifndef GP_WIDGET_GRID_H
82#define GP_WIDGET_GRID_H
83
84#include <stdint.h>
85
95
96/* row/column cell sizes, offsets and fill coefs */
97struct gp_widget_grid_cell {
98 unsigned int size;
99 unsigned int off;
100 uint8_t fill;
101};
102
103/* row/column border padding and fill coefs */
104struct gp_widget_grid_border {
105 uint8_t padd;
106 uint8_t fill;
107};
108
109struct gp_widget_grid {
110 unsigned int cols, rows;
111
112 unsigned int focused_col;
113 unsigned int focused_row;
114
115 /* if set a widget in a grid is focused */
116 int focused:1;
117 /* if set frame is rendered around the grid */
118 int frame:1;
119 /* if set the grid all columns and all rows have the same size */
120 int uniform:1;
121
122 /* cell column sizes offsets and fill coefs */
123 struct gp_widget_grid_cell *col_s;
124 /* cell row sizes offsets and fill coefs */
125 struct gp_widget_grid_cell *row_s;
126
127 /* column border padding and fill coefs */
128 struct gp_widget_grid_border *col_b;
129 /* row border padding and fill coefs */
130 struct gp_widget_grid_border *row_b;
131
132 gp_widget **widgets;
133};
134
146gp_widget *gp_widget_grid_new(unsigned int cols, unsigned int rows,
147 enum gp_widget_grid_flags flags);
148
163gp_widget *gp_widget_grid_put(gp_widget *self, unsigned int col, unsigned int row,
164 gp_widget *child);
165
175gp_widget *gp_widget_grid_rem(gp_widget *self, unsigned int col, unsigned int row);
176
186gp_widget *gp_widget_grid_get(gp_widget *self, unsigned int col, unsigned int row);
187
195static inline void gp_widget_grid_del(gp_widget *self, unsigned col, unsigned int row)
196{
197 gp_widget *ret = gp_widget_grid_rem(self, col, row);
198
199 gp_widget_free(ret);
200}
201
209void gp_widget_grid_rows_ins(gp_widget *self, unsigned int row, unsigned int rows);
210
217static inline void gp_widget_grid_row_ins(gp_widget *self, unsigned int row)
218{
219 gp_widget_grid_rows_ins(self, row, 1);
220}
221
230unsigned int gp_widget_grid_rows_append(gp_widget *self, unsigned int rows);
231
239static inline unsigned int gp_widget_grid_row_append(gp_widget *self)
240{
241 return gp_widget_grid_rows_append(self, 1);
242}
243
250void gp_widget_grid_rows_prepend(gp_widget *self, unsigned int rows);
251
257static inline void gp_widget_grid_row_prepend(gp_widget *self)
258{
259 return gp_widget_grid_rows_prepend(self, 1);
260}
261
272void gp_widget_grid_rows_del(gp_widget *self, unsigned int row, unsigned int rows);
273
283static inline void gp_widget_grid_row_del(gp_widget *self, unsigned int row)
284{
285 gp_widget_grid_rows_del(self, row, 1);
286}
287
295void gp_widget_grid_cols_ins(gp_widget *self, unsigned int col, unsigned int cols);
296
303static inline void gp_widget_grid_col_ins(gp_widget *self, unsigned int col)
304{
305 gp_widget_grid_cols_ins(self, col, 1);
306}
307
316unsigned int gp_widget_grid_cols_append(gp_widget *self, unsigned int cols);
317
325static inline unsigned int gp_widget_grid_col_append(gp_widget *self)
326{
327 return gp_widget_grid_cols_append(self, 1);
328}
329
336void gp_widget_grid_cols_prepend(gp_widget *self, unsigned int cols);
337
343static inline void gp_widget_grid_col_prepend(gp_widget *self)
344{
345 return gp_widget_grid_cols_prepend(self, 1);
346}
347
358void gp_widget_grid_cols_del(gp_widget *self, unsigned int col, unsigned int cols);
359
369static inline void gp_widget_grid_col_del(gp_widget *self, unsigned int col)
370{
371 gp_widget_grid_cols_del(self, col, 1);
372}
373
374
384 int padd, int fill);
385
393static inline void gp_widget_grid_no_border(gp_widget *self)
394{
396}
397
411void gp_widget_grid_col_fill_set(gp_widget *self, unsigned int col, uint8_t fill);
412
426void gp_widget_grid_row_fill_set(gp_widget *self, unsigned int row, uint8_t fill);
427
428#endif /* GP_WIDGET_GRID_H */
void gp_widget_free(gp_widget *self)
Frees widget memory.
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.
gp_widget * gp_widget_grid_new(unsigned int cols, unsigned int rows, enum gp_widget_grid_flags flags)
Allocates and initializes a widget 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_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.
gp_widget_border
Describes borders.
@ GP_WIDGET_BORDER_ALL
All borders selected.
A widget base.
Definition gp_widget.h:28