Skip to content

Commit

Permalink
include percentage with progress bar (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Dec 1, 2019
1 parent 8944e86 commit e1c956f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/ui/viewmodels/OverlayListPageViewModel.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "OverlayListPageViewModel.hh"

#include "ra_math.h"
#include "RA_StringUtils.h"

#include "services\IThreadPool.hh"

Expand Down Expand Up @@ -145,10 +146,16 @@ void OverlayListPageViewModel::RenderList(ra::ui::drawing::ISurface& pSurface, i
{
const auto nProgressBarWidth = (nWidth - nTextX - 12) * 2 / 3;
const auto nValue = pItem->GetProgressValue();
const auto nProgressBarFillWidth = (nProgressBarWidth - 2) * nValue / nTarget;
const auto nProgressBarFillWidth = gsl::narrow_cast<int>(((static_cast<long>(nProgressBarWidth) - 2) * nValue) / nTarget);
const auto nProgressBarPercent = gsl::narrow_cast<int>(static_cast<long>(nValue) * 100 / nTarget);

pSurface.FillRectangle(nTextX + 12, nY + 1 + 26 + 25, nProgressBarWidth, 8, pTheme.ColorOverlayScrollBar());
pSurface.FillRectangle(nTextX + 12 + 2, nY + 1 + 26 + 25 + 2, nProgressBarFillWidth - 4, 8 - 4, pTheme.ColorOverlayScrollBarGripper());

const auto nProgressFont = pSurface.LoadFont(pTheme.FontOverlay(), 14, ra::ui::FontStyles::Normal);
const std::wstring sProgressPercent = ra::StringPrintf(L"%d%%", nProgressBarPercent);
const auto szProgressPercent = pSurface.MeasureText(nProgressFont, sProgressPercent);
pSurface.WriteText(nTextX + 12 + nProgressBarWidth + 6, nY + 1 + 26 + 25 + 4 - (szProgressPercent.Height / 2) - 1, nProgressFont, nSubTextColor, sProgressPercent);
}

nIndex++;
Expand Down

0 comments on commit e1c956f

Please sign in to comment.