#pragma once #include #include #include #include namespace ui { class HeaderBar { private: pu::ui::elm::Rectangle::Ref bg; pu::ui::elm::Rectangle::Ref divider; pu::ui::elm::TextBlock::Ref appName; pu::ui::elm::TextBlock::Ref subtitle; pu::ui::elm::Rectangle::Ref chipBg; pu::ui::elm::Image::Ref avatar; pu::ui::elm::TextBlock::Ref userName; public: HeaderBar(pu::ui::Layout* parent, const std::string& sub = "Save Transfer") { using namespace theme; bg = pu::ui::elm::Rectangle::New(0, 0, layout::ScreenW, layout::HeaderH, color::BgSurface); divider = pu::ui::elm::Rectangle::New(0, layout::HeaderH - 1, layout::ScreenW, 1, color::Divider); appName = pu::ui::elm::TextBlock::New(space::lg, 8, "NXST"); appName->SetFont(type::font(type::Title)); appName->SetColor(color::TextPrimary); subtitle = pu::ui::elm::TextBlock::New(space::lg, 46, sub); subtitle->SetFont(type::font(type::Caption)); subtitle->SetColor(color::TextMuted); const int chipW = 280; const int chipX = layout::ScreenW - chipW - space::lg; chipBg = pu::ui::elm::Rectangle::New(chipX, 16, chipW, 40, color::BgSurface2, radius::pill); chipBg->SetVisible(false); avatar = pu::ui::elm::Image::New(chipX + 4, 20, ""); avatar->SetWidth(32); avatar->SetHeight(32); avatar->SetVisible(false); userName = pu::ui::elm::TextBlock::New(chipX + 44, 24, ""); userName->SetFont(type::font(type::Body)); userName->SetColor(color::TextPrimary); userName->SetVisible(false); parent->Add(bg); parent->Add(divider); parent->Add(appName); parent->Add(subtitle); parent->Add(chipBg); parent->Add(avatar); parent->Add(userName); } void SetUser(const std::optional& uid, const std::string& name) { const bool show = uid.has_value(); chipBg->SetVisible(show); userName->SetVisible(show); if (show) { userName->SetText(name); std::string path = Account::iconPath(*uid); if (!path.empty()) { avatar->SetImage(path); avatar->SetWidth(32); avatar->SetHeight(32); avatar->SetVisible(avatar->IsImageValid()); } else { avatar->SetVisible(false); } } else { avatar->SetVisible(false); } } void SetSubtitle(const std::string& text) { subtitle->SetText(text); } }; } // namespace ui