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

GetTextWidth() returns incorrect value for multi-line strings #415

Open
rfblock opened this issue Jul 20, 2024 · 0 comments
Open

GetTextWidth() returns incorrect value for multi-line strings #415

rfblock opened this issue Jul 20, 2024 · 0 comments

Comments

@rfblock
Copy link

rfblock commented Jul 20, 2024

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();
}
@raysan5 raysan5 changed the title GetTextWidth returns incorrect value for multi-line strings GetTextWidth() returns incorrect value for multi-line strings Aug 21, 2024
@kotek900 kotek900 mentioned this issue Sep 19, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant