Imgui does work well in touching screen in android(with android framwork GameActivity) #6659
kyrosle
started this conversation in
Build/Link/Run/Fonts issues ONLY!
Replies: 1 comment
-
and this is the imgui layer: #include "imgui_layer.h"
#include <imgui.h>
#include <backends/imgui_impl_opengl3.h>
#include <backends/imgui_impl_android.h>
#include "runtime/function/global/global_context.h"
namespace Gp {
ImguiLayer::ImguiLayer() : RenderLayer("Imgui Layer") {}
void ImguiLayer::OnAttach() {
auto window_size = g_runtime_global_context
.m_window_system->getWindowSize();
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_IsTouchScreen;
auto width = window_size[0];
auto height = window_size[1];
io.DisplaySize = ImVec2(width, height);
acout << "imgui window size w:" << width << " h:" << height << std::endl;
auto g_IniFilename = std::string(
g_runtime_global_context.m_app->activity->internalDataPath) + "/imgui";
io.IniFilename = g_IniFilename.c_str();;
ImGui::StyleColorsDark();
ImGui_ImplAndroid_Init(g_runtime_global_context.m_app->window);
ImGui_ImplOpenGL3_Init("#version 300 es");
ImFontConfig font_cfg;
font_cfg.SizePixels = 22.0f;
io.Fonts->AddFontDefault(&font_cfg);
ImGuiStyle &style = ImGui::GetStyle();
style.ScaleAllSizes(3.0f);
}
void ImguiLayer::OnDetach() {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplAndroid_Shutdown();
ImGui::DestroyContext();
}
void ImguiLayer::OnImGuiRender() {
std::array<int32_t, 2> s_window_size = g_runtime_global_context
.m_window_system->getWindowSize();
static bool show_demo_window = true;
static bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
// 1. Show the big demo window (Most of the sample code is in
// ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear
// ImGui!).
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);
// 2. Show a simple window that we create ourselves. We use a Begin/End pair
// to created a named window.
{
static float f = 0.0f;
static int counter = 0;
// Create a window called "Hello, world!" and append into it.
ImGui::Begin("Hello, world!");
ImGui::SetWindowSize(
ImVec2(s_window_size[0] * 0.6, s_window_size[1] * 0.8));
// Display some text (you can use a format strings too
ImGui::Text("This is some useful text.");
// Edit bools storing our window open/close state
ImGui::Checkbox("Demo Window", &show_demo_window);
ImGui::Checkbox("Another Window", &show_another_window);
// Edit 1 float using a slider from 0.0f to 1.0f
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
// Edit 3 floats representing a color
ImGui::ColorEdit3("clear color", (float *) &clear_color);
// Buttons return true when clicked (most widgets return true when edited/activated)
if (ImGui::Button("Button"))
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}
// 3. Show another simple window.
if (show_another_window) {
ImGui::Begin(
"Another Window",
&show_another_window); // Pass a pointer to our bool variable (the
// window will have a closing button that will
// clear the bool when clicked)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}
}
void ImguiLayer::Begin() {
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplAndroid_NewFrame();
ImGui::NewFrame();
}
void ImguiLayer::End() {
// Rendering
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
}
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is my porject with the patch.
Problem
the dilog doesn't match the touching.
Revelant code
The imgui layout is using the default demo layout.
VID_20230729_002900.mp4
Beta Was this translation helpful? Give feedback.
All reactions