Quick Links: Gideros Home | Download Gideros | Developer Guide
Multiline analog for Textfield - Gideros Forums
Multiline analog for Textfield
  • unlying +1 -1 (+0 / -1 )
    Hello.
    I'm making e-books and for some books i need a large texts on one screen. Native function for multiline text is necessary.

    Hates: talis

  • You can "roll your own" by creating a multiline object that is based on a sprite, then use the getBounds() function (search the forums) to get the size of the text one word at a time and then when you wrap over the bounds of the box just add a new line and continue until all the text has been used.

    You'll end up with a parent sprite that has several children each one a single line of text.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • Well that's similar to what TextWrap is doing, except it's handling also text alignment, strict width, etc.

    But @unlying is it really so bad?
    I 've just created an example to try it out with 100 lines, and it didn't seem so bad. I attached it to the post for you to check out.

    I've also printed out how much time something takes in miliseconds, to understand what is the most slow in the process, and usually it is creating TextField objects.

    If you can provide sample texts to load and discuss other features of TextWrap, that you don't need to use, maybe it would be possible to create something a little simpler and more optimal.
    LargeText.zip
    4K
  • Re the speed - I wonder if when "render to texture" is enabled, it will be easier (and ultimately quicker) to render a page of text in one go and then just display that.

    In my widget library I have some quite complex objects (buttons with stacked layers, icons, text labels etc) and as soon as render to texture is available, I'll be looking into that.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • techdojotechdojo +1 -1 (+2 / -0 )
    @scouser - are you making sound effects for your new game?
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • @


    But @unlying is it really so bad?
    I 've just created an example to try it out with 100 lines, and it didn't seem so bad.


    Yep. It is not good. But you are looking in wrong side. It is not about lines in txt file. It is about lines on screen. Try any 20Kb file and you will see difference. It takes MUCH time.
    Try this app https://play.google.com/store/apps/details?id=com.pickup.pickup
    I wonder who gives 5 marks for this app, because even I can't use it normally with these lags:) And these nasty squares...
    One of file used in this app attached.
    bebad.txt
    31K
  • actually I was first experimenting with 400kb file, which loaded in 12 seconds on my ipod.
    Interesting that 30kb unicode takes 6 seconds to load

    So results with your text:
    Open File: 3.000244140625 ms
    Read Content: 4 ms
    Delete Children: 5.000244140625 ms
    Create test text: 5424.3100585938 ms
    Do the calculations: 5426.3103027344 ms
    Done with iteration: 6228.3559570313 ms
    Create TextWrap: 6228.3559570313 ms

    As you see it takes more than 5 seconds to create test TextField, to measure it's dimensions, so it would be possible to calculate approximate chunks of text for each line (restricted by some width)

    If in your case, restriction by width is not needed, and you only need to deal with new line symbols, it could be done without testing TextField dimensions in couple of seconds.

    But I suppose both alignment and restriction by width is needed.
  • Yes, both is needed.
  • Only thing that I could come up with is to provide not only width, but also maximal count of letters per line. This way TextWrap does not have to create large TextField just to test and calculate letter chunks needed and now it loads on my device in about a second.

    But you would have to experiment with different letter count values to find your suitable one.

    Hope that helps you in any way :)

    LargeText.zip
    218K
  • @ar2rsawseen, thanks. I appreciate your help. But may be i'm doing something wrong, because new version of your textwrap doesn't load all content. Only part of it. I tried two files and both of them stops on line 10. Not on start but on 10-20 letter(depends from file). And it is not a problem with variable, because if i print it, i get all text.
    May be you understand what i'm doing wrong?
  • hmm, ok I'll check it our after work today ;)
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    Ok, now that explains why it worked so fast. Because I wasn't loading the whole file :D

    Fixed and it runs not as fast as I hoped, but still somewhat 2 times faster than initial one.

    What I would recommend you to do, is to try not to load everything in one time. Firstly store every new text as separate string (using json or lua, or simply splitting string by new line)
    And then there are couple of options:

    You can create some sort of list (TableView perhaps), where you click on a list item and go to one specific text to read it.

    You can create pagination and load about 10 or 20 texts per page.

    Or you can create a sophisticated scrollerView, which would load new texts while you scroll down (for example pre load 10 next texts, that are not yet visible on display and then with each scrolled one, load new a new one, so you'll always have a new text to show, and new ones are preloaded as you scroll through window). Similar what twitter and facebook does with their posts

    LargeText.zip
    217K

    Loves: unlying

  • @ar2rsawseen, thanks much. It works much better. But funny thing. If in early version it was 1 square for a string from file then we have double squares now.
    This is screen from attached application with font 10.
    Image 1.png
    178 x 394 - 12K
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    Hmm I thought I've dealt with this issue. :D

    Ok first problem was because I've dealt with new line symbols \n, but squares were because or carriage returns from windows system ( symbol: \r )
    And now I firstly remove all carriage returns and then split by new lines. And it all works great on my windows system. :D

    Ok I think I've found the bug. I don't know why it does not show on my Gideros player.

    Here please try this project:

    LargeText.zip
    218K

    Loves: unlying

  • Looks better:) But squares still with us:)
    Don't you see squares if font is 10, not 20?
    Image 2.png
    196 x 391 - 15K
  • ar2rsawseenar2rsawseen +1 -1 (+2 / -0 )
    Thats the problem I dont see any squares in my Gideros player.
    Thats why I can't fix it.

    you can try and experiment with it in TextWrap.lua on 80-81 line try decreasing lastSpace or increasing last value, for example,
    lastSpace = startStr - 1
    last = last + 1


    Just try to experiment with values :)

    Loves: atilim, unlying

  • unlying +1 -1 (+1 / -0 )
    +2 works fine! Thanks! Finally it works totally well for me. You're my hero:)

    Loves: ar2rsawseen

  • gorkemgorkem +1 -1 (+1 / -0 )
    unlying said:

    You're my hero:)



    Sorry but we cannot share Arturs with you [-X

    Loves: ar2rsawseen

    Before starting with Gideros Studio, read our extensive Developer FAQ here

  • So results with your text:
    Open File: 3.000244140625 ms
    Read Content: 4 ms
    Delete Children: 5.000244140625 ms
    Create test text: 5424.3100585938 ms
    Do the calculations: 5426.3103027344 ms
    Done with iteration: 6228.3559570313 ms
    Create TextWrap: 6228.3559570313 ms


    How did you print this?
  • Well there were multiple print() statements using function from LuaSocket just to get milliseconds in the LargeText project I posted somewhere above. Then it all appears in console below inside Gideros Studio
  • atilimatilim +1 -1 (+3 / -0 )
    Hi all,

    After reading your posts, I want to see if it's possible to achieve fast and smooth results with big text files. I've followed the path of @ar2rsawseen but decided to add/remove lines dynamically.

    I'm attaching my current status. On my Samsung S 2, it loads bebad.txt in about 1/4 seconds and I can smoothly scroll the text. I'm planning to finish it soon and the API will be very similar to @ar2rsawseen's.

    cheers
    TextWrap2.zip
    63K
  • ar2rsawseenar2rsawseen +1 -1 (+1 / -0 )
    We're even.
    Cause now I'm speechless. ^:)^ :)

    Loves: chipster123

  • Is this going to be added to Gideros or will it be an add on?
  • Wow. It works! Looks fantastic! Tested in my app - works fast! Looks like dreams become true. And no squares now. Great!

Howdy, Stranger!

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

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters