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

Strange thickness behavior when drawing an AddRect #6669

Open
ElectroidDes opened this issue Aug 1, 2023 · 3 comments
Open

Strange thickness behavior when drawing an AddRect #6669

ElectroidDes opened this issue Aug 1, 2023 · 3 comments

Comments

@ElectroidDes
Copy link

Strange thickness behavior when drawing an AddRect:

When I create a normal window and draw a rectangle, a rectangle is drawn with a line width of 1 pixel:

bool open_bool;
ImGui::Begin("Test Rec", &open_bool);

ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 WinPos = ImGui::GetWindowPos();
draw_list->AddRect({ WinPos.x + 100,  WinPos.y + 100 }, { WinPos.x + 200,  WinPos.y +  200 }, IM_COL32(255, 255, 255, 255), 0.0f, 0, 1.0f);
ImGui::End();

Test_Rec_1

However, when I add a font setting for the window title text, the lineweight of the rectangle being drawn becomes 3px:

bool open_bool;

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]);
ImGui::Begin("Test Rec", &open_bool);
ImGui::PopFont();

ImDrawList* draw_list = ImGui::GetWindowDrawList();
ImVec2 WinPos = ImGui::GetWindowPos();
draw_list->AddRect({ WinPos.x + 100,  WinPos.y + 100 }, { WinPos.x + 200,  WinPos.y +  200 }, IM_COL32(255, 255, 255, 255), 0.0f, 0, 1.0f);

ImGui::End();

Test_Rec_2

This is right ? Is this how it should be?

@ocornut
Copy link
Owner

ocornut commented Aug 1, 2023

ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]);
ImGui::Begin("Test Rec", &open_bool);
ImGui::PopFont();

This is currently unsupported (see #3224) and should assert, if it doesn't assert it means you have assert disabled and you have a bigger problem.

@ElectroidDes
Copy link
Author

As a workaround, it works like this:

 bool open_bool;

 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[3]);
 ImGui::Begin("Test Rec", &open_bool);
 ImGui::PopFont();


 ImGui::PushFont(ImGui::GetIO().Fonts->Fonts[0]); //----->crutch

 ImDrawList* draw_list = ImGui::GetWindowDrawList();
 ImVec2 WinPos = ImGui::GetWindowPos();
 draw_list->AddRect({ WinPos.x + 100, WinPos.y + 100 }, { WinPos.x + 200, WinPos.y + 200 }, IM_COL32(255, 255, 255, 255), 0.0f, 0, 1.0 f);

 ImGui::PopFont(); //----->crutch

 ImGui::End();

@ocornut
Copy link
Owner

ocornut commented Aug 1, 2023

Please read my previous message.

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