Author Topic: UILabel - How does "Shrink Content" work?  (Read 7190 times)

Melkor

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
  • Whats the point of your existence?
    • View Profile
    • Denora Game Studios
UILabel - How does "Shrink Content" work?
« on: November 03, 2014, 07:16:11 PM »
Hi there

First of all thanks for your great plugin, second: if i am no mistaken nGUi doesn't support right to left languages like Arabic and Persian? For that matter i am using this plugin https://www.assetstore.unity3d.com/en/#!/content/2674, it is good for writing words and single line texts or multiline text by using /n in them manually but it cannot shrink them automatically based on size of the screen like nGUI does with the texts in its labels.

What i want to do: Create wall of texts! that can re size and shrink itself automatically so it can be fitted in any screen.

I use that plugin i linked before in combination with nGUI's Label to make Arabic and Persian GUI's, with that in mind lets go to where the problem rises: look at the pics i have attached, the first one is OK in landscape mode with no shrinking by nGUI but look at the second pic O_O when i change the screen to portrait mode where shrinking happens line are written in reverse from bottom top top O_O

I have no idea of how the shrinking works, if i know how it works i may be able to make it shrink texts correctly for the left to right languages! tho i am not a skilled programmer ;/ some helps would be nice ;p i guess i just have to find where line should  end and then i can put a /n in the string? but how O_O

Best Regards
Mohammad


None are more hopelessly enslaved than those who falsely believe they are free.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel - How does "Shrink Content" work?
« Reply #1 on: November 04, 2014, 10:05:38 AM »
You will need to ask the plugin's author, not I. You are correct in your initial assumption that NGUI doesn't support RTL languages natively.

Melkor

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
  • Whats the point of your existence?
    • View Profile
    • Denora Game Studios
Re: UILabel - How does "Shrink Content" work?
« Reply #2 on: November 04, 2014, 10:58:16 AM »
You will need to ask the plugin's author, not I. You are correct in your initial assumption that NGUI doesn't support RTL languages natively.

I asked him, he doesn't work on this plugin anymore and it works great for smal labels and smal text till they does't need to be shrinked. I want to use it with nGUI and use shrink text that comes with NGui, so i want to make it correct for everyone who use nGUI and want to write right to left, i know there are many.

Just if u can tell me how shrinking works ill try to collaborate with that plugin author to make something out of it and make it compatile with nGUI! and then u can use it in nGUI to support right to left too because that plugin is free.

Thanks.
None are more hopelessly enslaved than those who falsely believe they are free.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel - How does "Shrink Content" work?
« Reply #3 on: November 04, 2014, 11:08:08 AM »
You will want to look at UILabel.ProcessText function. It calculates the size using NGUIText.Wrap, and if it doesn't fit, reduces the font size by a notch and tries again until it does.

Melkor

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
  • Whats the point of your existence?
    • View Profile
    • Denora Game Studios
Re: UILabel - How does "Shrink Content" work?
« Reply #4 on: November 04, 2014, 11:51:42 AM »
You will want to look at UILabel.ProcessText function. It calculates the size using NGUIText.Wrap, and if it doesn't fit, reduces the font size by a notch and tries again until it does.

Thanks, ill look into it ASAP, But how does it know when to break a long line into 2 or more lines?
The re size part work correctly but when it break a long line into multi lines then the problem rises.

*Look at it:

Ill press enter after this line!

This long line is for test purpose and i don't know what else to write, please read it at your own risk!

*when i change screen size it will be correctly like this in left to right languages:

Ill press enter after this line!

This long line is for test purpose and i
don't know what else to write, please
read it at your own risk!

*but it will be like this in right to left languages:

read it at your own risk!
don't know what else to write, please
This long line is for test purpose and i

Ill press enter after this line!

*How do you think we can fix this? Can you change the text wrap function to recognize right to left languages and break lines correctly?
None are more hopelessly enslaved than those who falsely believe they are free.

Melkor

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
  • Whats the point of your existence?
    • View Profile
    • Denora Game Studios
Re: UILabel - How does "Shrink Content" work?
« Reply #5 on: November 05, 2014, 11:14:54 AM »
I'm trying to find where the wrap text happens, if i understand correctly in the NGUIText.cs it puts a \n where ever it see its needed. i'm trying to find the \n in the new proceeded (wraped) text but i cant find the \n in it O_O

I am using this code to store every line in a string so i can reverse the order of them to be shown:

  1. string[] test = mUILabel.processedText.Split(new string[] { "\n", "\r\n" }, System.StringSplitOptions.None);
  2.  
  3.             foreach (string s in test)
  4.             {
  5.                 Debug.Log(s);
  6.             }

But only 1 string will be stored in the "test" string as if there is only 1 line where i see 3 line in the game view when play it O_O

Any thoughts?
« Last Edit: November 05, 2014, 12:02:10 PM by Melkor »
None are more hopelessly enslaved than those who falsely believe they are free.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UILabel - How does "Shrink Content" work?
« Reply #6 on: November 06, 2014, 01:56:12 AM »
Your string split is way too long. It should be simply:
  1. processedText.Split('\n');

Melkor

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 9
  • Whats the point of your existence?
    • View Profile
    • Denora Game Studios
Re: UILabel - How does "Shrink Content" work?
« Reply #7 on: November 06, 2014, 02:42:11 AM »
Your string split is way too long. It should be simply:
  1. processedText.Split('\n');

It is not the problem i tested it, no different. hmmm its weird...
None are more hopelessly enslaved than those who falsely believe they are free.