fix dropdown for locked ops

isolation_bkp/dynres
Dominik Madarász 2021-05-16 12:56:36 +02:00
parent 056cb420bb
commit 81cf0bf10f
4 changed files with 23 additions and 3 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,7 +1,7 @@
//~ NOTE(zaklaus): DATA SERIALISATION
#define ECOTEX_VERSION 2
#define ECOTEX_VERSION 3
#define UNPACK(kind) cw_unpack_next(&uc); assert(uc.item.type == kind);
@ -34,6 +34,8 @@ void texed_load(void) {
texed_add_op(kind);
td_op *op = zpl_array_end(ctx.ops);
UNPACK(CWP_ITEM_BOOLEAN);
op->is_locked = uc.item.as.boolean;
UNPACK(CWP_ITEM_BOOLEAN);
op->is_hidden = uc.item.as.boolean;
UNPACK(CWP_ITEM_ARRAY);
@ -86,6 +88,7 @@ void texed_save(void) {
for (int i = 0; i < zpl_array_count(ctx.ops); i += 1) {
td_op *op = &ctx.ops[i];
cw_pack_unsigned(&pc, op->kind);
cw_pack_boolean(&pc, (bool)op->is_locked);
cw_pack_boolean(&pc, (bool)op->is_hidden);
cw_pack_array_size(&pc, op->num_params);
for (int j = 0; j < op->num_params; j += 1) {

View File

@ -74,7 +74,7 @@ void texed_draw_topbar(zpl_aabb2 r) {
}
static bool is_add_op_dropbox_open = false;
static int add_op_dropbox_selected = 1;
static int add_op_dropbox_selected = 0;
static char add_op_list[2000] = {0};
void texed_draw_oplist_pane(zpl_aabb2 r) {
@ -145,6 +145,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 hidden_r = zpl_aabb2_cut_right(&op_item_r, 60.0f);
if (!default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_NORMAL);
if (GuiButton(aabb2_ray(hidden_r), ctx.ops[i].is_hidden ? "SHOW" : "HIDE")) {
ctx.ops[i].is_hidden = !ctx.ops[i].is_hidden;
texed_repaint_preview();
@ -159,6 +160,14 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
}
GuiSetState(GUI_STATE_NORMAL);
zpl_aabb2 lock_r = zpl_aabb2_cut_right(&op_item_r, 20.0f);
if (default_ops[ctx.ops[i].kind].is_locked) GuiSetState(GUI_STATE_DISABLED);
if (GuiButton(aabb2_ray(lock_r), ctx.ops[i].is_locked ? "#138#" : "#137#")) {
ctx.ops[i].is_locked = !ctx.ops[i].is_locked;
}
GuiSetState(GUI_STATE_NORMAL);
GuiDrawText(zpl_bprintf("%s %s", ctx.ops[i].name, ctx.ops[i].is_locked ? "(locked)" : ""), GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha));
}
@ -167,7 +176,15 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
if (is_add_op_dropbox_open && (op_dropdown_state = GuiDropdownBoxEco(aabb2_ray(add_op_r), add_op_list, "ADD OPERATION", &add_op_dropbox_selected, true)) > 0) {
is_add_op_dropbox_open = false;
if (op_dropdown_state < 2) {
texed_add_op(add_op_dropbox_selected);
int idx = 0;
for (int i = 0; i < DEF_OPS_LEN; i += 1) {
if (!default_ops[i].is_locked && idx == add_op_dropbox_selected) {
idx = i;
break;
}
else if (!default_ops[i].is_locked) idx += 1;
}
texed_add_op(idx);
}
}
}