#define DVX_WIDGET_IMPL // widgetSpacer.c -- Spacer widget (invisible stretching element) // // A zero-sized invisible widget with weight=100, used purely for // layout control. It absorbs leftover space in box layouts, pushing // sibling widgets apart. Common use: place a spacer between buttons // in a toolbar to right-align some buttons, or between a label and // a control to create elastic spacing. // // Because calcMinSize returns 0x0, the spacer takes no space when // there is none to spare, but greedily absorbs extra space via its // weight. This is the simplest possible layout primitive -- no paint, // no mouse, no keyboard, no state. The entire widget is effectively // just a weight value attached to a position in the sibling list. #include "dvxWidgetPlugin.h" static int32_t sTypeId = -1; // ============================================================ // widgetSpacerCalcMinSize // ============================================================ void widgetSpacerCalcMinSize(WidgetT *w, const BitmapFontT *font) { (void)font; w->calcMinW = 0; w->calcMinH = 0; } // ============================================================ // DXE registration // ============================================================ static const WidgetClassT sClassSpacer = { .version = WGT_CLASS_VERSION, .flags = 0, .handlers = { [WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetSpacerCalcMinSize, } }; // ============================================================ // Widget creation functions // ============================================================ WidgetT *wgtSpacer(WidgetT *parent) { WidgetT *w = widgetAlloc(parent, sTypeId); if (w) { w->weight = 100; } return w; } // ============================================================ // DXE registration // ============================================================ static const struct { WidgetT *(*create)(WidgetT *parent); } sApi = { .create = wgtSpacer }; static const WgtIfaceT sIface = { .basName = "Spacer", .props = NULL, .propCount = 0, .methods = NULL, .methodCount = 0, .events = NULL, .eventCount = 0, .createSig = WGT_CREATE_PARENT }; void wgtRegister(void) { sTypeId = wgtRegisterClass(&sClassSpacer); wgtRegisterApi("spacer", &sApi); wgtRegisterIface("spacer", &sIface); }