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

A JSON parser for widget layout. More...

#include <utils/gp_json.h>
#include <utils/gp_htable.h>
#include <widgets/gp_widget.h>

Go to the source code of this file.

Data Structures

struct  gp_widget_json_addr
 A structure to pass widget callbacks. More...
 
struct  gp_widget_json_callbacks
 Structure to pass callbacks to the JSON loader. More...
 
struct  gp_widget_json_ctx
 A context to propagate values top down and bottom up. More...
 

Typedefs

typedef struct gp_widget_json_addr gp_widget_json_addr
 A structure to pass widget callbacks.
 

Functions

gp_widgetgp_widget_from_json (gp_json_reader *json, gp_json_val *val, gp_widget_json_ctx *ctx)
 Loads a widget layout given a JSON object.
 
gp_widgetgp_widget_from_json_str (const char *str, const gp_widget_json_callbacks *const callbacks, gp_htable **uids)
 Loads a widget layout given a string with JSON layout.
 
gp_widgetgp_widget_layout_json (const char *fname, const gp_widget_json_callbacks *const callbacks, gp_htable **uids)
 Loads a widget layout given a path to a JSON layout description.
 
void * gp_widget_callback_addr (const char *fn_name, const gp_widget_json_ctx *ctx)
 Attempts to get a pointer to a function given it's name.
 
void * gp_widget_struct_addr (const char *struct_name, const gp_widget_json_ctx *ctx)
 Attempts to get a pointer to a structure given it's name.
 

Detailed Description

A JSON parser for widget layout.

Widget layout can be loaded from a JSON description. The application can resolve widgets by unique id and event handlers are resolved from the application binary at runtime.

Definition in file gp_widget_json.h.

Typedef Documentation

◆ gp_widget_json_addr

A structure to pass widget callbacks.

The pointers to application callbacks can either be resolved by the dynamic linker at runtime, or can be explicitly passed in this table. The table has to be sorted by id and NULL id terminted.

Example use:

static const gp_widget_json_addr app_callbacks[] = {
{.id = "abort", .on_event = abort_on_event},
{.id = "file_table", .table_col_ops = file_table_ops},
{}
};
A structure to pass widget callbacks.
const char * id
A callback name used to resolve the target widget on runtime.

Function Documentation

◆ gp_widget_callback_addr()

void * gp_widget_callback_addr ( const char *  fn_name,
const gp_widget_json_ctx ctx 
)

Attempts to get a pointer to a function given it's name.

This function is used to resolve callbacks from a JSON layout.

Parameters
fn_nameA fucntion name.
ctxA widget JSON loader context, usually passed from our caller.
Returns
A function pointer.

◆ gp_widget_from_json()

gp_widget * gp_widget_from_json ( gp_json_reader json,
gp_json_val val,
gp_widget_json_ctx ctx 
)

Loads a widget layout given a JSON object.

Parameters
jsonA json object.
valA json value.
ctxA widget JSON loader context, usually passed from our caller.
Returns
A widget layout or a NULL in case of a failure.

◆ gp_widget_from_json_str()

gp_widget * gp_widget_from_json_str ( const char *  str,
const gp_widget_json_callbacks *const  callbacks,
gp_htable **  uids 
)

Loads a widget layout given a string with JSON layout.

Parameters
strA string with a JSON layout.
callbacksAn optional NULL terminated array of application callbacks.
uidsA pointer to a hash table to store widget pointers by UIDs.
Returns
A widget layout or a NULL in case of a failure.

◆ gp_widget_layout_json()

gp_widget * gp_widget_layout_json ( const char *  fname,
const gp_widget_json_callbacks *const  callbacks,
gp_htable **  uids 
)

Loads a widget layout given a path to a JSON layout description.

Parameters
fnameA path to a JSON layout file.
callbacksAn optional NULL terminated array of application callbacks.
uidsA pointer to a hash table to store widget pointers by UIDs.
Returns
A widget layout or a NULL in case of a failure.

◆ gp_widget_struct_addr()

void * gp_widget_struct_addr ( const char *  struct_name,
const gp_widget_json_ctx ctx 
)

Attempts to get a pointer to a structure given it's name.

This function is used to resolve structures from a JSON layout.

Parameters
struct_nameA structure name.
ctxA widget JSON loader context, usually passed from our caller.
Returns
A structure pointer.