refactor locked ops

isolation_bkp/dynres
Dominik Madarász 2021-05-16 12:14:37 +02:00
parent 9ac94a33f2
commit 10b085efc9
3 changed files with 11 additions and 7 deletions

View File

@ -70,6 +70,7 @@ typedef struct {
td_op_kind kind; td_op_kind kind;
char const *name; char const *name;
bool is_hidden; bool is_hidden;
bool is_locked;
uint8_t num_params; uint8_t num_params;
td_param *params; td_param *params;

View File

@ -5,6 +5,7 @@
static td_op default_ops[] = { static td_op default_ops[] = {
{ {
OP(TOP_NEW_IMAGE), OP(TOP_NEW_IMAGE),
.is_locked = true,
.num_params = 3, .num_params = 3,
.params = (td_param[]) { .params = (td_param[]) {
PARAM(TPARAM_COORD, "w", "64"), PARAM(TPARAM_COORD, "w", "64"),

View File

@ -74,7 +74,7 @@ void texed_draw_topbar(zpl_aabb2 r) {
} }
static bool is_add_op_dropbox_open = false; static bool is_add_op_dropbox_open = false;
static int add_op_dropbox_selected = 0; static int add_op_dropbox_selected = 1;
static char add_op_list[2000] = {0}; static char add_op_list[2000] = {0};
void texed_draw_oplist_pane(zpl_aabb2 r) { void texed_draw_oplist_pane(zpl_aabb2 r) {
@ -86,8 +86,10 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
is_add_op_dropbox_open = true; is_add_op_dropbox_open = true;
zpl_memset(add_op_list, 0, sizeof(add_op_list)); zpl_memset(add_op_list, 0, sizeof(add_op_list));
for (int i = 1; i < DEF_OPS_LEN; i += 1) { for (int i = 0, cnt = 0; i < DEF_OPS_LEN; i += 1) {
zpl_strcat(add_op_list, zpl_bprintf("%.*s%s", i == 1 ? 0 : 1, ";", default_ops[i].name)); if (default_ops[i].is_locked) continue;
zpl_strcat(add_op_list, zpl_bprintf("%.*s%s", cnt == 0 ? 0 : 1, ";", default_ops[i].name));
cnt += 1;
} }
} }
@ -122,13 +124,13 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 swap_top = zpl_aabb2_cut_left(&swap_r, aabb2_ray(swap_r).width/2.0f); zpl_aabb2 swap_top = zpl_aabb2_cut_left(&swap_r, aabb2_ray(swap_r).width/2.0f);
zpl_aabb2 swap_bottom = swap_r; zpl_aabb2 swap_bottom = swap_r;
if (i <= 1) GuiSetState(GUI_STATE_DISABLED); if (i == 0 || (i > 0 && default_ops[i-1].is_locked)) GuiSetState(GUI_STATE_DISABLED);
if (GuiButton(aabb2_ray(swap_top), "#121#")) { if (GuiButton(aabb2_ray(swap_top), "#121#")) {
texed_swp_op(i, i-1); texed_swp_op(i, i-1);
} }
GuiSetState(GUI_STATE_NORMAL); GuiSetState(GUI_STATE_NORMAL);
if (i == 0 || i+1 >= zpl_array_count(ctx.ops)) GuiSetState(GUI_STATE_DISABLED); if ((i+1 < zpl_array_count(ctx.ops) && default_ops[i+1].is_locked) || i+1 >= zpl_array_count(ctx.ops)) GuiSetState(GUI_STATE_DISABLED);
if (GuiButton(aabb2_ray(swap_bottom), "#120#")) { if (GuiButton(aabb2_ray(swap_bottom), "#120#")) {
texed_swp_op(i, i+1); texed_swp_op(i, i+1);
} }
@ -136,7 +138,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
zpl_aabb2 remove_r = zpl_aabb2_cut_right(&op_item_r, 60.0f); zpl_aabb2 remove_r = zpl_aabb2_cut_right(&op_item_r, 60.0f);
if (i == 0) GuiSetState(GUI_STATE_DISABLED); if (default_ops[i].is_locked) GuiSetState(GUI_STATE_DISABLED);
if (GuiButton(aabb2_ray(remove_r), "REMOVE")) { if (GuiButton(aabb2_ray(remove_r), "REMOVE")) {
texed_rem_op(i); texed_rem_op(i);
} }
@ -157,7 +159,7 @@ void texed_draw_oplist_pane(zpl_aabb2 r) {
} }
GuiSetState(GUI_STATE_NORMAL); GuiSetState(GUI_STATE_NORMAL);
GuiDrawText(ctx.ops[i].name, GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha)); GuiDrawText(zpl_bprintf("%s %s", ctx.ops[i].name, default_ops[i].is_locked ? "(locked)" : ""), GetTextBounds(LABEL, list_text), GuiGetStyle(LABEL, TEXT_ALIGNMENT), Fade(RAYWHITE, guiAlpha));
} }
static int op_dropdown_state = 0; static int op_dropdown_state = 0;