// widgetCheckbox.c — Checkbox widget #include "widgetInternal.h" // ============================================================ // wgtCheckbox // ============================================================ WidgetT *wgtCheckbox(WidgetT *parent, const char *text) { WidgetT *w = widgetAlloc(parent, WidgetCheckboxE); if (w) { w->as.checkbox.text = text; w->as.checkbox.checked = false; } return w; } // ============================================================ // widgetCheckboxCalcMinSize // ============================================================ void widgetCheckboxCalcMinSize(WidgetT *w, const BitmapFontT *font) { w->calcMinW = CHECKBOX_BOX_SIZE + CHECKBOX_GAP + (int32_t)strlen(w->as.checkbox.text) * font->charWidth; w->calcMinH = DVX_MAX(CHECKBOX_BOX_SIZE, font->charHeight); } // ============================================================ // widgetCheckboxOnMouse // ============================================================ void widgetCheckboxOnMouse(WidgetT *hit) { hit->as.checkbox.checked = !hit->as.checkbox.checked; if (hit->onChange) { hit->onChange(hit); } } // ============================================================ // widgetCheckboxPaint // ============================================================ void widgetCheckboxPaint(WidgetT *w, DisplayT *d, const BlitOpsT *ops, const BitmapFontT *font, const ColorSchemeT *colors) { uint32_t fg = w->fgColor ? w->fgColor : colors->contentFg; uint32_t bg = w->bgColor ? w->bgColor : colors->contentBg; int32_t boxY = w->y + (w->h - CHECKBOX_BOX_SIZE) / 2; // Draw checkbox box BevelStyleT bevel; bevel.highlight = colors->windowShadow; bevel.shadow = colors->windowHighlight; bevel.face = bg; bevel.width = 1; drawBevel(d, ops, w->x, boxY, CHECKBOX_BOX_SIZE, CHECKBOX_BOX_SIZE, &bevel); // Draw check mark if checked if (w->as.checkbox.checked) { int32_t cx = w->x + 3; int32_t cy = boxY + 3; int32_t cs = CHECKBOX_BOX_SIZE - 6; for (int32_t i = 0; i < cs; i++) { drawHLine(d, ops, cx + i, cy + i, 1, fg); drawHLine(d, ops, cx + cs - 1 - i, cy + i, 1, fg); } } // Draw label drawText(d, ops, font, w->x + CHECKBOX_BOX_SIZE + CHECKBOX_GAP, w->y + (w->h - font->charHeight) / 2, w->as.checkbox.text, fg, bg, false); }