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

ImGui::Begin() title text does not respect pushed font #4953

Closed
aeris170 opened this issue Jan 27, 2022 · 2 comments
Closed

ImGui::Begin() title text does not respect pushed font #4953

aeris170 opened this issue Jan 27, 2022 · 2 comments

Comments

@aeris170
Copy link

Version/Branch of Dear ImGui:

Version: 1.87
Branch: docking

Dear ImGui 1.87 WIP (18605)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1929
define: _MSVC_LANG=202002
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000440
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 2048,2048
io.DisplaySize: 3440.00,1387.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: MSVC (Visual Studio 2019 v. 16.11.9 with C++20)
Operating System: Windows 10 @ Latest Update

My Issue/Question:

I'm pushing a font before making a call to ImGui::Begin(myTitle), but the title text is still in default font. How can I make the title use the font I pushed without making it the default font?

Screenshots/Video

image

Standalone, minimal, complete and verifiable example:

ImGui::PushID("Observer");
     
// This bit is included because I'm lost
std::string title(SOME_UNICODE_FROM_ICON_FONT_CPP_HEADERS_FONT_AWESOME);
title.append(" ");
title.append("Observer");

// Don't ask why I append ###, because some parts of my code is not present here
// (the bit where it adds some dynamic value to the title string), 
// but I included this because I'm lost
title.append("###");
title.append("Observer");

// Font is loaded for sure since AddFontFromFileTTF does not return NULL and
// bold font works for ImGui::Text
ImGui::PushFont(gui->GetFontBold()); // returns ImGui::GetIO().Fonts->Fonts[1]
ImGui::Begin(title.c_str()); // I am not in bold,
ImGui::Text("this text is for testing only"); // but I am bold, but why?

ImGui::End();
ImGui::PopFont();
ImGui::PopID();

Here is how I load my fonts:

// This function called once and only once when I launch my program.
// context is a static variable defined in my ImGuiIntegration.cpp file
ImGuiContext* ImGuiInit(GLFWwindow* window) {
	if(context == nullptr) {
		IMGUI_CHECKVERSION();
		context = ImGui::CreateContext();

		ImGuiIO& io{ ImGui::GetIO() };
		io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
		io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;

		io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
		io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

		// merge in icons from Font Awesome
		static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
		ImFontConfig icons_config;
		icons_config.MergeMode = true;
		icons_config.PixelSnapH = true;

                // I checked the return values with my debugger, and none of these 4 return NULL
		io.FontDefault = io.Fonts->AddFontFromFileTTF("Fonts/OpenSans-Regular.ttf", 18.0f);
		io.Fonts->AddFontFromFileTTF("Fonts/fa-regular-400-pro.ttf", 16.0f, &icons_config, icons_ranges);
		io.Fonts->AddFontFromFileTTF("Fonts/OpenSans-Bold.ttf", 18.0f);
		io.Fonts->AddFontFromFileTTF("Fonts/fa-solid-900-pro.ttf", 16.0f, &icons_config, icons_ranges);

		ImGui_ImplGlfw_InitForOpenGL(window, true);
		ImGui_ImplOpenGL3_Init("#version 430");

                /*
                   Some code regarding imgui colors, style etc.
                */
	}
	return context;
}
@ocornut
Copy link
Owner

ocornut commented Jan 27, 2022

Linking to #2700, #2539, #3537, #3521
In the case of font it's not really something we can easily change/fix, it would mean that potentially a single tab bar can use multiple font with varying height.

The default font at the time of NewFrame() will be used to submit docking-system tab bars.

@ocornut ocornut added the style label Jan 27, 2022
@aeris170
Copy link
Author

Linking to #2700, #2539, #3537, #3521 In the case of font it's not really something we can easily change/fix, it would mean that potentially a single tab bar can use multiple font with varying height.

The default font at the time of NewFrame() will be used to submit docking-system tab bars.

I see, since I don't have access to the line where NewFrame() is called (its in my lib, and I'm using my lib in another project) there is no alternative for me other than setting the desired font as default font. Thanks for the quick reply @ocornut.

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