67 lines
1.9 KiB
C
67 lines
1.9 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) {
|
|
int32_t textY = w->y + (w->h - font->charHeight) / 2;
|
|
|
|
if (!w->enabled) {
|
|
drawTextAccelEmbossed(d, ops, font, w->x, textY, w->as.label.text, colors);
|
|
return;
|
|
}
|
|
|
|
uint32_t fg = w->fgColor ? w->fgColor : colors->contentFg;
|
|
uint32_t bg = w->bgColor ? w->bgColor : colors->contentBg;
|
|
|
|
drawTextAccel(d, ops, font, w->x, textY, w->as.label.text, fg, bg, false);
|
|
}
|