1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-28 20:32:06 +00:00
AIO-switch-updater/source/warning_page.cpp

79 lines
2.6 KiB
C++
Raw Normal View History

#include "warning_page.hpp"
2021-09-11 14:48:13 +01:00
2021-03-16 14:56:46 +00:00
#include <algorithm>
#include <fstream>
2021-09-11 14:48:13 +01:00
#include "constants.hpp"
2021-03-16 14:56:46 +00:00
#include "fs.hpp"
2021-09-11 14:48:13 +01:00
#include "main_frame.hpp"
#include "utils.hpp"
2021-03-16 14:56:46 +00:00
namespace i18n = brls::i18n;
using namespace i18n::literals;
WarningPage::WarningPage(const std::string& text)
{
2021-03-16 14:56:46 +00:00
fs::createTree(CONFIG_PATH);
2021-03-19 16:56:10 +00:00
std::ofstream hiddenFile(HIDDEN_AIO_FILE);
2021-03-01 18:19:17 +00:00
this->button = (new brls::Button(brls::ButtonStyle::PRIMARY))->setLabel("menus/common/continue"_i18n);
this->button->setParent(this);
this->button->getClickEvent()->subscribe([this](View* view) {
brls::Application::pushView(new MainFrame());
});
this->label = new brls::Label(brls::LabelStyle::REGULAR, text, true);
this->label->setHorizontalAlign(NVG_ALIGN_LEFT);
//this->setBackground(brls::ViewBackground::DEBUG);
this->label->setParent(this);
this->registerAction("", brls::Key::B, [this] { return true; });
}
void WarningPage::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx)
{
auto end = std::chrono::high_resolution_clock::now();
auto missing = std::max(1l - std::chrono::duration_cast<std::chrono::seconds>(end - start).count(), 0l);
2021-09-11 14:48:13 +01:00
auto text = std::string("menus/common/continue"_i18n);
if (missing > 0) {
this->button->setLabel(text + " (" + std::to_string(missing) + ")");
this->button->setState(brls::ButtonState::DISABLED);
2021-09-11 14:48:13 +01:00
}
else {
this->button->setLabel(text);
this->button->setState(brls::ButtonState::ENABLED);
}
this->button->invalidate();
this->label->frame(ctx);
this->button->frame(ctx);
}
brls::View* WarningPage::getDefaultFocus()
{
return this->button;
}
void WarningPage::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash)
{
this->label->setWidth(0.8f * this->width);
this->label->invalidate(true);
this->label->setBoundaries(
this->x + this->width / 2 - this->label->getWidth() / 2,
2021-09-11 14:48:13 +01:00
this->y + (this->height - this->label->getHeight() - this->y - style->CrashFrame.buttonHeight) / 2,
this->label->getWidth(),
this->label->getHeight());
this->button->setBoundaries(
this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2,
2021-09-11 14:48:13 +01:00
this->y + (this->height - style->CrashFrame.buttonHeight * 3),
style->CrashFrame.buttonWidth,
style->CrashFrame.buttonHeight);
this->button->invalidate();
start = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(150);
}
WarningPage::~WarningPage()
{
delete this->label;
delete this->button;
}