From 85f0e5be560eb0bd21fb8f48d400326c22f52aad Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Mon, 16 Mar 2026 18:13:57 -0500 Subject: [PATCH] Vertical progress bar added. --- dvx/dvxWidget.h | 2 ++ dvx/widgets/widgetProgressBar.c | 52 ++++++++++++++++++++++++++++----- dvxdemo/demo.c | 7 ++++- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/dvx/dvxWidget.h b/dvx/dvxWidget.h index 0ac243d..7c114b3 100644 --- a/dvx/dvxWidget.h +++ b/dvx/dvxWidget.h @@ -307,6 +307,7 @@ typedef struct WidgetT { struct { int32_t value; int32_t maxValue; + bool vertical; } progressBar; struct { @@ -541,6 +542,7 @@ void wgtComboBoxSetSelected(WidgetT *w, int32_t idx); // ============================================================ WidgetT *wgtProgressBar(WidgetT *parent); +WidgetT *wgtProgressBarV(WidgetT *parent); void wgtProgressBarSetValue(WidgetT *w, int32_t value); int32_t wgtProgressBarGetValue(const WidgetT *w); diff --git a/dvx/widgets/widgetProgressBar.c b/dvx/widgets/widgetProgressBar.c index 8f58bf4..5f2047e 100644 --- a/dvx/widgets/widgetProgressBar.c +++ b/dvx/widgets/widgetProgressBar.c @@ -13,6 +13,24 @@ WidgetT *wgtProgressBar(WidgetT *parent) { if (w) { w->as.progressBar.value = 0; 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; @@ -58,8 +76,13 @@ void wgtProgressBarSetValue(WidgetT *w, int32_t value) { // ============================================================ void widgetProgressBarCalcMinSize(WidgetT *w, const BitmapFontT *font) { - w->calcMinW = font->charWidth * 12; - w->calcMinH = font->charHeight + 4; + if (w->as.progressBar.vertical) { + 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 innerH = w->h - 4; - int32_t fillW = (innerW * w->as.progressBar.value) / maxVal; - if (fillW > innerW) { - fillW = innerW; - } + if (w->as.progressBar.vertical) { + int32_t fillH = (innerH * w->as.progressBar.value) / maxVal; - if (fillW > 0) { - rectFill(d, ops, w->x + 2, w->y + 2, fillW, innerH, fg); + if (fillH > innerH) { + 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); + } } } diff --git a/dvxdemo/demo.c b/dvxdemo/demo.c index afb904a..ba9bb77 100644 --- a/dvxdemo/demo.c +++ b/dvxdemo/demo.c @@ -502,9 +502,14 @@ static void setupControlsWindow(AppContextT *ctx) { wgtHSeparator(page1); wgtLabel(page1, "&Progress:"); - WidgetT *pb = wgtProgressBar(page1); + WidgetT *pbRow = wgtHBox(page1); + WidgetT *pb = wgtProgressBar(pbRow); + pb->weight = 100; wgtProgressBarSetValue(pb, 65); wgtSetTooltip(pb, "Task progress: 65%"); + WidgetT *pbV = wgtProgressBarV(pbRow); + wgtProgressBarSetValue(pbV, 75); + wgtSetTooltip(pbV, "Vertical progress: 75%"); wgtLabel(page1, "&Volume:"); WidgetT *slider = wgtSlider(page1, 0, 100);