Files
NXST/include/nxst/ui/transfer_overlay.hpp
T

95 lines
3.3 KiB
C++

#pragma once
#include <pu/Plutonium>
#include <nxst/ui/theme.hpp>
#include <nxst/domain/util.hpp>
namespace ui {
class TransferOverlay : public pu::ui::Overlay {
private:
pu::ui::elm::Rectangle::Ref card;
pu::ui::elm::TextBlock::Ref titleText;
pu::ui::elm::TextBlock::Ref statusText;
pu::ui::elm::Rectangle::Ref progressTrack;
pu::ui::elm::ProgressBar::Ref progressBar;
pu::ui::elm::TextBlock::Ref indeterminateText;
pu::ui::elm::TextBlock::Ref hintText;
static constexpr int CardW = 720;
static constexpr int CardH = 360;
static constexpr int CardX = (theme::layout::ScreenW - CardW) / 2;
static constexpr int CardY = (theme::layout::ScreenH - CardH) / 2;
public:
TransferOverlay(const std::string &title)
: Overlay(0, 0, theme::layout::ScreenW, theme::layout::ScreenH, theme::color::Scrim)
{
using namespace theme;
card = pu::ui::elm::Rectangle::New(
CardX, CardY, CardW, CardH, color::BgSurface, radius::lg);
titleText = pu::ui::elm::TextBlock::New(
CardX + space::lg, CardY + space::lg, title);
titleText->SetFont(type::font(type::Title));
titleText->SetColor(color::TextPrimary);
statusText = pu::ui::elm::TextBlock::New(
CardX + space::lg,
CardY + space::lg + 56,
"");
statusText->SetFont(type::font(type::Body));
statusText->SetColor(color::TextSecondary);
int barX = CardX + space::lg;
int barY = CardY + space::lg + 56 + 56;
int barW = CardW - 2 * space::lg;
progressTrack = pu::ui::elm::Rectangle::New(
barX, barY, barW, 8, color::Divider, radius::sm);
progressBar = pu::ui::elm::ProgressBar::New(
barX, barY, barW, 8, 100.0);
progressBar->SetProgressColor(color::Primary);
progressBar->SetBackgroundColor(color::Divider);
indeterminateText = pu::ui::elm::TextBlock::New(
barX, barY - 4, "Preparing transfer...");
indeterminateText->SetFont(type::font(type::Body));
indeterminateText->SetColor(color::TextMuted);
indeterminateText->SetVisible(false);
hintText = pu::ui::elm::TextBlock::New(
CardX + space::lg,
CardY + CardH - space::lg - 18,
"B to cancel");
hintText->SetFont(type::font(type::Caption));
hintText->SetColor(color::TextMuted);
this->Add(card);
this->Add(titleText);
this->Add(statusText);
this->Add(progressTrack);
this->Add(progressBar);
this->Add(indeterminateText);
this->Add(hintText);
}
PU_SMART_CTOR(TransferOverlay)
void SetStatus(const std::string &status) {
statusText->SetText(StringUtils::elide(status, 56));
}
void SetProgress(double val) {
progressBar->SetProgress(val);
}
void SetProgressVisible(bool visible) {
progressTrack->SetVisible(visible);
progressBar->SetVisible(visible);
indeterminateText->SetVisible(!visible);
}
};
}