ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.46k stars 10.34k forks source link

Table font size problem with SetWindowFontScale #8138

Closed liyunlong23 closed 2 weeks ago

liyunlong23 commented 3 weeks ago

Version/Branch of Dear ImGui:

Version 1.90.9-docking, Branch: docking (master/docking/etc.)

Back-ends:

imgui_impl_win32.cpp + imgui_impl_dx9.cpp

Compiler, OS:

Windows11 + MSVC 2022

Full config/build information:

No response

Details:

My Issue/Question: When I create a table in ImGui::BeginChild, in ImGui::BeginTable("##ItemList",3,ImGuiTableFlags_ScrollY, outer_size), if ImGuiTableFlags is set to ImGuiTableFlags_ScrollY, I will encounter the problem that the fontsize is forced to be restored to the initial default fontsize. I called ImGui::SetWindowFontScale(0.8f) before the child window ImGui::BeginChild; the font size in the table in the child window will be restored to 22.0f, and it should be consistent with the size of other texts FontScale(0.8f), but it is not consistent. I changed ImGuiTableFlags_ScrollY to ImGuiTableFlags_None and this problem will no longer exist. By printing my screenshots, you can see the change in font size. The font in the table is obviously forced to be restored to the initial default size.

Screenshots/Video:

Snipaste_2024-11-08_18-02-07

Minimal, Complete and Verifiable Example code:

ImGui::SeparatorText(ICON_FA_PERSON_RAYS u8"item");
const float TEXT_BASE_HEIGHT = ImGui::GetTextLineHeightWithSpacing();
ImVec2 outer_size = ImVec2(0.0f, TEXT_BASE_HEIGHT * 4);
ImGui::Text("before_FontSize:%f", ImGui::GetFontSize());
static const char* itemTest[3] = { "one","two","three" };
if (ImGui::BeginTable("##ItemList", 3, ImGuiTableFlags_ScrollY, outer_size))
{
    ImGui::TableSetupColumn(u8"number", ImGuiTableColumnFlags_NoHide);
    ImGui::TableSetupColumn(u8"itemCode");
    ImGui::TableSetupColumn(u8"itemName");
    ImGui::TableHeadersRow();
    for (int row = 0; row < 9; row++)
    {
        ImGui::TableNextRow();
        for (int cell = 0; cell < IM_ARRAYSIZE(itemTest); cell++)
        {
            if (!ImGui::TableSetColumnIndex(cell) && cell > 0)
                continue;
            if (cell == 0) {
                int number = row + 1;
                ImGui::Text("Line %d", number);
            }
            else {
                ImGui::Text("fontSize:%f",ImGui::GetFontSize());
            }
        }
    }
    ImGui::EndTable();
}
ImGui::Text("after_FontSize:%f", ImGui::GetFontSize());
ImGui::Text(u8"Test Content!");
ocornut commented 3 weeks ago

Hello, This is linked to #2701, #6471, #1018. SetWindowFontScale() is currently not well supported, but we should work on it.

liyunlong23 commented 2 weeks ago

Well, I now add setWindowFontScale(0.8f) inside the table, which is simple and convenient