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

Fixing Button text ignores breakline (\n) #2967 #24374

Closed
wants to merge 8 commits into from
Closed

Fixing Button text ignores breakline (\n) #2967 #24374

wants to merge 8 commits into from

Conversation

cesarpinho
Copy link

After a long review of the code, the discussion on the issue #2967 page and the other merged issues (#4327 and #21334), I present a solution proposal.

In this comment, @StraToN say :

line breaks in Buttons' captions won't work for the moment. I will leave this apart.

And that's what I did. I fix the tabs in the Buttons' captions, Labels text and Control tooltips and fix the line breaks in the Label text and Control tooltip.

Before

Break Line (\n) Tab (\t)
Inspector Label prints the characters prints the characters
Tooltip prints the characters prints the characters
Button prints the characters prints the characters
GDScript Label It works discards the characters
Tooltip It works discards the characters
Button discards the characters discards the characters

After

Break Line (\n) Tab (\t)
Inspector Label it works it works
Tooltip it works it works
Button prints the characters it works
GDScript Label It works it works
Tooltip It works it works
Button discards the characters it works

Fix #2967

When we add a \ n or \ t directly in the editor or add \ t to GDScript, those characters are either printed or discarded and have no effect.

This happen is because if the string contains '\ n', Variant object stores two printable characters '\' and 'n'.

So just check the string and change the characters '\' 'n' and '\' 't' to '\ n' and '' (4 spaces). For this was added a method to the String class, check_control_characters, which does this verification. And this method is called in the Control::get_tooltip.

Fixing  #2967 Button text ignores breakline (\n)
When we add a \ n or \ t directly in the editor or add \ t to GDScript, those characters are either printed or discarded and have no effect.

To fix this it was enough to call the check_control_characters method of the class String in the methods Label::set_text and Label::get_text.

Fixing  #2967 Button text ignores breakline (\n)
When we add a \ t directly in the editor or in the GDScript, those characters are either printed or discarded and have no effect.

To fix this it was enough to call the check_control_characters method of the class String in the methods Button::set_text and Button::get_text.

Fixing  #2967 Button text ignores breakline (\n)
scene/gui/control.cpp Outdated Show resolved Hide resolved
@Anutrix
Copy link
Contributor

Anutrix commented Oct 4, 2019

@cesarpinho Please fix the conflicts.

String str_begin = s.substr(0, tab_pos);
String str_end = s.substr(tab_pos + 1, s.length());

s = str_begin + " " + str_end;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always assume, that \t == 4 spaces? Shouldn't it be configurable per usecase?

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Nov 7, 2019
@Anutrix
Copy link
Contributor

Anutrix commented Apr 8, 2020

@cesarpinho Requesting rebase.

@aaronfranke
Copy link
Member

@cesarpinho The merges you pushed aren't the same as a rebase. Godot requires contributors to make their PRs have good Git history in order to be accepted.

Please see this article for more information: https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html

@Anutrix
Copy link
Contributor

Anutrix commented May 27, 2020

@cesarpinho Requesting rebase and squash.

@aaronfranke
Copy link
Member

aaronfranke commented Jun 17, 2020

This PR has not been in a good state for about a year, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Button text ignores breakline (\n) (fixed in master)
7 participants