Implement StatusOr popup in MasterEditor
This commit is contained in:
@@ -23,6 +23,28 @@ namespace yaze {
|
|||||||
namespace app {
|
namespace app {
|
||||||
namespace editor {
|
namespace editor {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr ImGuiWindowFlags kMainEditorFlags =
|
||||||
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
|
||||||
|
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
|
||||||
|
ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoTitleBar;
|
||||||
|
|
||||||
|
void NewMasterFrame() {
|
||||||
|
const ImGuiIO &io = ImGui::GetIO();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
||||||
|
ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
|
||||||
|
ImGui::SetNextWindowSize(dimensions, ImGuiCond_Always);
|
||||||
|
|
||||||
|
if (!ImGui::Begin("##YazeMain", nullptr, kMainEditorFlags)) {
|
||||||
|
ImGui::End();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
MasterEditor::~MasterEditor() { rom_.Close(); }
|
MasterEditor::~MasterEditor() { rom_.Close(); }
|
||||||
|
|
||||||
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
|
void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
|
||||||
@@ -31,18 +53,11 @@ void MasterEditor::SetupScreen(std::shared_ptr<SDL_Renderer> renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MasterEditor::UpdateScreen() {
|
void MasterEditor::UpdateScreen() {
|
||||||
const ImGuiIO &io = ImGui::GetIO();
|
NewMasterFrame();
|
||||||
ImGui::NewFrame();
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
|
||||||
ImVec2 dimensions(io.DisplaySize.x, io.DisplaySize.y);
|
|
||||||
ImGui::SetNextWindowSize(dimensions, ImGuiCond_Always);
|
|
||||||
|
|
||||||
if (!ImGui::Begin("##YazeMain", nullptr, main_editor_flags_)) {
|
|
||||||
ImGui::End();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawYazeMenu();
|
DrawYazeMenu();
|
||||||
|
DrawFileDialog();
|
||||||
|
DrawStatusPopup();
|
||||||
|
|
||||||
TAB_BAR("##TabBar")
|
TAB_BAR("##TabBar")
|
||||||
DrawOverworldEditor();
|
DrawOverworldEditor();
|
||||||
@@ -51,11 +66,25 @@ void MasterEditor::UpdateScreen() {
|
|||||||
DrawScreenEditor();
|
DrawScreenEditor();
|
||||||
END_TAB_BAR()
|
END_TAB_BAR()
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MasterEditor::DrawFileDialog() {
|
||||||
|
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) {
|
||||||
|
if (ImGuiFileDialog::Instance()->IsOk()) {
|
||||||
|
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
||||||
|
rom_.LoadFromFile(filePathName);
|
||||||
|
status_ = rom_.OpenFromFile(filePathName);
|
||||||
|
overworld_editor_.SetupROM(rom_);
|
||||||
|
}
|
||||||
|
ImGuiFileDialog::Instance()->Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MasterEditor::DrawStatusPopup() {
|
||||||
if (!status_.ok()) {
|
if (!status_.ok()) {
|
||||||
gui::widgets::DisplayStatus(status_);
|
gui::widgets::DisplayStatus(status_);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterEditor::DrawYazeMenu() {
|
void MasterEditor::DrawYazeMenu() {
|
||||||
@@ -65,17 +94,6 @@ void MasterEditor::DrawYazeMenu() {
|
|||||||
DrawViewMenu();
|
DrawViewMenu();
|
||||||
DrawHelpMenu();
|
DrawHelpMenu();
|
||||||
END_MENU_BAR()
|
END_MENU_BAR()
|
||||||
|
|
||||||
if (ImGuiFileDialog::Instance()->Display("ChooseFileDlgKey")) {
|
|
||||||
if (ImGuiFileDialog::Instance()->IsOk()) {
|
|
||||||
std::string filePathName = ImGuiFileDialog::Instance()->GetFilePathName();
|
|
||||||
std::string filePath = ImGuiFileDialog::Instance()->GetCurrentPath();
|
|
||||||
rom_.LoadFromFile(filePathName);
|
|
||||||
status_ = rom_.OpenFromFile(filePathName);
|
|
||||||
overworld_editor_.SetupROM(rom_);
|
|
||||||
}
|
|
||||||
ImGuiFileDialog::Instance()->Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterEditor::DrawFileMenu() const {
|
void MasterEditor::DrawFileMenu() const {
|
||||||
@@ -171,6 +189,9 @@ void MasterEditor::DrawViewMenu() {
|
|||||||
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
ImGui::MenuItem("HEX Editor", nullptr, &show_memory_editor);
|
||||||
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
|
ImGui::MenuItem("ASM Editor", nullptr, &show_asm_editor);
|
||||||
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
|
ImGui::MenuItem("ImGui Demo", nullptr, &show_imgui_demo);
|
||||||
|
if (ImGui::MenuItem("Invalid Argument Popup")) {
|
||||||
|
status_ = absl::InvalidArgumentError("Invalid Argument Status");
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
if (ImGui::BeginMenu("GUI Tools")) {
|
if (ImGui::BeginMenu("GUI Tools")) {
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ class MasterEditor {
|
|||||||
void UpdateScreen();
|
void UpdateScreen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void DrawFileDialog();
|
||||||
|
void DrawStatusPopup();
|
||||||
|
|
||||||
void DrawYazeMenu();
|
void DrawYazeMenu();
|
||||||
void DrawFileMenu() const;
|
void DrawFileMenu() const;
|
||||||
void DrawEditMenu() const;
|
void DrawEditMenu() const;
|
||||||
@@ -51,11 +54,6 @@ class MasterEditor {
|
|||||||
absl::Status status_;
|
absl::Status status_;
|
||||||
|
|
||||||
ImVec4 current_palette_[8];
|
ImVec4 current_palette_[8];
|
||||||
|
|
||||||
ImGuiWindowFlags main_editor_flags_ =
|
|
||||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse |
|
|
||||||
ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_MenuBar |
|
|
||||||
ImGuiWindowFlags_NoTitleBar;
|
|
||||||
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
|
ImGuiTableFlags toolset_table_flags_ = ImGuiTableFlags_SizingFixedFit;
|
||||||
|
|
||||||
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
std::shared_ptr<SDL_Renderer> sdl_renderer_;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace yaze {
|
|||||||
namespace gui {
|
namespace gui {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
|
||||||
bool BeginCentered(const char *name) {
|
static bool BeginCentered(const char *name) {
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
|
ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
|
||||||
ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
ImGui::SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||||
@@ -19,29 +19,20 @@ bool BeginCentered(const char *name) {
|
|||||||
return ImGui::Begin(name, nullptr, flags);
|
return ImGui::Begin(name, nullptr, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayStatus(const absl::Status &status) {
|
void DisplayStatus(absl::Status &status) {
|
||||||
static bool display_open = true;
|
auto title = absl::StrCat("StatusWindow_", status.ToString()).data();
|
||||||
if (display_open) {
|
if (BeginCentered(title)) {
|
||||||
auto title = absl::StrCat("StatusWindow_", status.ToString()).data();
|
ImGui::Text(status.ToString().data());
|
||||||
if (BeginCentered(title)) {
|
ImGui::Spacing();
|
||||||
ImGui::Text(status.ToString().data());
|
ImGui::NextColumn();
|
||||||
|
ImGui::Columns(1);
|
||||||
ImGui::Spacing();
|
ImGui::Separator();
|
||||||
ImGui::NextColumn();
|
ImGui::NewLine();
|
||||||
|
ImGui::SameLine(270);
|
||||||
ImGui::Columns(1);
|
if (ImGui::Button("OK", ImVec2(200, 0))) {
|
||||||
ImGui::Separator();
|
status = absl::OkStatus();
|
||||||
|
|
||||||
ImGui::NewLine();
|
|
||||||
|
|
||||||
ImGui::SameLine(270);
|
|
||||||
// click ok when finished adjusting
|
|
||||||
if (ImGui::Button("OK", ImVec2(200, 0))) {
|
|
||||||
display_open = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::End();
|
|
||||||
}
|
}
|
||||||
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace yaze {
|
|||||||
namespace gui {
|
namespace gui {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
|
||||||
void DisplayStatus(const absl::Status& status);
|
void DisplayStatus(absl::Status& status);
|
||||||
|
|
||||||
TextEditor::LanguageDefinition GetAssemblyLanguageDef();
|
TextEditor::LanguageDefinition GetAssemblyLanguageDef();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user