Editor: áreas como classes (ViewClass)
Paleta, scripts, palco e saída são ViewClass (nome, tamanho mínimo, render, overlay de popups, posição da alça). Nome, mínimos do layout, alças e o desenho — na janela principal e nas áreas destacadas — vêm da tabela em vez de switch por view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
27245d9080
commit
c5805d2f63
1 file changed
+61
-28
@@ -1732,14 +1732,23 @@ static bool tabwin_on_draw(Ed* ed, int k, TinyBlocks_RenderableBlock** dst);
|
||||
static void drag_to_ctx(Ed* ed, int tgt);
|
||||
static void tabwins_close_all(Ed* ed);
|
||||
|
||||
/* == Areas como classes ===
|
||||
* Paleta, scripts, palco e saida sao ViewClass: nome, tamanho minimo,
|
||||
* desenho, popups (por cima) e posicao da alca. A janela principal e as
|
||||
* janelas destacadas desenham pela mesma tabela. */
|
||||
typedef struct ViewClass {
|
||||
const char* name;
|
||||
float min_w, min_h;
|
||||
void (*render)(Ed* ed, TinyBlocks_RenderableBlock* rb);
|
||||
void (*overlay)(Ed* ed, TinyBlocks_RenderableBlock* rb); /* popups da area */
|
||||
void (*grip)(const AreaRect* A, float* gx, float* gy); /* NULL = canto do cabecalho */
|
||||
} ViewClass;
|
||||
|
||||
static const ViewClass* view_class(int v);
|
||||
|
||||
static const char* view_name(int v) {
|
||||
switch (v) {
|
||||
case V_PALETTE: return "Blocos";
|
||||
case V_SCRIPTS: return "Scripts";
|
||||
case V_STAGE: return "Palco";
|
||||
case V_OUTPUT: return "Saída";
|
||||
}
|
||||
return "?";
|
||||
const ViewClass* vc = view_class(v);
|
||||
return vc ? vc->name : "?";
|
||||
}
|
||||
|
||||
static int lay_node(Ed* ed, int kind, int a, int b, int view, int fix, float px) {
|
||||
@@ -1864,9 +1873,8 @@ static void lay_restore(Ed* ed) {
|
||||
static float lay_min(Ed* ed, int n, bool horiz) {
|
||||
const LayNode* N = &ed->lay[n];
|
||||
if (N->kind == LN_LEAF) {
|
||||
if (horiz)
|
||||
return N->view == V_PALETTE ? CAT_W + 120.f : N->view == V_SCRIPTS ? 220.f : 160.f;
|
||||
return N->view == V_STAGE ? STAGE_BAR_H + 60.f : N->view == V_SCRIPTS ? TAB_H + 120.f : 80.f;
|
||||
const ViewClass* vc = view_class(N->view);
|
||||
return vc ? (horiz ? vc->min_w : vc->min_h) : 80.f;
|
||||
}
|
||||
float a = lay_min(ed, N->a, horiz), b = lay_min(ed, N->b, horiz);
|
||||
return ((N->kind == LN_HSPLIT) == horiz) ? a + b : fmaxf(a, b);
|
||||
@@ -2044,11 +2052,18 @@ static void lay_swap(Ed* ed, int va, int vb) {
|
||||
#define GRIP_S 18.f
|
||||
static void grip_pos(Ed* ed, int v, float* gx, float* gy) {
|
||||
const AreaRect* A = &ed->area[v];
|
||||
switch (v) {
|
||||
case V_STAGE: *gx = A->x + A->w - 50 - GRIP_S - 8; *gy = A->y + (STAGE_BAR_H - GRIP_S) * 0.5f; break;
|
||||
case V_OUTPUT: *gx = A->x + A->w - 8 - GRIP_S - 6; *gy = A->y + 6; break;
|
||||
default: *gx = A->x + A->w - GRIP_S - 8; *gy = A->y + (TAB_H - GRIP_S) * 0.5f; break;
|
||||
const ViewClass* vc = view_class(v);
|
||||
if (vc && vc->grip) { vc->grip(A, gx, gy); return; }
|
||||
*gx = A->x + A->w - GRIP_S - 8;
|
||||
*gy = A->y + (TAB_H - GRIP_S) * 0.5f;
|
||||
}
|
||||
|
||||
static void stage_grip(const AreaRect* A, float* gx, float* gy) {
|
||||
*gx = A->x + A->w - 50 - GRIP_S - 8; *gy = A->y + (STAGE_BAR_H - GRIP_S) * 0.5f;
|
||||
}
|
||||
|
||||
static void output_grip(const AreaRect* A, float* gx, float* gy) {
|
||||
*gx = A->x + A->w - 8 - GRIP_S - 6; *gy = A->y + 6;
|
||||
}
|
||||
|
||||
static int grip_at(Ed* ed, float mx, float my) {
|
||||
@@ -6510,6 +6525,34 @@ static void area_eval(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
tabctx_leave(as->ed, &sv);
|
||||
}
|
||||
|
||||
static void palette_view_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
render_flyout(ed, rb);
|
||||
render_categories(ed, rb);
|
||||
}
|
||||
|
||||
static void scripts_view_render(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
render_workspace(ed, rb);
|
||||
render_comp_panel(ed, rb);
|
||||
render_tab_bar(ed, rb);
|
||||
}
|
||||
|
||||
static void scripts_view_overlay(Ed* ed, TinyBlocks_RenderableBlock* rb) {
|
||||
render_plus_menu(ed, rb);
|
||||
render_tooltip(ed, rb);
|
||||
render_ctx_menu(ed, rb);
|
||||
}
|
||||
|
||||
static const ViewClass s_views[V_COUNT] = {
|
||||
[V_PALETTE] = { "Blocos", CAT_W + 120.f, 80.f, palette_view_render, NULL, NULL },
|
||||
[V_SCRIPTS] = { "Scripts", 220.f, TAB_H + 120.f, scripts_view_render, scripts_view_overlay, NULL },
|
||||
[V_STAGE] = { "Palco", 160.f, STAGE_BAR_H + 60.f, render_stage, NULL, stage_grip },
|
||||
[V_OUTPUT] = { "Saída", 160.f, 80.f, render_output, NULL, output_grip },
|
||||
};
|
||||
|
||||
static const ViewClass* view_class(int v) {
|
||||
return (v >= 0 && v < V_COUNT) ? &s_views[v] : NULL;
|
||||
}
|
||||
|
||||
static bool area_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_RenderableBlock** dst) {
|
||||
(void)rt;
|
||||
AreaScene* as = (AreaScene*)self->userdata;
|
||||
@@ -6524,16 +6567,12 @@ static bool area_on_draw(TinyBlocks_Block* self, TinyBlocks* rt, TinyBlocks_Rend
|
||||
tb_draw_clear(rb, COL_UI_BG.r, COL_UI_BG.g, COL_UI_BG.b, 1.f);
|
||||
bool saved[V_COUNT];
|
||||
areas_only(ed, v, saved);
|
||||
switch (v) {
|
||||
case V_PALETTE: render_flyout(ed, rb); render_categories(ed, rb); break;
|
||||
case V_SCRIPTS: render_workspace(ed, rb); render_comp_panel(ed, rb); render_tab_bar(ed, rb); break;
|
||||
case V_STAGE: render_stage(ed, rb); break;
|
||||
case V_OUTPUT: render_output(ed, rb); break;
|
||||
}
|
||||
const ViewClass* vc = view_class(v);
|
||||
if (vc) vc->render(ed, rb);
|
||||
if (ed->state == ES_DRAG && ed->drag_bi >= 0) /* bloco arrastado entre janelas */
|
||||
render_drag_chain(ed, rb);
|
||||
render_areas_overlay(ed, rb);
|
||||
if (v == V_SCRIPTS) { render_plus_menu(ed, rb); render_tooltip(ed, rb); render_ctx_menu(ed, rb); }
|
||||
if (vc && vc->overlay) vc->overlay(ed, rb);
|
||||
areas_restore(ed, saved);
|
||||
rb_translate(rb, -AREA(v).x, -AREA(v).y);
|
||||
*dst = rb;
|
||||
@@ -6588,13 +6627,7 @@ static bool editor_on_draw(TinyBlocks_Block* self, TinyBlocks* rt,
|
||||
bool saved[V_COUNT];
|
||||
areas_only(ed, -1, saved); /* as destacadas desenham na janela delas */
|
||||
|
||||
render_workspace(ed, rb);
|
||||
render_comp_panel(ed, rb);
|
||||
render_flyout(ed, rb);
|
||||
render_categories(ed, rb);
|
||||
render_stage(ed, rb);
|
||||
render_output(ed, rb);
|
||||
render_tab_bar(ed, rb);
|
||||
for (int v = 0; v < V_COUNT; v++) view_class(v)->render(ed, rb); /* as escondidas nao desenham */
|
||||
render_menu(ed, rb);
|
||||
|
||||
/* A pilha arrastada fica por cima de tudo (pode passar sobre a paleta) */
|
||||
|
||||
Reference in new issue
Block a user