raygui icon indicating copy to clipboard operation
raygui copied to clipboard

`GetTextWidth()` returns incorrect value for multi-line strings

Open rfblock opened this issue 7 months ago • 0 comments

GetTextWidth only calculates the length of the first line instead of all lines. This also affects GuiMessageBox (and possibly other GUI functions that I haven't gotten around to testing).

Example 1 with GetTextWidth image

int main(void)
{
	SetConfigFlags(FLAG_VSYNC_HINT);
	InitWindow(800, 450, "Minimal Reproducible Example -- GetTextWidth");

	char exampleText[] = "Line 1\nL i n e  2";

	while (!WindowShouldClose())
	{
		// ===== DRAW ====
		BeginDrawing();
		ClearBackground(WHITE);

		// ===== GUI =====

		int width = GetTextWidth(exampleText);

		// This would ideally draw a box around the example text, but instead the text gets cut off
		GuiDrawRectangle((Rectangle) {20, 20, width + 6, 30}, 2, BLACK, WHITE);
		GuiLabel((Rectangle) {22, 20, width, 30}, exampleText);

		// ===== END GUI ====

		EndDrawing();
		// ===== END DRAW ====
	}

	CloseWindow();
}

Example 2 with GuiMessageBox Screenshot from 2024-07-20 14-28-21

int main(void)
{
	SetConfigFlags(FLAG_VSYNC_HINT);
	InitWindow(800, 450, "Minimal Reproducible Example -- GuiMessageBox");

	char exampleText[] = "Line 1\nL i n e  2";

	while (!WindowShouldClose())
	{
		// ===== DRAW ====
		BeginDrawing();
		ClearBackground(WHITE);

		// ===== GUI =====

		// This would ideally draw the example text in the message box, but it instead gets
		// cut off even though there is plenty of space
		GuiMessageBox((Rectangle) {20, 20, 250, 100}, "#191# Error!", exampleText, "OK");

		// ===== END GUI =====

		EndDrawing();
		// ===== END DRAW =====
	}

	CloseWindow();
}

rfblock avatar Jul 20 '24 08:07 rfblock