DVX_GUI/dvxbasic/ide/ideDesigner.h
2026-03-28 21:14:38 -05:00

182 lines
5.4 KiB
C

// ideDesigner.h -- DVX BASIC form designer
//
// Design-time data model and design surface for visual form editing.
// Controls are stored as pure data (not live widgets) and rendered
// onto a Canvas widget. The designer reads and writes .frm files.
#ifndef IDE_DESIGNER_H
#define IDE_DESIGNER_H
#include "dvxApp.h"
#include "dvxWidget.h"
#include "widgetCanvas.h"
#include "stb_ds_wrap.h"
#include <stdint.h>
#include <stdbool.h>
// ============================================================
// Limits
// ============================================================
#define DSGN_MAX_NAME 32
#define DSGN_MAX_TEXT 256
#define DSGN_MAX_PROPS 32
#define DSGN_GRID_SIZE 8
#define DSGN_HANDLE_SIZE 6
// ============================================================
// Design-time property (stored as key=value strings)
// ============================================================
typedef struct {
char name[DSGN_MAX_NAME];
char value[DSGN_MAX_TEXT];
} DsgnPropT;
// ============================================================
// Design-time control
// ============================================================
typedef struct {
char name[DSGN_MAX_NAME];
char typeName[DSGN_MAX_NAME];
int32_t left;
int32_t top;
int32_t width;
int32_t height;
int32_t tabIndex;
DsgnPropT props[DSGN_MAX_PROPS];
int32_t propCount;
WidgetT *widget; // live widget (created at design time for WYSIWYG)
} DsgnControlT;
// ============================================================
// Design-time form
// ============================================================
typedef struct {
char name[DSGN_MAX_NAME];
char caption[DSGN_MAX_TEXT];
int32_t width;
int32_t height;
DsgnControlT *controls; // stb_ds dynamic array
bool dirty;
WidgetT *contentBox; // VBox parent for live widgets
} DsgnFormT;
// ============================================================
// Toolbox tool IDs
// ============================================================
typedef enum {
TOOL_POINTER = 0,
TOOL_BUTTON,
TOOL_LABEL,
TOOL_TEXTBOX,
TOOL_CHECKBOX,
TOOL_OPTION,
TOOL_FRAME,
TOOL_LISTBOX,
TOOL_COMBOBOX,
TOOL_HSCROLL,
TOOL_VSCROLL,
TOOL_TIMER,
TOOL_PICTURE,
TOOL_IMAGE,
TOOL_COUNT
} DsgnToolE;
// ============================================================
// Grab handle IDs
// ============================================================
typedef enum {
HANDLE_NONE = -1,
HANDLE_E = 0, // resize width
HANDLE_S, // resize height
HANDLE_SE, // resize both
HANDLE_COUNT = 3
} DsgnHandleE;
// ============================================================
// Interaction mode
// ============================================================
typedef enum {
DSGN_IDLE,
DSGN_REORDERING, // dragging control up/down in the VBox
DSGN_RESIZING
} DsgnModeE;
// ============================================================
// Designer state
// ============================================================
typedef struct {
DsgnFormT *form;
int32_t selectedIdx; // -1 = form itself selected
DsgnToolE activeTool;
DsgnModeE mode;
DsgnHandleE activeHandle;
int32_t dragStartY; // mouse Y at drag start (for reorder)
int32_t dragOrigWidth; // widget size at resize start
int32_t dragOrigHeight;
int32_t dragStartX; // mouse X at resize start
WindowT *formWin;
AppContextT *ctx;
} DsgnStateT;
// ============================================================
// API
// ============================================================
// Initialize designer state.
void dsgnInit(DsgnStateT *ds, AppContextT *ctx);
// Set the canvas overlay widget (for grab handles).
void dsgnSetCanvas(DsgnStateT *ds, WidgetT *canvas);
// Create live widgets for all controls in the form.
// Call after dsgnLoadFrm or dsgnNewForm, with the form window's contentBox.
void dsgnCreateWidgets(DsgnStateT *ds, WidgetT *contentBox);
// Load a .frm file into the designer.
bool dsgnLoadFrm(DsgnStateT *ds, const char *source, int32_t sourceLen);
// Save the designer form to .frm text format.
// Returns the number of bytes written (excluding null), or -1 on error.
int32_t dsgnSaveFrm(const DsgnStateT *ds, char *buf, int32_t bufSize);
// Create a new blank form.
void dsgnNewForm(DsgnStateT *ds, const char *name);
// Repaint the design surface.
void dsgnPaint(DsgnStateT *ds);
// Draw selection handles over the painted window surface.
void dsgnPaintOverlay(DsgnStateT *ds, int32_t winX, int32_t winY);
// Handle mouse click on the design surface.
void dsgnOnMouse(DsgnStateT *ds, int32_t x, int32_t y, bool drag);
// Handle key press in design view.
void dsgnOnKey(DsgnStateT *ds, int32_t key);
// Get the name of the selected control (or form name if nothing selected).
const char *dsgnSelectedName(const DsgnStateT *ds);
// Get the default event name for a control type.
const char *dsgnDefaultEvent(const char *typeName);
// Get the VB type name for a tool ID.
const char *dsgnToolTypeName(DsgnToolE tool);
// Auto-generate a unique control name for the given type.
void dsgnAutoName(const DsgnStateT *ds, const char *typeName, char *buf, int32_t bufSize);
// Free designer resources.
void dsgnFree(DsgnStateT *ds);
#endif // IDE_DESIGNER_H