aboutsummaryrefslogtreecommitdiff
path: root/cli/component.hpp
blob: fe02d0b238de9b51a5309cb630d99c4ad01de357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <algorithm>
#include <ftxui/component/component_base.hpp>
#include <ftxui/component/component.hpp>

#include "katja/repository.hpp"

namespace katja
{
    class PageBase : public ftxui::ComponentBase
    {
    public:
        virtual void Load() = 0;
    };

    using Page = std::shared_ptr<PageBase>;

    class PageContainer final : public ftxui::ComponentBase
    {
        int menu_selected{ 0 };
        ftxui::Component menu;
        ftxui::Component content;
        std::vector<std::string> menu_entries;

    public:
        std::function<void()> on_enter;

        PageContainer(std::vector<std::pair<std::string, Page>> pages);

        ftxui::Element Render() override;
        bool OnEvent(ftxui::Event event) override;
    };

    class WelcomePage final : public PageBase
    {
    public:
        void Load() override;
        ftxui::Element Render() override;
    };

    class UpdatesPage final : public PageBase
    {
        std::vector<package_identifier> updatable;

    public:
        explicit UpdatesPage(std::vector<package_identifier>&& updatable);

        void Load() override;
        ftxui::Element Render() override;
    };

    class SearchPage final : public PageBase
    {
    public:
        void Load() override;
    };
}