Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

ScrollBox, a class for scrolling text

edited April 2012 in Code Sharing Posts: 384

Hi All,

I was making a scrolling window for text, and ended up also with a pinch to change font size and three-finger touch to move the box around.
I found @Herwig's zoom library useful in getting to grips with it! See http://twolivesleft.com/Codea/Talk/discussion/550/zoom-library

You can find my code all in one blob at https://gist.github.com/2283493

I left the Touch class in debug mode to show the pretty average touch value... :)

One thing has me puzzled though: the text disappears when you zoom in past a certain point, which depends on the amount of text and the textWrap size... Any ideas?

Tagged:

Comments

  • Posts: 118

    Isn't it that textSize should not exceed 2048 pixels (as I mentioned in my zoom library)?

  • Posts: 384

    I think you are right @Herwig, although the x dimension is fairly small, making the font size bigger increases the y dimension, which is not drawn due to clip. When a decent amount of text is used, we will run into this problem.

    How should we overcome it? String manipulation would work but might be too slow with copies being made internally on concatenation etc. Would a table of words being table.concat ed into a strIng be faster?

  • edited October 24 Posts: 25

    @Fred. thanks first. this is what I want. and it is very good to use.

    agree with what you said , String manipulation would work but is be too slow with copies being made internally on concatenation etc.

    I tried some codes, to get each letter or line and draw again.. it counts too many in each draw . and make app much slow.

    but the limit in your code is still obvious. i test your code in my mini2. if the length is more than HEIGHT ( around the limit) , texts cannot be shown.

    if zoom in and shown in proper fontsize, letters are very small.

    is it a limit of COdea , or Lua ? any idea to solve it ?

  • Posts: 384
    Hi @totorofat , thanks for asking, but it has been so long since I wrote it that I had completely forgotten about it... :) it's over to you now - I hope you can improve it and share with the community. Best of luck!
  • dave1707dave1707 Mod
    Posts: 6,325

    @totorofat If the text length is too long, then Codea doesn’t show it. I would say it’s a Codea limit and not a Lua limit. The only way that I know of to get around this is to move just the text you want to display into another string so it doesn’t exceed the limit. It’s easy to copy text from one string to another, but to do it as you scroll text in a scroll box isn’t easy. You need to know the position in the string where each line in the scroll box starts so the text isn’t jumping around as you scroll the text.

  • Posts: 25

    @dave1707 thanks dave. I understand what you said. but the way make my present app slow very obvious. sometime , it looks like that some other codes are not operated ( at first , the function is ok. after running somet time, app is slow . the some function is missing. ) So I will adjust my code in many place. now I am still using the above method to text on.

    I count the height and width of strings . due to persentage, I get the biggest fontsize I can use . then text on screen. it works well now. but I know it cannot work for long way . if string is too long, fontsize could be very small and that is no meaning.

    if can unlock the limit, that is too much good. ( ye , maybe you need to do too much. arreciate so much ) . but then, what we should do is only tween the text , from left to right, front bottom to top. very easi. scrolling will be much easy to code.

Sign In or Register to comment.