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