80 lines
2.2 KiB
C
80 lines
2.2 KiB
C
#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 = {
|
|
.flags = 0,
|
|
.paint = NULL,
|
|
.paintOverlay = NULL,
|
|
.calcMinSize = widgetSpacerCalcMinSize,
|
|
.layout = NULL,
|
|
.onMouse = NULL,
|
|
.onKey = NULL,
|
|
.destroy = NULL,
|
|
.getText = NULL,
|
|
.setText = NULL
|
|
};
|
|
|
|
// ============================================================
|
|
// 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
|
|
};
|
|
|
|
void wgtRegister(void) {
|
|
sTypeId = wgtRegisterClass(&sClassSpacer);
|
|
wgtRegisterApi("spacer", &sApi);
|
|
}
|