Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
TextWrap with scrolling — Gideros Forum

TextWrap with scrolling

incipientincipient Member
edited July 2013 in General questions
Hi Giderosians,

I am after a "TextWrap" with scrolling (finger slide scrolling). I have looked at as2's, atilims, and talis', however they don't seem to support it.

Had anyone come up with a solution? (or a library! :) )

Thanks for any help!

Comments

  • unlyingunlying Guru
    edited July 2013 Accepted Answer
    omg! We can't upload even .lua files. Wtf?

    here:

    howto= gideros.class(Sprite)

    function howto:init()
    y=0
    local file = io.open("howto.txt", "r")
    local str = file:read("*all")
    file:close()
    str = str:gsub("\13\10", "\10")
    textwr=TextWrap2.new(str, application:getContentWidth()-10, application:getContentHeight()-10, 22, font1)
    self:addChild(textwr)
    textwr:setPosition(10,10)
    self:addEventListener(Event.ADDED_TO_STAGE, self.onAddedToStage, self)
    end
    function howto:onAddedToStage()
    self:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    self:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    self:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)

    end
    function howto:onMouseDown(event)
    sy = event.y
    textwr.y0 = event.y

    end

    function howto:onMouseUp(event)
    isMouseDown = false
    end


    function howto:onMouseMove(event)
    if textwr == nill then

    else
    local dy = sy - event.y
    y = y + dy
    sy = event.y
    textwr:setScrollPosition(0, y)
    end


    end

    Likes: incipient

    +1 -1 (+1 / -0 )Share on Facebook
  • talistalis Guru
    edited July 2013
    Hi @incipent,
    Just to make your further posts more effective i would like to share some information. Maybe you already know but anyway repeating will not hurt i guess :D

    1-You can refer to any forum member by a '@' suffix and the nickname as prefix.
    When you do that there will be a notification to that user so the probability to miss the discussion becomes lower.
    like @talis or @incipent

    2-This one will be about your question. Actually @unlying already gave a solution so i will not repeat it. I will just try to describe you the logic behind it.
    All actions (inputs) from user are handled as events in Gideros. In order for you to act according to those inputs you should have to register those inputs inside your lua code.
    (Listen, hook ... them)
    This is done by addEventListener function. In unlying's example you can see that this function is called like,
    self:addEventListener( ...
    this is because unlying created a class called howto, and define those eventlisteners to the object itself. self refers to howto class' itself.
    Inside those eventlistener there are some built in input types like
    Event.MOUSE_DOWN, Event.MOUSE_UP,Event.MOUSE_Move ... those are already defined inside Gideros. (You can define your own events also but that's another topic :D )
    The second paremeter is the function that Gideros will run whenever those input types occur. In the above example, whenever
    Event.MOUSE_DOWN occurs self.onMouseDown function will be called
    Event.MOUSE_UP occurs self.onMouseUp function will be called
    Event.MOUSE_MOVE occurs self.onMouseMove function will be called

    (You can change the name of the called function any rename it, although as a good coding practice try to name them logically like unlying did
    )
    There is one more important event lies there in the code which is Event.ADDED_TO_STAGE.
    This will be triggered by Gideros whenever an ui element will be drawn on the screen.(Stage) like an image. Of course lets not forget that those events will be only valid for the class "howto", because all events are registered as self:addEventListener(.. inside the "howto" class.

    I hope that those information will help you to understand better aabout events.
    For more detailed and official information please refer to the documentation itself.
    http://docs.giderosmobile.com/events.htm






  • incipientincipient Member
    edited August 2013
    Hi @talis, @unlying

    thanks heaps for the help on this one! I didn't know about the '@' thing, very good to know :)

    I really appreciate the help, I tweaked your code a little unlying - removed a few variables, and added an upper and lower scroll boundary. I also wrapped it all into the TextWrap2.lua file, so all you need to call is "textwrap2variable:setYScrollListener(listener)" and it'll scroll =) (or, should scroll!)
    I only needed Y scroll, so didn't do any X scrolling =/

    I have attached my lua file if anyone else comes across it and finds it helpful =)

    edit: I'm hopeless at this! fixed scroll area...again -.-
    lua
    lua
    TextWrap2.lua
    8K
Sign In or Register to comment.