Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from sieren/add-json-error-handling
Add Error Screen for JSON Parsing
- Loading branch information
Showing
8 changed files
with
105 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#include "AppContext.h" | ||
#include <fs/ConfigReader.hpp> | ||
#include "rapidjson/stringbuffer.h" | ||
|
||
#include <memory> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <ui/UIWidget.hpp> | ||
#include <string> | ||
|
||
namespace gfx | ||
{ | ||
struct UIErrorWidget : public UIWidget | ||
{ | ||
UIErrorWidget(ScreenDriver* screenPtr, Frame frame, const uint16_t tag = 0) : | ||
UIWidget(screenPtr, frame, tag) | ||
{ | ||
mBackgroundColor = {255, 0, 0}; | ||
} | ||
|
||
void setWarningMessage(const std::string message) | ||
{ | ||
mWarningMessage = message; | ||
} | ||
|
||
void draw() override | ||
{ | ||
mpScreen->createSprite(mFrame, mBackgroundColor); | ||
mpScreen->loadFont(SmallFont); | ||
mpScreen->setTextColor(Color::WhiteColor(), mBackgroundColor); | ||
Frame textFrame; | ||
const auto textWidth = mpScreen->getTextWidth(mWarningMessage.c_str()); | ||
const auto centerPoint = mFrame.getCenterPoint(); | ||
textFrame.position.x = centerPoint.x - textWidth / 2; | ||
textFrame.position.y = mFrame.size.height/2; | ||
|
||
mpScreen->drawText(textFrame, 1, mWarningMessage.c_str()); | ||
mpScreen->pushSprite(mFrame.position); | ||
mpScreen->deleteSprite(); | ||
} | ||
|
||
private: | ||
std::string mWarningMessage; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
// Surround includes in these defines to silence warnings | ||
// from third party libraries. | ||
|
||
#if defined _MSC_VER | ||
/* DISABLE WARNINGS */ | ||
#define DISABLE_WARNINGS __pragma(warning( push, 0 )) | ||
/* ENABLE WARNINGS */ | ||
#define ENABLE_WARNINGS __pragma(warning( pop )) | ||
#elif defined __GNUC__ | ||
/* DISABLE WARNINGS */ | ||
#define DISABLE_WARNINGS \ | ||
_Pragma("GCC diagnostic push") \ | ||
_Pragma("GCC diagnostic ignored \"-Wall\"") | ||
_Pragma("GCC diagnostic ignored \"-Wcpp\"") | ||
/* ENABLE WARNINGS */ | ||
#define ENABLE_WARNINGS _Pragma("GCC diagnostic push") | ||
#else /* TODO: add more compilers here */ | ||
#define DISABLE_WARNINGS | ||
#define ENABLE_WARNINGS | ||
#endif | ||
|
||
#include <exception> | ||
// Override rapidjson assertions to throw exceptions by default | ||
#define RAPIDJSON_ASSERT(x) if(!(x)) throw std::logic_error("JSON Parsing failed. Check your config!"); |