83 lines
1.9 KiB
C++
83 lines
1.9 KiB
C++
#include "WarehouseGUI.h"
|
|
#include "M5Stack.h"
|
|
|
|
using namespace gui;
|
|
|
|
WarehouseGUI::WarehouseGUI() {
|
|
this->screens = std::vector<AGUIScreen*>();
|
|
}
|
|
|
|
WarehouseGUI::~WarehouseGUI() = default;
|
|
|
|
int WarehouseGUI::addScreens(gui::AGUIScreen *screen) {
|
|
this->screens.push_back(screen);
|
|
return 0;
|
|
}
|
|
|
|
int WarehouseGUI::removeScreens(gui::AGUIScreen *screen) {
|
|
for (int i = 0; i < this->screens.size(); ++i) {
|
|
if (this->screens[i] == screen) {
|
|
this->screens.erase(this->screens.begin() + i);
|
|
return 0;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int WarehouseGUI::removeScreens(int index) {
|
|
if (index < 0 || index >= this->screens.size()) {
|
|
return -1;
|
|
}
|
|
this->screens.erase(this->screens.begin() + index);
|
|
return 0;
|
|
}
|
|
|
|
int WarehouseGUI::removeScreens(const char *name) {
|
|
for (int i = 0; i < this->screens.size(); ++i) {
|
|
if (this->screens[i]->getName() == name) {
|
|
this->screens.erase(this->screens.begin() + i);
|
|
return 0;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int WarehouseGUI::update() {
|
|
return this->current_screen->update();
|
|
}
|
|
|
|
int WarehouseGUI::setup() {
|
|
if (this->current_screen == nullptr) {
|
|
return -1;
|
|
}
|
|
return this->current_screen->setup();
|
|
}
|
|
|
|
int WarehouseGUI::changeCurrentScreen(const char *name) {
|
|
for (auto *screen : this->screens) {
|
|
if (screen->getName() == name) {
|
|
this->current_screen = screen;
|
|
this->current_screen->setup();
|
|
return 0;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int WarehouseGUI::changeCurrentScreen(int index) {
|
|
if (index < 0 || index >= this->screens.size()) {
|
|
return -1;
|
|
}
|
|
this->current_screen = this->screens[index];
|
|
this->current_screen->setup();
|
|
return 0;
|
|
}
|
|
|
|
std::vector<AGUIScreen *> gui::WarehouseGUI::getAllScreens() {
|
|
return this->screens;
|
|
}
|
|
|
|
AGUIScreen *gui::WarehouseGUI::getCurrentScreen() {
|
|
return this->current_screen;
|
|
}
|