74 lines
2.0 KiB
C++
74 lines
2.0 KiB
C++
#include "component.hpp"
|
|
|
|
namespace katja
|
|
{
|
|
PageContainer::PageContainer(std::vector<std::pair<std::string, Page>> pages)
|
|
{
|
|
ftxui::Components menu_pages;
|
|
|
|
std::transform(std::cbegin(pages), std::cend(pages), std::back_inserter(menu_entries),
|
|
[](const std::pair<std::string, Page>& pair) { return pair.first; });
|
|
std::transform(std::cbegin(pages), std::cend(pages), std::back_inserter(menu_pages),
|
|
[](const std::pair<std::string, Page>& pair) { return pair.second; });
|
|
|
|
ftxui::MenuOption menu_option = ftxui::MenuOption::Horizontal();
|
|
this->menu = ftxui::Menu(&this->menu_entries, &this->menu_selected, menu_option);
|
|
|
|
this->content = ftxui::Container::Tab(menu_pages, &this->menu_selected);
|
|
}
|
|
|
|
ftxui::Element PageContainer::Render()
|
|
{
|
|
return ftxui::vbox({
|
|
this->menu->Render(),
|
|
this->content->Render()
|
|
});
|
|
}
|
|
|
|
bool PageContainer::OnEvent(ftxui::Event event)
|
|
{
|
|
if (event.character() == "q" && this->on_enter)
|
|
{
|
|
on_enter();
|
|
return true;
|
|
}
|
|
return menu->OnEvent(event);
|
|
}
|
|
|
|
ftxui::Element WelcomePage::Render()
|
|
{
|
|
return ftxui::text("Select an action in the menu.");
|
|
}
|
|
|
|
void WelcomePage::Load()
|
|
{
|
|
}
|
|
|
|
UpdatesPage::UpdatesPage(std::vector<package_identifier>&& updatable)
|
|
: updatable(std::move(updatable))
|
|
{
|
|
}
|
|
|
|
void UpdatesPage::Load()
|
|
{
|
|
}
|
|
|
|
ftxui::Element UpdatesPage::Render()
|
|
{
|
|
std::vector<std::shared_ptr<ftxui::Node>> lines;
|
|
|
|
for (const auto& package_identifier : this->updatable)
|
|
{
|
|
auto line = ftxui::text(package_identifier.to_string()) | color(ftxui::Color::SkyBlue2);
|
|
lines.push_back(line);
|
|
}
|
|
ftxui::Element summary = ftxui::text(" Updates (" + std::to_string(lines.size()) + ")");
|
|
|
|
return ftxui::window(summary, ftxui::vbox(lines));
|
|
}
|
|
|
|
void SearchPage::Load()
|
|
{
|
|
}
|
|
}
|