Vertical progress bar added.

This commit is contained in:
Scott Duensing 2026-03-16 18:13:57 -05:00
parent d2b90bd83e
commit 85f0e5be56
3 changed files with 52 additions and 9 deletions

View file

@ -307,6 +307,7 @@ typedef struct WidgetT {
struct { struct {
int32_t value; int32_t value;
int32_t maxValue; int32_t maxValue;
bool vertical;
} progressBar; } progressBar;
struct { struct {
@ -541,6 +542,7 @@ void wgtComboBoxSetSelected(WidgetT *w, int32_t idx);
// ============================================================ // ============================================================
WidgetT *wgtProgressBar(WidgetT *parent); WidgetT *wgtProgressBar(WidgetT *parent);
WidgetT *wgtProgressBarV(WidgetT *parent);
void wgtProgressBarSetValue(WidgetT *w, int32_t value); void wgtProgressBarSetValue(WidgetT *w, int32_t value);
int32_t wgtProgressBarGetValue(const WidgetT *w); int32_t wgtProgressBarGetValue(const WidgetT *w);

View file

@ -13,6 +13,24 @@ WidgetT *wgtProgressBar(WidgetT *parent) {
if (w) { if (w) {
w->as.progressBar.value = 0; w->as.progressBar.value = 0;
w->as.progressBar.maxValue = 100; w->as.progressBar.maxValue = 100;
w->as.progressBar.vertical = false;
}
return w;
}
// ============================================================
// wgtProgressBarV
// ============================================================
WidgetT *wgtProgressBarV(WidgetT *parent) {
WidgetT *w = widgetAlloc(parent, WidgetProgressBarE);
if (w) {
w->as.progressBar.value = 0;
w->as.progressBar.maxValue = 100;
w->as.progressBar.vertical = true;
} }
return w; return w;
@ -58,8 +76,13 @@ void wgtProgressBarSetValue(WidgetT *w, int32_t value) {
// ============================================================ // ============================================================
void widgetProgressBarCalcMinSize(WidgetT *w, const BitmapFontT *font) { void widgetProgressBarCalcMinSize(WidgetT *w, const BitmapFontT *font) {
w->calcMinW = font->charWidth * 12; if (w->as.progressBar.vertical) {
w->calcMinH = font->charHeight + 4; w->calcMinW = font->charHeight + 4;
w->calcMinH = font->charWidth * 12;
} else {
w->calcMinW = font->charWidth * 12;
w->calcMinH = font->charHeight + 4;
}
} }
@ -89,13 +112,26 @@ void widgetProgressBarPaint(WidgetT *w, DisplayT *d, const BlitOpsT *ops, const
int32_t innerW = w->w - 4; int32_t innerW = w->w - 4;
int32_t innerH = w->h - 4; int32_t innerH = w->h - 4;
int32_t fillW = (innerW * w->as.progressBar.value) / maxVal;
if (fillW > innerW) { if (w->as.progressBar.vertical) {
fillW = innerW; int32_t fillH = (innerH * w->as.progressBar.value) / maxVal;
}
if (fillW > 0) { if (fillH > innerH) {
rectFill(d, ops, w->x + 2, w->y + 2, fillW, innerH, fg); fillH = innerH;
}
if (fillH > 0) {
rectFill(d, ops, w->x + 2, w->y + 2 + innerH - fillH, innerW, fillH, fg);
}
} else {
int32_t fillW = (innerW * w->as.progressBar.value) / maxVal;
if (fillW > innerW) {
fillW = innerW;
}
if (fillW > 0) {
rectFill(d, ops, w->x + 2, w->y + 2, fillW, innerH, fg);
}
} }
} }

View file

@ -502,9 +502,14 @@ static void setupControlsWindow(AppContextT *ctx) {
wgtHSeparator(page1); wgtHSeparator(page1);
wgtLabel(page1, "&Progress:"); wgtLabel(page1, "&Progress:");
WidgetT *pb = wgtProgressBar(page1); WidgetT *pbRow = wgtHBox(page1);
WidgetT *pb = wgtProgressBar(pbRow);
pb->weight = 100;
wgtProgressBarSetValue(pb, 65); wgtProgressBarSetValue(pb, 65);
wgtSetTooltip(pb, "Task progress: 65%"); wgtSetTooltip(pb, "Task progress: 65%");
WidgetT *pbV = wgtProgressBarV(pbRow);
wgtProgressBarSetValue(pbV, 75);
wgtSetTooltip(pbV, "Vertical progress: 75%");
wgtLabel(page1, "&Volume:"); wgtLabel(page1, "&Volume:");
WidgetT *slider = wgtSlider(page1, 0, 100); WidgetT *slider = wgtSlider(page1, 0, 100);