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

Text Wrapping is Incorrect #17

Open
dwjclark11 opened this issue Nov 23, 2024 · 5 comments
Open

Text Wrapping is Incorrect #17

dwjclark11 opened this issue Nov 23, 2024 · 5 comments
Assignees

Comments

@dwjclark11
Copy link
Owner

dwjclark11 commented Nov 23, 2024

Description
If the text is using any special characters such as !? etc with spaces with the minimal amount of wrapping, the next line will include the space before the word. This is not a desirable outcome.

Prerequisites

  • Have an game object in the world/scene with a text component.

To Reproduce
Steps to reproduce the behavior:

  1. Ensure there is a game object with a text component.
  2. Change the text to be Hello World! Hello World! Hello World! Hello World!
  3. Check to see if the wrapping is correct.

Expected behavior
The text should wrap at the desired wrap size and not have spaces in front of the first word on a new line.

Actual behavior
Text is not wrapping correctly and new lines start with a space in front. The space should be removed if on a new line.

Screenshots

  • To be added later.

Additional context

  • Currently in the scene in the editor for the Text Component, we are using an input text which will only allow a specific number of characters to be added before crashing. This must be fixed in order to test using the editor itself.
  • A work around for this would be to do this in the lua scripting and completely create the entity with the text component using the main.lua file and run the scene.

EX:

-- Main Lua Script!

gEntity = Entity("TextWrapTest", "")
gEntity:add_component(Transform(vec2(100, 100), vec2(1, 1), 0))
-- Add the component and set the wrap. Make sure to adjust the wrap and test multiple sizes.
gEntity:add_component(TextComponent("pixel", "Hello World! Hello World! Hello World! Hello World! ")).wrap = 400 

main = {
	[1] = {
		update = function()
			-- Nothing needed here
		end
	},
	[2] = {
		render = function()
			-- Nothing needed here
		end
	},
}
@dwjclark11
Copy link
Owner Author

dwjclark11 commented Nov 23, 2024

I am currently not able to reproduce this issue. I believe it may have been fixed with 7115aa4, further investigating.

Wrap 400

image

Wrap 200

image

Wrap 175

image

  • This wrapping is creating a new line. Not desirable; however, it is still "Working".
  • For this text, any wrap that is too small will log an error.

@TheEmperorE2
Copy link

Hi there, Im TyberZann01.
I using JoystixMonospace-Regular.ttf font.
Font Size 32.0f px
Padding: 4.0f or 0.0f
I dont make that typo 7115aa4 and checked the latest version of this file.

1
2
3
4

This is me version of generate batches: https://pastebin.com/gUMuV5h9

@dwjclark11
Copy link
Owner Author

dwjclark11 commented Nov 23, 2024

@TheEmperorE2 Thank you, I will look into this some more today!

@dwjclark11
Copy link
Owner Author

dwjclark11 commented Nov 24, 2024

@TheEmperorE2 I was able to reproduce the issue. The solution seems a bit tricky. I will look into this some more when I have some more time.
If you could try adding this as a work around. It will ensure that the first letter is an alpha value before creating a new line.

// ...More Above
else
{
	text_holder.pop_back(); // Pop off the newline character
}

if ( text_size > 0 )
{
	if ( std::isalpha( text_holder[ 0 ] ) )
	{
		textChunks.push_back( text_holder );
		temp_pos = textGlyph->position;
		text_holder.clear();
	}
	else
	{
		text_holder.erase( 0, 1 );
		temp_pos.x -= fontSize;
	}
}
// ... More Below

Thanks

@TheEmperorE2
Copy link

Thx man.

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