Layout logic moved from core into widgets.

This commit is contained in:
Scott Duensing 2026-04-04 15:50:58 -05:00
parent 7cd7388607
commit 93b912d932
9 changed files with 28 additions and 31 deletions

View file

@ -136,7 +136,6 @@ typedef enum {
// Flags encode static properties checked by the framework.
// Widgets set these in their WidgetClassT definition.
#define WCLASS_FOCUSABLE 0x00000001
#define WCLASS_BOX_CONTAINER 0x00000002
#define WCLASS_HORIZ_CONTAINER 0x00000004
#define WCLASS_PAINTS_CHILDREN 0x00000008
#define WCLASS_NO_HIT_RECURSE 0x00000010

View file

@ -128,7 +128,6 @@ WidgetT *widgetFindByAccel(WidgetT *root, char key);
int32_t widgetCountVisibleChildren(const WidgetT *w);
int32_t widgetFrameBorderWidth(const WidgetT *w);
bool widgetIsFocusable(int32_t type);
bool widgetIsBoxContainer(int32_t type);
bool widgetIsHorizContainer(int32_t type);
int32_t multiClickDetect(int32_t vx, int32_t vy);

View file

@ -527,21 +527,6 @@ bool widgetIsFocusable(int32_t type) {
}
// ============================================================
// widgetIsBoxContainer
// ============================================================
//
// Returns true for widget types that use the generic box layout.
bool widgetIsBoxContainer(int32_t type) {
if (type < 0 || type >= arrlen(widgetClassTable) || !widgetClassTable[type]) {
return false;
}
return (widgetClassTable[type]->flags & WCLASS_BOX_CONTAINER) != 0;
}
// ============================================================
// widgetIsHorizContainer
// ============================================================

View file

@ -128,9 +128,7 @@ void widgetCalcMinSizeBox(WidgetT *w, const BitmapFontT *font) {
// size calculation. Hints only increase the minimum, never shrink it.
void widgetCalcMinSizeTree(WidgetT *w, const BitmapFontT *font) {
if (widgetIsBoxContainer(w->type)) {
widgetCalcMinSizeBox(w, font);
} else if (wclsHas(w, WGT_METHOD_CALC_MIN_SIZE)) {
if (wclsHas(w, WGT_METHOD_CALC_MIN_SIZE)) {
wclsCalcMinSize(w, font);
} else {
w->calcMinW = 0;
@ -357,9 +355,7 @@ void widgetLayoutBox(WidgetT *w, const BitmapFontT *font) {
// do nothing (they have no children to lay out).
void widgetLayoutChildren(WidgetT *w, const BitmapFontT *font) {
if (widgetIsBoxContainer(w->type)) {
widgetLayoutBox(w, font);
} else if (wclsHas(w, WGT_METHOD_LAYOUT)) {
if (wclsHas(w, WGT_METHOD_LAYOUT)) {
wclsLayout(w, font);
}
}

View file

@ -141,21 +141,31 @@ void widgetFrameDestroy(WidgetT *w) {
static const WidgetClassT sClassVBox = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER,
.flags = 0,
.handlers = {
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};
static const WidgetClassT sClassHBox = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_HORIZ_CONTAINER,
.flags = WCLASS_HORIZ_CONTAINER,
.handlers = {
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};
static const WidgetClassT sClassFrame = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_FOCUS_FORWARD,
.flags = WCLASS_FOCUS_FORWARD,
.handlers = {
[WGT_METHOD_PAINT] = (void *)widgetFramePaint,
[WGT_METHOD_DESTROY] = (void *)widgetFrameDestroy,
[WGT_METHOD_GET_LAYOUT_METRICS] = (void *)widgetFrameGetLayoutMetrics,
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};

View file

@ -310,9 +310,11 @@ void widgetRadioSetText(WidgetT *w, const char *text) {
static const WidgetClassT sClassRadioGroup = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER,
.flags = 0,
.handlers = {
[WGT_METHOD_DESTROY] = (void *)widgetRadioGroupDestroy,
[WGT_METHOD_DESTROY] = (void *)widgetRadioGroupDestroy,
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};

View file

@ -72,10 +72,12 @@ void widgetStatusBarGetLayoutMetrics(const WidgetT *w, const BitmapFontT *font,
static const WidgetClassT sClassStatusBar = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_HORIZ_CONTAINER,
.flags = WCLASS_HORIZ_CONTAINER,
.handlers = {
[WGT_METHOD_PAINT] = (void *)widgetStatusBarPaint,
[WGT_METHOD_GET_LAYOUT_METRICS] = (void *)widgetStatusBarGetLayoutMetrics,
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};

View file

@ -596,10 +596,12 @@ static const WidgetClassT sClassTabControl = {
static const WidgetClassT sClassTabPage = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_ACCEL_WHEN_HIDDEN,
.flags = WCLASS_ACCEL_WHEN_HIDDEN,
.handlers = {
[WGT_METHOD_ON_ACCEL_ACTIVATE] = (void *)widgetTabPageAccelActivate,
[WGT_METHOD_DESTROY] = (void *)widgetTabPageDestroy,
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};

View file

@ -64,10 +64,12 @@ void widgetToolbarGetLayoutMetrics(const WidgetT *w, const BitmapFontT *font, in
static const WidgetClassT sClassToolbar = {
.version = WGT_CLASS_VERSION,
.flags = WCLASS_BOX_CONTAINER | WCLASS_HORIZ_CONTAINER,
.flags = WCLASS_HORIZ_CONTAINER,
.handlers = {
[WGT_METHOD_PAINT] = (void *)widgetToolbarPaint,
[WGT_METHOD_GET_LAYOUT_METRICS] = (void *)widgetToolbarGetLayoutMetrics,
[WGT_METHOD_CALC_MIN_SIZE] = (void *)widgetCalcMinSizeBox,
[WGT_METHOD_LAYOUT] = (void *)widgetLayoutBox,
}
};