Label text character check

Started by Slasher, Sun 21/09/2014 11:19:36

Previous topic - Next topic

Slasher

Hi,

quote from punaman:
Labels used to have a 200 character limit, but this has been removed in the latest 2.72 beta (so long as you use the Label.Text="" approach)

I'm using 3.2.1.  I'm not sure what the character limit is for labels.

Anyhow, I have a gui set up with three labels (one for each page of a case note book). Each label is only shown if it contains text, which can be added in any order (page arrows will display).

What I am aiming to do is have ags do a live count of characters in a label and when it reaches the maximum automatically put the text into the next label etc.

Help much appreciated.



Crimson Wizard

#1
Slasher, what Pumaman was speaking about was the memory limit of a label, not visual limit.
If I understand correctly, your problem is that you need to calculate a visual limit, so that the labels would wrap text?

You may use "GetTextWidth" function to know text visual width and compare this with label width (or gui width):
Code: ags

int width = GetTextWidth(lblText1.Text, lblText1.Font);
if (width > lblText1.Width)
{
   // move some text to the next label
}


Slasher

Hi Crimson,

I think its more about height rather than width. Like when the label has reach maximum characters it will wrap text to the next label. Bearing in mine I use Append for many lines that are added.

I will see if I can use/adjust your code.

cheers

slasher


Crimson Wizard

#3
Oh. So you have a wrapping line?
In which case you may use... guess what? GetTextHeight! :D


Code: ags

int height = GetTextHeight(lblText1.Text, lblText1.Font, lblText1.Width + 1);
if (height > lblText1.Height)
{
   // move some text to the next label
}


Notice I use "lblText1.Width + 1" instead of just "lblText1.Width". There's a very old bug in AGS that is fixed by adding 1 to width.

Slasher

Hi Crimson,

i put your script in rep exec:

Code: ags
int height = GetTextHeight(LNotes.Text, LNotes.Font, LNotes.Width + 1);
if (height > LNotes.Height)
{
 // move some text to the next label... should go from LNotes to LNotes2 label.
 // when I click arrow to go to the next page the label does not display the text (click next page arrow and do labels visible properties.
  
}
 


I just get an error come up to shut down game.. after adding more lines than a label takes.

(roll)

cheers

SMF spam blocked by CleanTalk