Skip to content
Repos

mologram

C++ 1.4 KB41 lines Opens in site

Directory Raw Download

#include "mologram/ui/PremiumPanel.hpp"

namespace mologram::ui {
using namespace ttgui;

static std::string pretty(std::string id) {
  for (auto& c : id) if (c == '_') c = ' ';
  if (!id.empty()) id[0] = (char)std::toupper((unsigned char)id[0]);
  return id;
}

std::string PremiumPanel::text(const PremiumFeature& f) {
  return pretty(f.id) + " needs Telegram Premium.\n\n"
         "Your account does not have Premium right now, so this was not done.\n"
         "Nothing was lost: your drafts, messages and the open chat are unchanged.\n\n"
         "To get Premium, open the chat with @PremiumBot in Telegram.\n"
         "Without Premium: " + f.fallback + ".";
}

Window* PremiumPanel::open(Application& app, const PremiumFeature& f) {
  Window* win = app.wm.createWindow("Telegram Premium", "lightblue", {10, 4, 56, 14});
  win->appName = "PremiumPanel";
  win->modal = true;
  auto* box = new VBox();
  auto* body = new TextWidget();
  body->cfg = &app.cfg;
  body->text = text(f);
  body->flex = 1;
  auto* ok = new PushButton("OK");
  ok->cfg = &app.cfg;
  ok->onPressed.connect([&app, win]() { app.wm.closeWindow(win); });
  box->addChild(std::unique_ptr<Widget>(body));
  box->addChild(std::unique_ptr<Widget>(ok));
  win->setContent(std::unique_ptr<Widget>(box));
  box->bounds = win->contentRect();
  box->layout();
  app.setFocused(ok);
  return win;
}

} // namespace mologram::ui
38.7ms