@@ -3950,6 +3950,99 @@ void RegisterTests_DrawList(ImGuiTestEngine* e)
39503950 ImGui::End ();
39513951 };
39523952
3953+ // ## Test word-wrapping logic
3954+ // Also see "widgets_text_wrapped", "widgets_text_wrapped_2", "widgets_inputtext_wordwrap_1"
3955+ // FIXME: This is currently a test bed and doesn't actually test/verify anything yet.
3956+ // FIXME: #9066 / #8838 for fuller CJK features.
3957+ t = IM_REGISTER_TEST (e, " drawlist" , " drawlist_text_wordwrap_1" );
3958+ t->GuiFunc = [](ImGuiTestContext* ctx)
3959+ {
3960+ ImGui::Begin (" Test Window" , NULL , ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
3961+
3962+ auto TextWidth = [](const char * s)
3963+ {
3964+ return ImGui::CalcTextSize (s).x ;
3965+ };
3966+ struct WordWrapTestCase
3967+ {
3968+ const char * Text;
3969+ float WrapWidth;
3970+ };
3971+ const WordWrapTestCase test_cases[] =
3972+ {
3973+ { " Hello World" , TextWidth (" Hello" ) },
3974+ { " Hello World" , TextWidth (" Hello " ) },
3975+ { " Hello World" , TextWidth (" Hello W" ) },
3976+ { " Hello World!" , TextWidth (" Hello" ) },
3977+ { " Hello World!" , TextWidth (" Hello " ) },
3978+ { " Hello World!" , TextWidth (" Hello W" ) },
3979+ { " abcde!." , FLT_MAX },
3980+ { " abcde!." , TextWidth (" abcde!." ) },
3981+ { " abcde!. That" , TextWidth (" abcde!." ) }, // #8139, #8439
3982+ { " Hello 1.4023" , TextWidth (" Hello 1.4" ) }, // #8503
3983+ { " example... this" , TextWidth (" example" ) }, // #9094
3984+ { " example... this" , TextWidth (" example." ) }, // #9094
3985+ { " example... this" , TextWidth (" example.." ) }, // #9094
3986+ { " example... this" , TextWidth (" example..." ) }, // #9094
3987+ { " example... this" , TextWidth (" example... " ) }, // #9094
3988+ { " a a a a a a a" , TextWidth (" a a a" ) }, // #8990
3989+ { " a a a a a a a" , TextWidth (" a a a " ) }, // #8990
3990+ };
3991+
3992+ ImDrawList* draw_list = ImGui::GetWindowDrawList ();
3993+ ImFont* font = ImGui::GetFont ();
3994+ float font_size = ImGui::GetFontSize ();
3995+ ImU32 text_col = ImGui::GetColorU32 (ImGuiCol_Text);
3996+
3997+ if (ImGui::BeginTable (" split" , 3 , ImGuiTableFlags_Borders))
3998+ {
3999+ ImGui::TableSetupColumn (" _None" );
4000+ ImGui::TableSetupColumn (" _WrapKeepBlanks" );
4001+ ImGui::TableHeadersRow ();
4002+
4003+ for (int n = 0 ; n < IM_ARRAYSIZE (test_cases); n++)
4004+ {
4005+ ImGui::TableNextRow ();
4006+ ImGui::TableSetColumnIndex (0 );
4007+ ImGui::TextDisabled (" %d" , n);
4008+
4009+ const WordWrapTestCase& tc = test_cases[n];
4010+ for (int step = 0 ; step < 2 ; step++)
4011+ {
4012+ ImGui::TableSetColumnIndex (step + 1 );
4013+
4014+ ImVec2 p = ImGui::GetCursorScreenPos ();
4015+ ImDrawTextFlags text_flags = ImDrawTextFlags_None;
4016+ if (step == 1 )
4017+ text_flags |= ImDrawTextFlags_WrapKeepBlanks;
4018+ float wrap_width = tc.WrapWidth ;
4019+
4020+ // Calculate text size (use internals so we can pass flags)
4021+ const char * p_end_text;
4022+ ImVec2 p_end_offset;
4023+ ImVec2 sz = ImFontCalcTextSizeEx (font, font_size, FLT_MAX, wrap_width, tc.Text , nullptr , nullptr , &p_end_text, &p_end_offset, text_flags);
4024+ // ImVec2 sz = font->CalcTextSizeA(font_size, FLT_MAX, wrap_width, tc.Text, nullptr);
4025+
4026+ draw_list->AddRect (p, p + sz, IM_COL32 (255 , 0 , 255 , 180 ));
4027+ draw_list->AddLine (p + ImVec2 (wrap_width, 0 .0f ), p + ImVec2 (wrap_width, sz.y ), IM_COL32 (255 , 255 , 0 , 255 )); // Wrap limit
4028+ draw_list->AddCircleFilled (p + p_end_offset, 2 .0f , IM_COL32 (255 , 0 , 255 , 255 )); // End offset
4029+
4030+ // Render text (use internals so we can pass flags)
4031+ font->RenderText (draw_list, font_size, p, text_col, draw_list->_ClipRectStack .back (), tc.Text , nullptr , wrap_width, text_flags);
4032+ // draw_list->AddText(nullptr, 0.0f, p, text_col, tc.Text, nullptr, wrap_width);
4033+
4034+ if (wrap_width < FLT_MAX)
4035+ ImGui::Dummy (ImVec2 (ImMax (sz.x , wrap_width), sz.y ));
4036+ else
4037+ ImGui::Dummy (sz);
4038+ }
4039+ }
4040+ ImGui::EndTable ();
4041+ }
4042+
4043+ ImGui::End ();
4044+ };
4045+
39534046 // ## Test VtxOffset
39544047 t = IM_REGISTER_TEST (e, " drawlist" , " drawlist_vtxoffset_basic" );
39554048 t->GuiFunc = [](ImGuiTestContext* ctx)
0 commit comments