Skip to content

Conversation

iTutFadU
Copy link

start can be non-zero since the method is public. Otherwise it counts newlines before the start of the actual text in range.

@Stefterv
Copy link
Collaborator

Stefterv commented Sep 29, 2025

Hi @iTutFadU could you show through screenshots what this change would entail?

@iTutFadU
Copy link
Author

The text will show up at the correct height (here green) instead of counting newlines preceding it before the range (here red).

The example code:

String text = "Some\n\ntext\nwith\nnewlines";
char[] chars;
float textWidth;

void setup() {
    size(500, 500, P2D);
    textFont(createFont("Arial", 50));
    textAlign(LEFT, TOP);
    chars = text.toCharArray();
    textWidth = textWidth(text.substring(6, text.length()));
}

void draw() {
    background(20);
    
    fill(#FF5555);
    text(chars, 6, text.length(), 0, 0);
    
    fill(#55FF55);
    text(text.substring(6, text.length()), width / 2, 0);
}

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

Successfully merging this pull request may close these issues.

2 participants