ocornut/imgui

Ability to add icons (images) to the ImGui Docking TabBar

Closed this issue · 6 comments

Version/Branch of Dear ImGui:

Version 1.92.4, Branch: docking

Back-ends:

imgui_impl_opengl3.cpp + imgui_impl_glfw.cpp

Compiler, OS:

Windows 11 + MSVC

Full config/build information:

No response

Details:

How can I add icons to the TabBar (not the TitleBar) without affecting the underlying window docking mechanism?

As I understand it, the hierarchy is as follows:
The DockNodeUpdate function calls the DockNodeUpdateTabBar function, which calls TabItemEx, and TabItemEx calls TabItemLabelAndCloseButton.
This function draws the window title and close button.

And then the Dockspace function calls DockNodeUpdate.

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

No response

Do you want to add the icons within individual tabs (eg corresponding to a window) or separate from a specific tab ?

I want to add icons to a specific window, that is, each window has its own icon.

You need to merge an icon font into your font and use icons as part of the window title.

This is covered in the FAQ “ How can I easily use icons in my application?”
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-easily-use-icons-in-my-application

Which links to the FONTS document:
https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#using-icon-fonts

So I can't load my icons from images and pass them to ImTextureID or ImTextureRef?

So I can't load my icons from images and pass them to ImTextureID or ImTextureRef?

Yes but that won’t help you injecting this icon in the middle of a specific window title.

To make it part of window title, You would need to register a custom ImFontLoader, add it as a secondary source to your font, and react to specific Unicode code points of your choices and map them to loading images into the font atlas.
See #8466. So you’d create yourself a system where you have a list of image/path associated to Unicode code points and perform the loading yourself. You may also need to resize the image (you can use stb_image_resize.h) to match the font size.

Technically you can also easily register custom rectangles into the font atlas and render them, or load textures yourself as you suggested, but you won’t easily be able to inject that as part of the docked tab title.

It’s much easier and natural right now to use icon fonts.

Ok, thank you!