Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add window icons to ImGui viewports #2715

Open
junnys6018 opened this issue Aug 7, 2019 · 1 comment
Open

Add window icons to ImGui viewports #2715

junnys6018 opened this issue Aug 7, 2019 · 1 comment

Comments

@junnys6018
Copy link

junnys6018 commented Aug 7, 2019

Version/Branch of Dear ImGui:

Version: v1.72b
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: MSVC
Operating System: Windows 10

Is it possible to add window icons to Imgui viewports?
I am currently running the following code inside ImGui_ImplGlfw_CreateWindow()
to add icons. But it would be nice if an api was provided to set a default icon

static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
{
...
int width, height, nrChannels;
unsigned char* img = stbi_load("res/icon.png", &width, &height, &nrChannels, 4);
GLFWimage icon = { width,height,img };
glfwSetWindowIcon(data->Window, 1, &icon);
stbi_image_free(img);
...
}

Screenshots/Video

Capture

@ocornut
Copy link
Owner

ocornut commented Aug 28, 2019

I am not sure it is easy or possible to provide a cross platform API for that without dragging in a lots of things. I think we should let the user implement it themselves in particular because I would expect some application may even want to have different icon depending on the content of the viewport.

For now my suggestion is to avoid modifying ImGui_ImplGlfw_CreateWindow():

Instead you can replace the Platform_CreateWindow or Platform_ShowWindow field of ImGuiPlatformIO. Save the previous handler, register yours instead. In your handler call the previous handler and then do your icon loading (if you do it in Platform_CreateWindow do it after calling the original handler, if you do it in Platform_ShowWindow do it first).

Open to other suggestions but I think this would be the path of least resistance and more flexibility for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants