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
16#include <core/gp_compiler.h>
17
27
37typedef struct gp_widget_choice_ops {
46 const char *(*get_choice)(gp_widget *self, size_t idx);
56 size_t (*get)(gp_widget *self, enum gp_widget_choice_op op);
63 void (*set)(gp_widget *self, size_t sel);
65
70typedef struct gp_widget_choice_arr {
71 const void *ptr;
72 size_t memb_cnt;
73 uint16_t memb_size;
74 uint16_t memb_off;
76
77extern const gp_widget_choice_ops gp_widget_choice_arr_ops;
78
82typedef struct gp_widget_choice_desc {
83 const gp_widget_choice_ops *ops;
84 union {
85 void *ops_priv;
86 const char *const *choices;
88 };
90
91enum gp_widget_choice_flags {
92 GP_WIDGET_CHOICE_COPY = 1,
93};
94
95struct gp_widget_choice {
96 /* The actual widget data getters/setters */
97 const struct gp_widget_choice_ops *ops;
98
99 /*
100 * Optional storage for cnt and sel, can be utilized by the
101 * setters/getters from ops.
102 */
103 size_t cnt;
104 size_t sel;
105
106 /* Previously selected choice can be queried in the widget callback */
107 size_t prev_sel;
108
109 /* Pointer to a widget data */
110 union {
111 void *ops_priv;
112 char **choices;
113 struct gp_widget_choice_arr *arr;
114 };
115
116 char payload[] GP_ALIGNED;
117};
118
130 const char *choices[],
131 size_t cnt, size_t sel);
132
142 const struct gp_widget_choice_ops *ops);
143
144
160 const void *array,
161 size_t memb_cnt, uint16_t memb_size,
162 uint16_t memb_off, size_t sel,
163 enum gp_widget_choice_flags flags);
164
165
177
185
192void gp_widget_choice_sel_set(gp_widget *self, size_t sel);
193
202
214
223const char *gp_widget_choice_name_get(gp_widget *self, size_t idx);
224
232static inline const char *gp_widget_choice_sel_name_get(gp_widget *self)
233{
235}
236
248 gp_json_reader *json, gp_json_val *val,
249 gp_widget_json_ctx *ctx);
250
251#endif /* GP_WIDGET_CLASS_CHOICE_H */
A compiler dependent macros.
gp_widget_type
Widget types.
Definition gp_widget.h:173
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.
struct gp_widget_choice_ops gp_widget_choice_ops
A choice widget ops.
const char * gp_widget_choice_name_get(gp_widget *self, size_t idx)
Returns a choice value for a given index.
struct gp_widget_choice_arr gp_widget_choice_arr
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.
struct gp_widget_choice_desc gp_widget_choice_desc
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:29