DVX_GUI/dvx/widgets/widgetLabel.c

61 lines
1.8 KiB
C

// widgetLabel.c — Label widget
#include "widgetInternal.h"
// ============================================================
// wgtLabel
// ============================================================
WidgetT *wgtLabel(WidgetT *parent, const char *text) {
WidgetT *w = widgetAlloc(parent, WidgetLabelE);
if (w) {
w->as.label.text = text;
w->accelKey = accelParse(text);
}
return w;
}
// ============================================================
// widgetLabelGetText
// ============================================================
const char *widgetLabelGetText(const WidgetT *w) {
return w->as.label.text;
}
// ============================================================
// widgetLabelSetText
// ============================================================
void widgetLabelSetText(WidgetT *w, const char *text) {
w->as.label.text = text;
w->accelKey = accelParse(text);
}
// ============================================================
// widgetLabelCalcMinSize
// ============================================================
void widgetLabelCalcMinSize(WidgetT *w, const BitmapFontT *font) {
w->calcMinW = textWidthAccel(font, w->as.label.text);
w->calcMinH = font->charHeight + 1;
}
// ============================================================
// widgetLabelPaint
// ============================================================
void widgetLabelPaint(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;
drawTextAccel(d, ops, font, w->x, w->y + (w->h - font->charHeight) / 2,
w->as.label.text, fg, bg, false);
}