Label height VS String length...

Started by Slasher, Fri 24/11/2017 12:30:51

Previous topic - Next topic

Slasher

Hi,

I'm using GetTextHeight to determine if String text should go into label one or label two.

This works fine except that the length of any String is not checked first to see if its full length will fit into label 1 and subsequently if it's too long then the text gets cut off.

Code: ags

{
  int height = GetTextHeight(LNotes.Text, LNotes.Font, LNotes.Width + 1);

  if (height >LNotes.Height)
  {
  LNotes2.Text=LNotes2.Text.Append(" Brother Tingwell has a shard of stained glass embedded in his robe.");
  }
  else if (height <LNotes.Height){
  LNotes.Text=LNotes.Text.Append(" Brother Tingwell has a shard of stained glass embedded in his robe.");
}
}
 


I'm looking for a way for a String to carry over to label two if it exceeds the full height of a label one.

Cheers..


Khris

#1
Just to make sure: you do know that labels actually wrap text, right? All you need to do is increase the height of the label, and you will see the rest of your text.

I'm also confused by your question; you're describing an issue, but the code you posted already looks like an attempt at solving it. So are you asking how to deal with the original issue? Or how to fix your code?

dayowlron

I would set a variable to be the string you are trying to add and possibly make this a function, however with what you have below you just need to add the string you are trying to add to the text in line 2.
Also don't know if this is an issue but if it is short enough you add it to label 1, otherwise you add it to label 2 whether label 2 is large enough or not. not sure if that could be a potential problem in the future or not.
Code: ags

{
  String msg = " Brother Tingwell has a shard of stained glass embedded in his robe.";
  int height = GetTextHeight(LNotes.Text + msg, LNotes.Font, LNotes.Width + 1);
 
  if (height >LNotes.Height)
  {
  LNotes2.Text=LNotes2.Text.Append(msg);
  }
  else //if (height <LNotes.Height){
  LNotes.Text=LNotes.Text.Append(msg);
}

the main part is adding in the new message when checking height like I did in line 3.
Another change you might want to consider is removing the if after the else statement since it is not needed and if height happened to equal LNotes.Height then the message would not be added at all.
Pro is the opposite of Con                       Kids of today are so much different
This fact can clearly be seen,                  Don't you know?
If progress means to move forward         Just ask them where they are from
Then what does congress mean?             And they tell you where you can go.  --Nipsey Russell

Slasher

Khris... if I heighten the lablel the text will go down over the buttons at the bottom whereas it's just above them. It does word wrap and words get cut off.... Is there an alternative to dayowlron's way at fixing it?

dayowlron.... Sounds good but seems a lot of extra work.

There will be at least 30 String entries...

cheers





Khris

Ok, so let me get this straight. You have a label for in-game notes, and over the course of the game, more and more text gets added to the label. At some point the text would cover some buttons at the bottom of the GUI, so from that point on you want to append the text to a second label.

Could you post a screenshot of the GUI?

Also, after lots of years and lots of games, I guess you might want to finally tackle writing your own functions. Because right now it looks like as soon as you got the required lines to work, your plan was to paste them all over your room scripts....?

Slasher

#5
Khris

Quote[http://Also, after lots of years and lots of games, I guess you might want to finally tackle writing your own functions. Because right now it looks like as soon as you got the required lines to work, your plan was to paste them all over your room scripts....?
I did it without thinking about a cut off point.. And yes, a simple function that would control all this would have been more appropriate..

Here is the gui with text that gets cut short..


Snarky

There doesn't seem to be anywhere else for the text to go, though? Are you having the different pages on separate labels? That's really not the best way to do this.

What you want is to store the text in a string somewhere, and then simply change the label's text property depending on the Case and the page. The simplest way to break up the story into separate pages is to store it as an array of strings, one string per page: In that case you just have to work out the page breaks manually. Otherwise you have to write a function that does the text breaking: e.g. a function that you takes the full text and the page number as arguments, and returns the text for just that page as a result. It's not too difficult, really; you have the basics of it in the first post of the thread.

SMF spam blocked by CleanTalk