GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_widget_class_choice.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
13#ifndef GP_WIDGET_CLASS_CHOICE_H
14#define GP_WIDGET_CLASS_CHOICE_H
15
25
35typedef struct gp_widget_choice_ops {
44 const char *(*get_choice)(gp_widget *self, size_t idx);
54 size_t (*get)(gp_widget *self, enum gp_widget_choice_op op);
61 void (*set)(gp_widget *self, size_t sel);
63
68typedef struct gp_widget_choice_arr {
69 const void *ptr;
70 size_t memb_cnt;
71 uint16_t memb_size;
72 uint16_t memb_off;
74
75extern const gp_widget_choice_ops gp_widget_choice_arr_ops;
76
80typedef struct gp_widget_choice_desc {
81 const gp_widget_choice_ops *ops;
82 union {
83 void *ops_priv;
84 const char *const *choices;
86 };
88
89enum gp_widget_choice_flags {
90 GP_WIDGET_CHOICE_COPY = 1,
91};
92
93struct gp_widget_choice {
94 /* The actual widget data getters/setters */
95 const struct gp_widget_choice_ops *ops;
96
97 /*
98 * Optional storage for cnt and sel, can be utilized by the
99 * setters/getters from ops.
100 */
101 size_t cnt;
102 size_t sel;
103
104 /* Previously selected choice can be queried in the widget callback */
105 size_t prev_sel;
106
107 /* Pointer to a widget data */
108 union {
109 void *ops_priv;
110 char **choices;
111 struct gp_widget_choice_arr *arr;
112 };
113
114 char payload[];
115};
116
128 const char *choices[],
129 size_t cnt, size_t sel);
130
140 const struct gp_widget_choice_ops *ops);
141
142
158 const void *array,
159 size_t memb_cnt, uint16_t memb_size,
160 uint16_t memb_off, size_t sel,
161 enum gp_widget_choice_flags flags);
162
163
175
183
190void gp_widget_choice_sel_set(gp_widget *self, size_t sel);
191
200
212
221const char *gp_widget_choice_name_get(gp_widget *self, size_t idx);
222
230static inline const char *gp_widget_choice_sel_name_get(gp_widget *self)
231{
233}
234
246 gp_json_reader *json, gp_json_val *val,
247 gp_widget_json_ctx *ctx);
248
249#endif /* GP_WIDGET_CLASS_CHOICE_H */
gp_widget_type
Widget types.
Definition gp_widget.h:197
gp_widget * gp_widget_choice_from_json(enum gp_widget_type widget_type, gp_json_reader *json, gp_json_val *val, gp_widget_json_ctx *ctx)
Parses JSON into a choice widget.
gp_widget * gp_widget_choice_new(enum gp_widget_type widget_type, const char *choices[], size_t cnt, size_t sel)
Allocates and initializes new choice widget.
static const char * gp_widget_choice_sel_name_get(gp_widget *self)
Returns name of selected choice.
const char * gp_widget_choice_name_get(gp_widget *self, size_t idx)
Returns a choice value for a given index.
size_t gp_widget_choice_prev_sel_get(gp_widget *self)
Returns previously selected choice.
size_t gp_widget_choice_sel_get(gp_widget *self)
Returns a selected choice.
gp_widget * gp_widget_choice_arr_new(enum gp_widget_type widget_type, const void *array, size_t memb_cnt, uint16_t memb_size, uint16_t memb_off, size_t sel, enum gp_widget_choice_flags flags)
Creates a choice widget based on a static array.
void gp_widget_choice_sel_set(gp_widget *self, size_t sel)
Sets a selected choice in the choice widget.
void gp_widget_choice_refresh(gp_widget *self)
Request update after the choices has been changed.
gp_widget_choice_op
A choice op for the get callback.
@ GP_WIDGET_CHOICE_OP_CNT
Gets the number of choices.
@ GP_WIDGET_CHOICE_OP_SEL
Gets index of the selected choice.
size_t gp_widget_choice_cnt_get(gp_widget *self)
Returns the number of choices to choose from.
gp_widget * gp_widget_choice_ops_new(enum gp_widget_type widget_type, const struct gp_widget_choice_ops *ops)
Creates a choice widget based on widget ops.
A JSON parser internal state.
A parsed JSON key value pair.
size_t(* get)(gp_widget *self, enum gp_widget_choice_op op)
Returns a selected choice or number of choices.
void(* set)(gp_widget *self, size_t sel)
Sets the selected choice.
A context to propagate values top down and bottom up.
A widget base.
Definition gp_widget.h:28