Files
MuditaOS/module-apps/apps-common/widgets/DigitsContainer.cpp
Onufry Pajaczek 7c6af2c57f [BH-1542] Pure meditation fix and cetner TimeFixedWidget
*DigitsContainer definicions moved to cpp file(for proper linkage)
*DigitsContainer changed container to std::vector
*Fixed a bug in ProgressTimerWithBarGraphAndCounter where timerText was
treated as timeWidget
*MeditationCountdownWindow timer is now custom size
*Minus removed form MeditationRunningWindow timer
2022-08-18 09:12:36 +02:00

50 lines
1.6 KiB
C++

// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "DigitsContainer.hpp"
#include <Utils.hpp>
namespace gui
{
void setDigits(std::string text, const DigitsContainer &container, DimensionsParams params)
{
std::for_each(std::crbegin(container.digits),
std::crend(container.digits),
[text = std::move(text), &params](Label *label) mutable {
if (text.empty()) {
label->setText("");
label->setSize(0, 0);
}
else {
label->setText(std::string{text.back()});
label->setSize(params.digitMaxWidth, params.mainBoxHeight);
text.pop_back();
}
});
}
DigitsContainer::DigitsContainer(uint32_t digitsCount) : digits(digitsCount, nullptr)
{}
void DigitsContainer::setMinutesBox(std::uint32_t minutes, DimensionsParams params)
{
constexpr auto rangeGuard = 1000;
minutes %= rangeGuard;
setDigits(std::to_string(minutes), *this, params);
}
void DigitsContainer::setSecondsBox(std::uint32_t seconds, DimensionsParams params)
{
constexpr auto rangeGuard = 100;
seconds %= rangeGuard;
std::string text = utils::addLeadingZeros(std::to_string(seconds), digits.size());
setDigits(std::move(text), *this, params);
}
} // namespace gui