int demorect(int parent, const char *label, float hue, int box, int layout, int w, int h, int m1, int m2, int m3, int m4) { int item = colorrect(label, nvgHSL(hue, 1.0f, 0.8f)); uiSetLayout(item, layout); uiSetBox(item, box); uiSetMargins(item, m1, m2, m3, m4); uiSetSize(item, w, h); uiInsert(parent, item); return item; }
int label(int iconid, const char *label) { int item = uiItem(); uiSetSize(item, 0, BND_WIDGET_HEIGHT); UIButtonData *data = (UIButtonData *)uiAllocHandle(item, sizeof(UIButtonData)); data->head.subtype = ST_LABEL; data->head.handler = NULL; data->iconid = iconid; data->label = label; return item; }
void createUI(NVGcontext *vg, float w, float h) { int col; uiClear(); { int root = uiItem(); // position root element uiSetLayout(root,UI_LEFT|UI_TOP); uiSetMargins(root,50,50,0,0); uiSetSize(root,250,400); } col = column(0); uiSetLayout(col, UI_TOP|UI_HFILL); button(col, __LINE__, BND_ICONID(6,3), "Item 1", demohandler); button(col, __LINE__, BND_ICONID(6,3), "Item 2", demohandler); { int h = hgroup(col); radio(h, __LINE__, BND_ICONID(6,3), "Item 3.0", &enum1); radio(h, __LINE__, BND_ICONID(0,10), NULL, &enum1); radio(h, __LINE__, BND_ICONID(1,10), NULL, &enum1); radio(h, __LINE__, BND_ICONID(6,3), "Item 3.3", &enum1); } { int colr; int rows = row(col); int coll = vgroup(rows); label(coll, -1, "Items 4.0:"); coll = vgroup(coll); button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.0", demohandler); button(coll, __LINE__, BND_ICONID(6,3), "Item 4.0.1", demohandler); colr = vgroup(rows); uiSetFrozen(colr, option1); label(colr, -1, "Items 4.1:"); colr = vgroup(colr); slider(colr, __LINE__, "Item 4.1.0", &progress1); slider(colr,__LINE__, "Item 4.1.1", &progress2); } button(col, __LINE__, BND_ICONID(6,3), "Item 5", NULL); check(col, __LINE__, "Frozen", &option1); check(col, __LINE__, "Item 7", &option2); check(col, __LINE__, "Item 8", &option3); textbox(col, (UIhandle)textbuffer, textbuffer, 32); uiLayout(); }
int radio(int iconid, const char *label, int *value) { int item = uiItem(); uiSetSize(item, label?0:BND_TOOL_WIDTH, BND_WIDGET_HEIGHT); UIRadioData *data = (UIRadioData *)uiAllocHandle(item, sizeof(UIRadioData)); data->head.subtype = ST_RADIO; data->head.handler = radiohandler; data->iconid = iconid; data->label = label; data->value = value; uiSetEvents(item, UI_BUTTON0_DOWN); return item; }
int textbox(char *text, int maxsize) { int item = uiItem(); uiSetSize(item, 0, BND_WIDGET_HEIGHT); uiSetEvents(item, UI_BUTTON0_DOWN | UI_KEY_DOWN | UI_CHAR); // store some custom data with the button that we use for styling // and logic, e.g. the pointer to the data we want to alter. UITextData *data = (UITextData *)uiAllocHandle(item, sizeof(UITextData)); data->head.subtype = ST_TEXT; data->head.handler = textboxhandler; data->text = text; data->maxsize = maxsize; return item; }
int label(int parent, int iconid, const char *label) { int item = uiItem(); uiSetSize(item, 0, BND_WIDGET_HEIGHT); { UIButtonData *data = (UIButtonData *)uiAllocData(item, sizeof(UIButtonData)); data->head.subtype = ST_LABEL; data->iconid = iconid; data->label = label; } uiAppend(parent, item); return item; }
int button(int iconid, const char *label, UIhandler handler) { // create new ui item int item = uiItem(); // set size of wiget; horizontal size is dynamic, vertical is fixed uiSetSize(item, 0, BND_WIDGET_HEIGHT); uiSetEvents(item, UI_BUTTON0_HOT_UP); // store some custom data with the button that we use for styling UIButtonData *data = (UIButtonData *)uiAllocHandle(item, sizeof(UIButtonData)); data->head.subtype = ST_BUTTON; data->head.handler = handler; data->iconid = iconid; data->label = label; return item; }
int check(const char *label, int *option) { // create new ui item int item = uiItem(); // set size of wiget; horizontal size is dynamic, vertical is fixed uiSetSize(item, 0, BND_WIDGET_HEIGHT); // attach event handler e.g. demohandler above uiSetEvents(item, UI_BUTTON0_DOWN); // store some custom data with the button that we use for styling UICheckData *data = (UICheckData *)uiAllocHandle(item, sizeof(UICheckData)); data->head.subtype = ST_CHECK; data->head.handler = checkhandler; data->label = label; data->option = option; return item; }
int slider(const char *label, float *progress) { // create new ui item int item = uiItem(); // set size of wiget; horizontal size is dynamic, vertical is fixed uiSetSize(item, 0, BND_WIDGET_HEIGHT); // attach our slider event handler and capture two classes of events uiSetEvents(item, UI_BUTTON0_DOWN | UI_BUTTON0_CAPTURE); // store some custom data with the button that we use for styling // and logic, e.g. the pointer to the data we want to alter. UISliderData *data = (UISliderData *)uiAllocHandle(item, sizeof(UISliderData)); data->head.subtype = ST_SLIDER; data->head.handler = sliderhandler; data->label = label; data->progress = progress; return item; }
int radio(int parent, UIhandle handle, int iconid, const char *label, int *value) { int item = uiItem(); uiSetHandle(item, handle); uiSetSize(item, label?0:BND_TOOL_WIDTH, BND_WIDGET_HEIGHT); { UIRadioData *data = (UIRadioData *)uiAllocData(item, sizeof(UIRadioData)); data->head.subtype = ST_RADIO; data->iconid = iconid; data->label = label; data->value = value; } uiSetHandler(item, radiohandler, UI_BUTTON0_DOWN); uiAppend(parent, item); return item; }
int textbox(int parent, UIhandle handle, char *text, int maxsize) { int item = uiItem(); UITextData *data; uiSetHandle(item, handle); uiSetSize(item, 0, BND_WIDGET_HEIGHT); uiSetHandler(item, textboxhandler, UI_BUTTON0_DOWN | UI_KEY_DOWN | UI_CHAR); // store some custom data with the button that we use for styling // and logic, e.g. the pointer to the data we want to alter. data = (UITextData *)uiAllocData(item, sizeof(UITextData)); data->head.subtype = ST_TEXT; data->text = text; data->maxsize = maxsize; uiAppend(parent, item); return item; }
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; }
int slider(int parent, UIhandle handle, const char *label, float *progress) { // 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 our slider event handler and capture two classes of events uiSetHandler(item, sliderhandler, UI_BUTTON0_DOWN | UI_BUTTON0_CAPTURE); { // store some custom data with the button that we use for styling // and logic, e.g. the pointer to the data we want to alter. UISliderData *data = (UISliderData *)uiAllocData(item, sizeof(UISliderData)); data->head.subtype = ST_SLIDER; data->label = label; data->progress = progress; } uiAppend(parent, item); return item; }
void draw(NVGcontext *vg, float w, float h) { bndBackground(vg, 0, 0, w, h); // some OUI stuff uiBeginLayout(); int root = panel(); // position root element uiSetSize(0,w,h); ((UIData*)uiGetHandle(root))->handler = roothandler; uiSetEvents(root, UI_SCROLL|UI_BUTTON0_DOWN); uiSetBox(root, UI_COLUMN); static int choice = -1; int menu = uiItem(); uiSetLayout(menu, UI_HFILL|UI_TOP); uiSetBox(menu, UI_ROW); uiInsert(root, menu); int opt_blendish_demo = add_menu_option(menu, "Blendish Demo", &choice); int opt_oui_demo = add_menu_option(menu, "OUI Demo", &choice); int opt_layouts = add_menu_option(menu, "UI_LAYOUT", &choice); int opt_row = add_menu_option(menu, "UI_ROW", &choice); int opt_column = add_menu_option(menu, "UI_COLUMN", &choice); int opt_wrap = add_menu_option(menu, "UI_WRAP", &choice); if (choice < 0) choice = opt_blendish_demo; int content = uiItem(); uiSetLayout(content, UI_FILL); uiInsert(root, content); if (choice == opt_blendish_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_FILL); uiInsert(content, democontent); UIData *data = (UIData *)uiAllocHandle(democontent, sizeof(UIData)); data->handler = 0; data->subtype = ST_DEMOSTUFF; } else if (choice == opt_oui_demo) { int democontent = uiItem(); uiSetLayout(democontent, UI_TOP); uiSetSize(democontent, 250, 0); uiInsert(content, democontent); build_democontent(democontent); } else if (choice == opt_layouts) { build_layoutdemo(content); } else if (choice == opt_row) { build_rowdemo(content); } else if (choice == opt_column) { build_columndemo(content); } else if (choice == opt_wrap) { build_wrapdemo(content); } uiEndLayout(); drawUI(vg, 0, BND_CORNER_NONE); #if 0 for (int i = 0; i < uiGetLastItemCount(); ++i) { if (uiRecoverItem(i) == -1) { UIitem *pitem = uiLastItemPtr(i); nvgBeginPath(vg); nvgRect(vg,pitem->margins[0],pitem->margins[1],pitem->size[0],pitem->size[1]); nvgStrokeWidth(vg, 2); nvgStrokeColor(vg, nvgRGBAf(1.0f,0.0f,0.0f,0.5f)); nvgStroke(vg); } } #endif if (choice == opt_blendish_demo) { UIvec2 cursor = uiGetCursor(); cursor.x -= w/2; cursor.y -= h/2; if (abs(cursor.x) > (w/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 0, (cursor.x > 0)); } else if (abs(cursor.y) > (h/3)) { bndJoinAreaOverlay(vg, 0, 0, w, h, 1, (cursor.y > 0)); } } uiProcess((int)(glfwGetTime()*1000.0)); }