nuklear
nuklear copied to clipboard
nk_tab
I was looking for a gui tabs function but couldn't found it. Then I tested the demo with overview function and it had tabs.
Here is the gui tabs from overview.c#L956
It had no function for it so I converted it to a function:
NK_API int nk_tab (struct nk_context *ctx, const char *title, int active)
{
const struct nk_user_font *f = ctx->style.font;
float text_width = f->width(f->userdata, f->height, title, nk_strlen(title));
float widget_width = text_width + 3 * ctx->style.button.padding.x;
nk_layout_row_push(ctx, widget_width);
struct nk_style_item c = ctx->style.button.normal;
if (active) {ctx->style.button.normal = ctx->style.button.active;}
int r = nk_button_label (ctx, title);
ctx->style.button.normal = c;
return r;
}
Now it can look like this:
nk_style_push_vec2(ctx, &ctx->style.window.spacing, nk_vec2(0,0));
nk_style_push_float(ctx, &ctx->style.button.rounding, 0);
nk_layout_row_begin(ctx, NK_STATIC, 30, 2);
if (nk_tab (ctx, "TAB1", state == TAB1)) {state = TAB1;}
if (nk_tab (ctx, "TAB2", state == TAB2)) {state = TAB2;}
nk_style_pop_float(ctx);
nk_style_pop_vec2(ctx);
Very similar to nk_option_label
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "TAB1", state == TAB1)) {state = TAB1;}
if (nk_option_label(ctx, "TAB2", state == TAB2)) {state = TAB2;}
Quite nice!
Creo que se pudiera mejorar mas con algo como esto, que usted cree? @KenthJohan
nk_layout_row_begin(ctx, NK_STATIC, 30, 2);
if (nk_tab(ctx, "Tab1", tabState)) {
nk_label(ctx,"Soy el Tab1",NK_TEXT_LEFT);
}
if (nk_tab(ctx, "Tab2", tabState)) {
nk_label(ctx,"Soy el Tab2",NK_TEXT_LEFT);
}