yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
test_editor.cc
Go to the documentation of this file.
2
3#include <SDL.h>
4
7#include "app/gui/style.h"
8#include "imgui/backends/imgui_impl_sdl2.h"
9#include "imgui/backends/imgui_impl_sdlrenderer2.h"
10#include "imgui/imgui.h"
11#include "imgui_test_engine/imgui_te_context.h"
12#include "imgui_test_engine/imgui_te_engine.h"
13#include "imgui_test_engine/imgui_te_imconfig.h"
14#include "imgui_test_engine/imgui_te_ui.h"
15
16namespace yaze {
17namespace test {
18namespace integration {
19
20absl::Status TestEditor::Update() {
21 ImGui::NewFrame();
22 if (ImGui::Begin("My Window")) {
23 ImGui::Text("Hello, world!");
24 ImGui::Button("My Button");
25 }
26
27 static bool show_demo_window = true;
28
29 ImGuiTestEngine_ShowTestEngineWindows(engine_, &show_demo_window);
30
31 ImGui::End();
32
33 return absl::OkStatus();
34}
35
36void TestEditor::RegisterTests(ImGuiTestEngine* engine) {
37 engine_ = engine;
38 ImGuiTest* test = IM_REGISTER_TEST(engine, "demo_test", "test1");
39 test->TestFunc = [](ImGuiTestContext* ctx) {
40 ctx->SetRef("My Window");
41 ctx->ItemClick("My Button");
42 ctx->ItemCheck("Node/Checkbox");
43 };
44}
45
48 yaze::core::Controller controller;
49 controller.init_test_editor(&test_editor);
50
51 if (!controller.CreateWindow().ok()) {
52 return EXIT_FAILURE;
53 }
54 if (!controller.CreateRenderer().ok()) {
55 return EXIT_FAILURE;
56 }
57 IMGUI_CHECKVERSION();
58 ImGui::CreateContext();
59
60 // Initialize Test Engine
61 ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext();
62 ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine);
63 test_io.ConfigVerboseLevel = ImGuiTestVerboseLevel_Info;
64 test_io.ConfigVerboseLevelOnError = ImGuiTestVerboseLevel_Debug;
65
66 ImGuiIO& io = ImGui::GetIO();
67 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
68
69 // Initialize ImGui for SDL
70 ImGui_ImplSDL2_InitForSDLRenderer(
71 controller.window(), yaze::core::Renderer::GetInstance().renderer());
72 ImGui_ImplSDLRenderer2_Init(yaze::core::Renderer::GetInstance().renderer());
73
74 test_editor.RegisterTests(engine);
75 ImGuiTestEngine_Start(engine, ImGui::GetCurrentContext());
76 controller.set_active(true);
77
78 // Set the default style
80
81 // Build a new ImGui frame
82 ImGui_ImplSDLRenderer2_NewFrame();
83 ImGui_ImplSDL2_NewFrame();
84
85 while (controller.IsActive()) {
86 controller.OnInput();
87 if (const auto status = controller.OnTestLoad(); !status.ok()) {
88 return EXIT_FAILURE;
89 }
90 controller.DoRender();
91 }
92
93 ImGuiTestEngine_Stop(engine);
94 controller.OnExit();
95 return EXIT_SUCCESS;
96}
97
98} // namespace integration
99} // namespace test
100} // namespace yaze
Main controller for the application.
Definition controller.h:29
absl::Status CreateWindow()
auto window() -> SDL_Window *
Definition controller.h:53
bool IsActive() const
Definition controller.h:31
void set_active(bool active)
Definition controller.h:55
absl::Status OnTestLoad()
void init_test_editor(editor::Editor *editor)
Definition controller.h:54
absl::Status CreateRenderer()
static Renderer & GetInstance()
Definition renderer.h:26
absl::Status Update() override
void RegisterTests(ImGuiTestEngine *engine)
void ColorsYaze()
Definition style.cc:117
Main namespace for the application.
Definition controller.cc:18