GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_choice.h
1//SPDX-License-Identifier: LGPL-2.0-or-later
2
3/*
4
5 Copyright (c) 2014-2023 Cyril Hrubis <metan@ucw.cz>
6
7 */
8
9#ifndef GP_WIDGET_CHOICE_H
10#define GP_WIDGET_CHOICE_H
11
12enum gp_widget_choice_op {
13 GP_WIDGET_CHOICE_OP_SEL,
14 GP_WIDGET_CHOICE_OP_CNT,
15};
16
17typedef struct gp_widget_choice_ops {
18 const char *(*get_choice)(gp_widget *self, size_t idx);
19 size_t (*get)(gp_widget *self, enum gp_widget_choice_op op);
20 void (*set)(gp_widget *self, size_t val);
21} gp_widget_choice_ops;
22
27typedef struct gp_widget_choice_arr {
28 const void *ptr;
29 size_t memb_cnt;
30 uint16_t memb_size;
31 uint16_t memb_off;
33
34extern const gp_widget_choice_ops gp_widget_choice_arr_ops;
35
39typedef struct gp_widget_choice_desc {
40 const gp_widget_choice_ops *ops;
41 union {
42 void *ops_priv;
43 const char *const *choices;
45 };
47
48enum gp_widget_choice_flags {
49 GP_WIDGET_CHOICE_COPY = 1,
50};
51
52struct gp_widget_choice {
53 /* The actual widget data getters/setters */
54 const struct gp_widget_choice_ops *ops;
55
56 /*
57 * Optional storage for cnt and sel, can be utilized by the
58 * setters/getters from ops.
59 */
60 size_t cnt;
61 size_t sel;
62
63 /* Previously selected choice can be queried in the widget callback */
64 size_t prev_sel;
65
66 /* Pointer to a widget data */
67 union {
68 void *ops_priv;
69 char **choices;
70 struct gp_widget_choice_arr *arr;
71 };
72
73 char payload[];
74};
75
86gp_widget *gp_widget_choice_new(unsigned int widget_type,
87 const char *choices[],
88 size_t cnt, size_t sel);
89
98gp_widget *gp_widget_choice_ops_new(unsigned int widget_type,
99 const struct gp_widget_choice_ops *ops);
100
101
117gp_widget *gp_widget_choice_arr_new(unsigned int widget_type, const void *array,
118 size_t memb_cnt, uint16_t memb_size,
119 uint16_t memb_off, size_t sel, int flags);
120
128void gp_widget_choice_refresh(gp_widget *self);
129
136size_t gp_widget_choice_cnt_get(gp_widget *self);
137
144void gp_widget_choice_sel_set(gp_widget *self, size_t sel);
145
152size_t gp_widget_choice_sel_get(gp_widget *self);
153
163size_t gp_widget_choice_prev_sel_get(gp_widget *self);
164
173const char *gp_widget_choice_name_get(gp_widget *self, size_t idx);
174
180static inline const char *gp_widget_choice_sel_name_get(gp_widget *self)
181{
182 return gp_widget_choice_name_get(self, gp_widget_choice_sel_get(self));
183}
184
194gp_widget *gp_widget_choice_from_json(unsigned int widget_type,
195 gp_json_reader *json, gp_json_val *val,
196 gp_widget_json_ctx *ctx);
197
198#endif /* GP_WIDGET_CHOICE_H */
A JSON parser internal state.
A parsed JSON key value pair.
A context to propagate values top down and bottom up.