Author Topic: Textview customisation (flip entries positionning upside down)  (Read 2276 times)

vipo

  • Guest
solved
« Last Edit: December 05, 2022, 03:12:14 PM by someone »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Textview customisation
« Reply #1 on: March 11, 2014, 06:14:36 PM »
On top of what? The chat example doesn't hide messages, and like in any chat, the last message is always shown at the bottom. Are you trying to reverse the order, making newer messages show up on top? If so, just reverse the iteration order inside UITextList.Rebuild, line 263.

Starlink UI kit has a chat system where messages automatically fade out, but when you start typing, a history log gets shown.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Textview customisation
« Reply #2 on: March 11, 2014, 11:58:31 PM »
You are starting too high.
  1. for (int i = mParagraphs.size - 1; i >= 0; --i)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Textview customisation (flip entries positionning upside down)
« Reply #3 on: March 12, 2014, 09:54:39 PM »
Change the UITextList.UpdateVisibleText function instead:
  1.         protected void UpdateVisibleText ()
  2.         {
  3.                 if (isValid)
  4.                 {
  5.                         if (mTotalLines == 0)
  6.                         {
  7.                                 textLabel.text = "";
  8.                                 return;
  9.                         }
  10.  
  11.                         int maxLines = Mathf.FloorToInt((float)textLabel.height / lineHeight);
  12.                         int sh = Mathf.Max(0, mTotalLines - maxLines);
  13.                         int offset = Mathf.RoundToInt(mScroll * sh);
  14.                         if (offset < 0) offset = 0;
  15.  
  16.                         StringBuilder final = new StringBuilder();
  17.  
  18.                         for (int i = mParagraphs.size; maxLines > 0 && i > 0; ) // <-- this right here
  19.                         {
  20.                                 Paragraph p = mParagraphs.buffer[--i]; // <-- and this
  21.  
  22.                                 for (int b = 0, bmax = p.lines.Length; maxLines > 0 && b < bmax; ++b)
  23.                                 {
  24.                                         string s = p.lines[b];
  25.  
  26.                                         if (offset > 0)
  27.                                         {
  28.                                                 --offset;
  29.                                         }
  30.                                         else
  31.                                         {
  32.                                                 if (final.Length > 0) final.Append("\n");
  33.                                                 final.Append(s);
  34.                                                 --maxLines;
  35.                                         }
  36.                                 }
  37.                         }
  38.                         textLabel.text = final.ToString();
  39.                 }
  40.         }
...and if you want the paragraph lines to be reversed as well, then flip the inner 'for' loop as well.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Textview customisation (flip entries positionning upside down)
« Reply #4 on: April 01, 2014, 07:31:21 AM »
Because mParagraphs.buffer[mParagraphs.size] is outside the buffer.