mirror of
https://github.com/yoboujon/ftxui_template.git
synced 2025-06-08 13:00:50 +02:00
Renamed ScreenPage to Page, Event to EventPage.
This commit is contained in:
parent
c526374738
commit
09528d1b93
5 changed files with 18 additions and 19 deletions
|
@ -1,16 +1,15 @@
|
||||||
#ifndef HEADER_EVENT_FTXUI
|
#ifndef HEADER_EVENT_FTXUI
|
||||||
#define HEADER_EVENT_FTXUI
|
#define HEADER_EVENT_FTXUI
|
||||||
|
|
||||||
#include <deque>
|
|
||||||
#include <any>
|
#include <any>
|
||||||
|
#include <deque>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
enum class EventType : uint8_t
|
enum class EventType : uint8_t
|
||||||
{
|
{
|
||||||
SWITCH_SCREEN,
|
SWITCH_SCREEN,
|
||||||
SEND_COMMAND,
|
SEND_TEXT,
|
||||||
LAUNCH_INSTANCE,
|
|
||||||
STOP,
|
STOP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void add_event(const EventPayload &payload);
|
void add_event(const EventPayload &payload);
|
||||||
friend class Event;
|
friend class EventPage;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _is_running;
|
bool _is_running;
|
||||||
|
@ -39,10 +38,10 @@ private:
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Event
|
class EventPage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Event(EventHandler &eventhandler);
|
EventPage(EventHandler &eventhandler);
|
||||||
void send_event(const EventPayload &payload);
|
void send_event(const EventPayload &payload);
|
||||||
void send_event(const EventType &type, std::any data = {});
|
void send_event(const EventType &type, std::any data = {});
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
#include <ftxui/component/component_base.hpp>
|
#include <ftxui/component/component_base.hpp>
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
class ScreenPage : public Event
|
class Page : public EventPage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ScreenPage(EventHandler &handler)
|
Page(EventHandler &handler)
|
||||||
: Event(handler), _page()
|
: EventPage(handler), _page()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
ftxui::ScreenInteractive *get_screen();
|
ftxui::ScreenInteractive *get_screen();
|
||||||
void add_screen(ScreenPage *p);
|
void add_screen(Page *p);
|
||||||
void select_screen(size_t index);
|
void select_screen(size_t index);
|
||||||
void select_screen(const ScreenPage *p);
|
void select_screen(const Page *p);
|
||||||
void start();
|
void start();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ private:
|
||||||
~UserInterface();
|
~UserInterface();
|
||||||
|
|
||||||
ftxui::ScreenInteractive _screen;
|
ftxui::ScreenInteractive _screen;
|
||||||
std::vector<ScreenPage *> _pages;
|
std::vector<Page *> _pages;
|
||||||
ftxui::Component _page_container;
|
ftxui::Component _page_container;
|
||||||
ftxui::Component _main_container;
|
ftxui::Component _main_container;
|
||||||
ftxui::Component _main_renderer;
|
ftxui::Component _main_renderer;
|
||||||
|
|
|
@ -6,19 +6,19 @@
|
||||||
|
|
||||||
constexpr int64_t EVENT_LOOP_WAIT_MS = 100;
|
constexpr int64_t EVENT_LOOP_WAIT_MS = 100;
|
||||||
|
|
||||||
// Event
|
// EventPage
|
||||||
|
|
||||||
Event::Event(EventHandler &eventhandler)
|
EventPage::EventPage(EventHandler &eventhandler)
|
||||||
: _event_handler(eventhandler)
|
: _event_handler(eventhandler)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::send_event(const EventPayload &payload)
|
void EventPage::send_event(const EventPayload &payload)
|
||||||
{
|
{
|
||||||
_event_handler.add_event(payload);
|
_event_handler.add_event(payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event::send_event(const EventType &type, std::any data)
|
void EventPage::send_event(const EventType &type, std::any data)
|
||||||
{
|
{
|
||||||
_event_handler.add_event({type, data});
|
_event_handler.add_event({type, data});
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ ftxui::ScreenInteractive *UserInterface::get_screen()
|
||||||
return &_screen;
|
return &_screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::add_screen(ScreenPage *p)
|
void UserInterface::add_screen(Page *p)
|
||||||
{
|
{
|
||||||
_pages.push_back(p);
|
_pages.push_back(p);
|
||||||
}
|
}
|
||||||
|
@ -29,9 +29,9 @@ void UserInterface::select_screen(size_t index)
|
||||||
_page_index = index;
|
_page_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::select_screen(const ScreenPage *p)
|
void UserInterface::select_screen(const Page *p)
|
||||||
{
|
{
|
||||||
const typename std::vector<ScreenPage *>::iterator it = std::find(_pages.begin(), _pages.end(), p);
|
const typename std::vector<Page *>::iterator it = std::find(_pages.begin(), _pages.end(), p);
|
||||||
const size_t index = it - _pages.begin();
|
const size_t index = it - _pages.begin();
|
||||||
select_screen(index);
|
select_screen(index);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue