Browse Source

example: added checkbox example

pull/1/head
Leonard Ritter 10 years ago
parent
commit
0950220fc3
1 changed files with 46 additions and 0 deletions
  1. +46
    -0
      example.cpp

+ 46
- 0
example.cpp View File

@@ -34,6 +34,8 @@ typedef enum {
ST_COLUMN = 4,
// row
ST_ROW = 5,
// check button
ST_CHECK = 6,
} SubType;

typedef struct {
@@ -46,6 +48,12 @@ typedef struct {
const char *label;
} UIButtonData;

typedef struct {
UIData head;
const char *label;
int *option;
} UICheckData;

typedef struct {
UIData head;
int iconid;
@@ -125,6 +133,14 @@ void drawUI(NVGcontext *vg, int item, int x, int y) {
cornerFlags(item),(BNDwidgetState)uiGetState(item),
data->iconid,data->label);
} break;
case ST_CHECK: {
const UICheckData *data = (UICheckData*)head;
BNDwidgetState state = (BNDwidgetState)uiGetState(item);
if (*data->option)
state = BND_ACTIVE;
bndOptionButton(vg,rect.x,rect.y,rect.w,rect.h, state,
data->label);
} break;
case ST_RADIO:{
const UIRadioData *data = (UIRadioData*)head;
BNDwidgetState state = (BNDwidgetState)uiGetState(item);
@@ -191,6 +207,30 @@ int button(int parent, UIhandle handle, int iconid, const char *label,
return item;
}

void checkhandler(int item, UIevent event) {
const UICheckData *data = (const UICheckData *)uiGetData(item);
*data->option = !(*data->option);
}

int check(int parent, UIhandle handle, const char *label, int *option) {
// create new ui item
int item = uiItem();
// set persistent handle for item that is used
// to track activity over time
uiSetHandle(item, handle);
// set size of wiget; horizontal size is dynamic, vertical is fixed
uiSetSize(item, 0, BND_WIDGET_HEIGHT);
// attach event handler e.g. demohandler above
uiSetHandler(item, checkhandler, UI_BUTTON0_DOWN);
// store some custom data with the button that we use for styling
UICheckData *data = (UICheckData *)uiAllocData(item, sizeof(UICheckData));
data->head.subtype = ST_CHECK;
data->label = label;
data->option = option;
uiAppend(parent, item);
return item;
}

// simple logic for a slider

// starting offset of the currently active slider
@@ -569,6 +609,12 @@ void draw(NVGcontext *vg, float w, float h) {
button(col, 11, BND_ICONID(6,3), "Item 5", NULL);
static int option1,option2,option3;
check(col, 12, "Item 6", &option1);
check(col, 13, "Item 7", &option2);
check(col, 14, "Item 8", &option3);
uiProcess();


Loading…
Cancel
Save