add proper fnl modules to demo
This commit is contained in:
parent
9bb9fa5f5b
commit
47c4f2045c
14 changed files with 510 additions and 240 deletions
|
|
@ -38,26 +38,47 @@ static int mu_text_height(mu_Font font) {
|
|||
return f->default_height;
|
||||
}
|
||||
|
||||
static void pxl8_ui_render_icon(pxl8_gfx* gfx, i32 id, i32 x, i32 y, i32 w, i32 h, u8 color) {
|
||||
switch (id) {
|
||||
case 2: {
|
||||
i32 cx = x + w / 2;
|
||||
i32 cy = y + h / 2;
|
||||
i32 size = (w < h ? w : h) / 3;
|
||||
pxl8_line(gfx, cx - size, cy, cx, cy + size, color);
|
||||
pxl8_line(gfx, cx, cy + size, cx + size, cy - size, color);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
i32 cx = x + w / 2;
|
||||
i32 cy = y + h / 2;
|
||||
i32 size = (w < h ? w : h) / 4;
|
||||
pxl8_line(gfx, cx - size, cy - size, cx + size, cy + size, color);
|
||||
pxl8_line(gfx, cx + size, cy - size, cx - size, cy + size, color);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void pxl8_ui_render_commands(pxl8_ui* ui) {
|
||||
mu_Command* cmd = NULL;
|
||||
while (mu_next_command(&ui->mu_ctx, &cmd)) {
|
||||
switch (cmd->type) {
|
||||
case MU_COMMAND_RECT: {
|
||||
mu_RectCommand* rc = (mu_RectCommand*)cmd;
|
||||
u8 color = rc->color.r;
|
||||
pxl8_rect_fill(ui->gfx, rc->rect.x, rc->rect.y, rc->rect.w, rc->rect.h, color);
|
||||
pxl8_rect_fill(ui->gfx, rc->rect.x, rc->rect.y, rc->rect.w, rc->rect.h, rc->color.r);
|
||||
break;
|
||||
}
|
||||
case MU_COMMAND_TEXT: {
|
||||
mu_TextCommand* tc = (mu_TextCommand*)cmd;
|
||||
u8 color = tc->color.r;
|
||||
pxl8_text(ui->gfx, tc->str, tc->pos.x, tc->pos.y, color);
|
||||
pxl8_text(ui->gfx, tc->str, tc->pos.x, tc->pos.y, tc->color.r);
|
||||
break;
|
||||
}
|
||||
case MU_COMMAND_CLIP: {
|
||||
break;
|
||||
}
|
||||
case MU_COMMAND_ICON: {
|
||||
mu_IconCommand* ic = (mu_IconCommand*)cmd;
|
||||
pxl8_ui_render_icon(ui->gfx, ic->id, ic->rect.x, ic->rect.y, ic->rect.w, ic->rect.h, ic->color.r);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +125,21 @@ pxl8_ui* pxl8_ui_create(pxl8_gfx* gfx) {
|
|||
ui->mu_ctx.text_height = mu_text_height;
|
||||
ui->mu_ctx.text_width = mu_text_width;
|
||||
|
||||
ui->mu_ctx.style->colors[0] = (mu_Color){15, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[1] = (mu_Color){8, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[2] = (mu_Color){1, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[3] = (mu_Color){2, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[4] = (mu_Color){15, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[5] = (mu_Color){0, 0, 0, 0};
|
||||
ui->mu_ctx.style->colors[6] = (mu_Color){7, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[7] = (mu_Color){8, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[8] = (mu_Color){10, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[9] = (mu_Color){2, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[10] = (mu_Color){3, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[11] = (mu_Color){10, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[12] = (mu_Color){7, 0, 0, 255};
|
||||
ui->mu_ctx.style->colors[13] = (mu_Color){8, 0, 0, 255};
|
||||
|
||||
return ui;
|
||||
}
|
||||
|
||||
|
|
@ -163,6 +199,48 @@ bool pxl8_ui_button(pxl8_ui* ui, const char* label) {
|
|||
return mu_button(&ui->mu_ctx, label) & MU_RES_SUBMIT;
|
||||
}
|
||||
|
||||
bool pxl8_ui_checkbox(pxl8_ui* ui, const char* label, bool* state) {
|
||||
if (!ui || !state || !label) return false;
|
||||
|
||||
mu_Context* ctx = &ui->mu_ctx;
|
||||
mu_push_id(ctx, label, (int)strlen(label));
|
||||
|
||||
mu_Id id = mu_get_id(ctx, label, (int)strlen(label));
|
||||
mu_Rect r = mu_layout_next(ctx);
|
||||
mu_Rect box = mu_rect(r.x, r.y, r.h, r.h);
|
||||
|
||||
int had_focus_before = (ctx->focus == id);
|
||||
mu_update_control(ctx, id, r, 0);
|
||||
int has_focus_after = (ctx->focus == id);
|
||||
int mouseover = mu_mouse_over(ctx, r);
|
||||
|
||||
int res = 0;
|
||||
int int_state = *state ? 1 : 0;
|
||||
|
||||
if (had_focus_before && !has_focus_after && !ctx->mouse_down && mouseover) {
|
||||
res |= MU_RES_CHANGE;
|
||||
int_state = !int_state;
|
||||
}
|
||||
|
||||
mu_draw_control_frame(ctx, id, box, MU_COLOR_BASE, 0);
|
||||
if (int_state) {
|
||||
mu_draw_icon(ctx, MU_ICON_CHECK, box, ctx->style->colors[MU_COLOR_TEXT]);
|
||||
}
|
||||
r = mu_rect(r.x + box.w, r.y, r.w - box.w, r.h);
|
||||
mu_draw_control_text(ctx, label, r, MU_COLOR_TEXT, 0);
|
||||
|
||||
mu_pop_id(ctx);
|
||||
|
||||
*state = int_state != 0;
|
||||
return res & MU_RES_CHANGE;
|
||||
}
|
||||
|
||||
void pxl8_ui_indent(pxl8_ui* ui, i32 amount) {
|
||||
if (!ui) return;
|
||||
mu_Layout* layout = &ui->mu_ctx.layout_stack.items[ui->mu_ctx.layout_stack.idx - 1];
|
||||
layout->indent += amount;
|
||||
}
|
||||
|
||||
void pxl8_ui_label(pxl8_ui* ui, const char* text) {
|
||||
if (!ui || !text) return;
|
||||
mu_label(&ui->mu_ctx, text);
|
||||
|
|
@ -205,6 +283,14 @@ void pxl8_ui_window_end(pxl8_ui* ui) {
|
|||
mu_end_window(&ui->mu_ctx);
|
||||
}
|
||||
|
||||
void pxl8_ui_window_set_open(pxl8_ui* ui, const char* title, bool open) {
|
||||
if (!ui || !title) return;
|
||||
mu_Container* win = mu_get_container(&ui->mu_ctx, title);
|
||||
if (win) {
|
||||
win->open = open ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
pxl8_frame_theme pxl8_ui_theme_default(void) {
|
||||
pxl8_frame_theme theme = {0};
|
||||
theme.bg_color = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue