Gui.cs: Label trimming whitespace when height > 1

Created on 8 Jul 2020  路  8Comments  路  Source: migueldeicaza/gui.cs

The following code will strip the leading whitespace from the label:

Label appNameView = new Label() { X = 0, Y = 0, Height = 2, Width = Dim.Fill() };
appNameView.Text = "     how about this?";

image

Currently the WordWrap is implied based on the height of the label - not sure why..

https://github.com/migueldeicaza/gui.cs/blob/3ea9b23a27e393d148dbf99e1c3a39b463c1d7e5/Terminal.Gui/Core/TextFormatter.cs#L133

Might be useful to be able to set a property on the Label to enable/disable WordWrap.

Discovered when updating to the latest code base:

image

bug

All 8 comments

I made enabling wordwrap based on height of the label in an attempt to not break existing apps. Label previously supported mulit-line, but feebly.

Can you share with me the code that generates the image above and I'll look into a graceful way of dealing with this?

ok, to reproduce try this:

            Label appNameView = new Label() { X = 0, Y = 0, Height = Dim.Fill(), Width = Dim.Fill() };

            StringBuilder appName = new StringBuilder();
            appName.AppendLine(@"   ________               ___    ");
            appName.AppendLine(@"  / ____/ /_  ____ ______/ (_)__ ");
            appName.AppendLine(@" / /   / __ \/ __ `/ ___/ / / _ \");
            appName.AppendLine(@"/ /___/ / / / /_/ / /  / / /  __/");
            appName.AppendLine(@"\____/_/ /_/\__,_/_/  /_/_/\___/ ");
            appNameView.Text = appName.ToString();

@daltskin do you think the real problem here is I'm stripping leading/trailing whitespace at all? I mean, now that I think about it, the fact that label strips whitespace is surprising, and I'm a fan of the old tenet about the principle of "least astonishment" in design: "Do the thing that is least astonishing to to user."

I have a feeling that's the mistake I made. I don't have time right now to look at the code and start debugging this, but will get to it asap.

Agree - IMHO you shouldn't trim it at all.

Question: If I can fix it so the spaces are not trimmed correctly, do you REALLY need a "no wordwrap" option? Specifically, for the scenario with the ASCII art?

@daltskin I believe I fixed your issue with #785.

I did it without adding an API to turn off word wrap: I just made word wrap work correctly by not stripping whitespace (and I fixed another bug that was related).

You good with this?

Great work @tig - now it's looking great again :)

No need for a wordwrap option that I can currently foresee.

Thanks so much!

Great work @tig - now it's looking great again :)

No need for a wordwrap option that I can currently foresee.

Thanks so much!

Great. BTW, I tested (and fixed a bug regarding) using the Unicode non-breaking space char (/u00A0) as a way of forcing word wrap to not happen. Works great. Just do .Replace (' ', '/u00A0') to the Text.

Was this page helpful?
0 / 5 - 0 ratings