#include "screen.h" #include #include "fonts.h" namespace roro { bool Screen::begin() { canvas_.setColorDepth(8); // RGB332: saves 32 KB of RAM (M1 Q46); theme colours are converted canvas_.setPsram(false); return canvas_.createSprite(theme::kWidth, theme::kHeight) != nullptr; } void Screen::render(AppManager& apps, const StatusInfo& status, const Toast* toast) { canvas_.fillSprite(theme::kBackground); const auto& area = theme::kContent; canvas_.setClipRect(area.x, area.y, area.w, area.h); apps.foreground().draw(canvas_); canvas_.clearClipRect(); widgets::statusBar(canvas_, status); if (toast) widgets::toast(canvas_, *toast); canvas_.pushSprite(&M5Cardputer.Display, 0, 0); } void Screen::renderUpdate(const std::string& title, const std::string& detail, int percent) { canvas_.fillSprite(theme::kBackground); canvas_.setTextDatum(top_center); canvas_.setFont(&fonts::bold); canvas_.setTextColor(theme::kAccent); canvas_.drawString(title.c_str(), theme::kWidth / 2, 34); canvas_.setFont(&fonts::body); canvas_.setTextColor(theme::kText); canvas_.drawString(detail.c_str(), theme::kWidth / 2, 56); if (percent >= 0) { const int x = 20, y = 82, w = theme::kWidth - 40, h = 12; canvas_.drawRect(x, y, w, h, theme::kMuted); canvas_.fillRect(x + 1, y + 1, (w - 2) * percent / 100, h - 2, theme::kAccent); canvas_.drawString((std::to_string(percent) + "%").c_str(), theme::kWidth / 2, y + 18); } canvas_.setTextDatum(top_left); canvas_.pushSprite(&M5Cardputer.Display, 0, 0); } } // namespace roro