GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
gp_widget_class_choice.h File Reference

A choice class for widgets. More...

Go to the source code of this file.

Data Structures

struct  gp_widget_choice_ops
 A choice widget ops. More...
 
struct  gp_widget_choice_arr
 
struct  gp_widget_choice_desc
 

Typedefs

typedef struct gp_widget_choice_ops gp_widget_choice_ops
 A choice widget ops.
 
typedef struct gp_widget_choice_arr gp_widget_choice_arr
 
typedef struct gp_widget_choice_desc gp_widget_choice_desc
 

Enumerations

enum  gp_widget_choice_op { GP_WIDGET_CHOICE_OP_SEL , GP_WIDGET_CHOICE_OP_CNT }
 A choice op for the get callback. More...
 

Functions

gp_widgetgp_widget_choice_new (enum gp_widget_type widget_type, const char *choices[], size_t cnt, size_t sel)
 Allocates and initializes new choice widget.
 
gp_widgetgp_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.
 
gp_widgetgp_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_refresh (gp_widget *self)
 Request update after the choices has been changed.
 
size_t gp_widget_choice_cnt_get (gp_widget *self)
 Returns the number of choices to choose from.
 
void gp_widget_choice_sel_set (gp_widget *self, size_t sel)
 Sets a selected choice in the choice widget.
 
size_t gp_widget_choice_sel_get (gp_widget *self)
 Returns a selected choice.
 
size_t gp_widget_choice_prev_sel_get (gp_widget *self)
 Returns previously selected choice.
 
const char * gp_widget_choice_name_get (gp_widget *self, size_t idx)
 Returns a choice value for a given index.
 
static const char * gp_widget_choice_sel_name_get (gp_widget *self)
 Returns name of selected choice.
 
gp_widgetgp_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.
 

Detailed Description

A choice class for widgets.

Definition in file gp_widget_class_choice.h.

Typedef Documentation

◆ gp_widget_choice_arr

An array description to take the choices from along with ops to operate on the description.

◆ gp_widget_choice_desc

Choice description which could be passed to the JSON loader.

◆ gp_widget_choice_ops

A choice widget ops.

These are callbacks called by the widget implementation to get the choice values, selected choice and the number of choices.

The application needs to call gp_widget_choice_refresh() when the state changes, e.g. choice was added to or removed from the set.

Enumeration Type Documentation

◆ gp_widget_choice_op

A choice op for the get callback.

Enumerator
GP_WIDGET_CHOICE_OP_SEL 

Gets index of the selected choice.

GP_WIDGET_CHOICE_OP_CNT 

Gets the number of choices.

Definition at line 19 of file gp_widget_class_choice.h.

Function Documentation

◆ gp_widget_choice_arr_new()

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.

Parameters
widget_typeA widget type.
arrayA pointer an array.
memb_cntAn array size, i.e. number of elements.
memb_sizeAn array member size, e.g. sizeof(struct foo)
memb_offAn offset of the string for the choice in the array, e.g. offsetof(struct foo, str_elem)
selA selected choice.
flagsA bitwise combination of flags.
Returns
A choice widget.

Referenced by gp_widget_radiobutton_arr_new(), and gp_widget_spinbutton_arr_new().

◆ gp_widget_choice_cnt_get()

size_t gp_widget_choice_cnt_get ( gp_widget self)

Returns the number of choices to choose from.

Parameters
selfA choice widget.
Returns
A number of choices.

◆ gp_widget_choice_from_json()

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.

Parameters
widget_typeA widget type.
jsonA JSON widget.
valA JSON value.
ctxA widget JSON loader context.
Returns
A choice widget.

◆ gp_widget_choice_name_get()

const char * gp_widget_choice_name_get ( gp_widget self,
size_t  idx 
)

Returns a choice value for a given index.

Parameters
selfA choice widget.
idxAn choice index.
Returns
A choice value.

Referenced by gp_widget_choice_sel_name_get().

◆ gp_widget_choice_new()

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.

Parameters
widget_typeA widget type.
choicesAn array of strings describing available choices.
cntSize of the choices array.
selInitially selected choice.
Returns
A choice widget.

Referenced by gp_widget_radiobutton_new(), and gp_widget_spinbutton_new().

◆ gp_widget_choice_ops_new()

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.

Parameters
widget_typeA widget type.
opsA pointer to the widget ops.
Returns
A choice widget.

Referenced by gp_widget_radiobutton_ops_new(), and gp_widget_spinbutton_ops_new().

◆ gp_widget_choice_prev_sel_get()

size_t gp_widget_choice_prev_sel_get ( gp_widget self)

Returns previously selected choice.

The value is valid only after choice was changed from the UI, i.e. can be used in the widget event callback to get the previosly selected choice.

Parameters
selfA choice widget.
Returns
A previously selected choice.

◆ gp_widget_choice_refresh()

void gp_widget_choice_refresh ( gp_widget self)

Request update after the choices has been changed.

Causes the choice widget to be resized and rerendered. Since there are cases when the widget state is not stored in the widget, but rather feched by the gp_widget_choice_ops this call tells the widget to call the callback to refresh the state.

Parameters
selfA choice widget.

◆ gp_widget_choice_sel_get()

size_t gp_widget_choice_sel_get ( gp_widget self)

Returns a selected choice.

Parameters
selfA choice widget.
Returns
Currently selected choice widget.

Referenced by gp_widget_choice_sel_name_get().

◆ gp_widget_choice_sel_name_get()

static const char * gp_widget_choice_sel_name_get ( gp_widget self)
inlinestatic

Returns name of selected choice.

Parameters
selfA choice widget.
Returns
A selected choice name.

Definition at line 230 of file gp_widget_class_choice.h.

References gp_widget_choice_name_get(), and gp_widget_choice_sel_get().

◆ gp_widget_choice_sel_set()

void gp_widget_choice_sel_set ( gp_widget self,
size_t  sel 
)

Sets a selected choice in the choice widget.

Parameters
selfA choice widget.
selA choice to select.