ScrollView: text width & auto-scroll

Dear all, 

I came back after a while and I see a great forum improvement. Kudos!

By the way, I ask your opinions on something I’m trying to do, but I’m not sure how to do it. I am using the sample ScrollView, and I can place where I want it. Good. Now the questions :slight_smile:

How can I modify how the ScrollView wraps the text with new lines? I’ve tried to set the scrollWidth property, but it didn’t affect anything. 

And the hard one:

How can I “auto-scroll” the view?

I mean, it should automagically go up (as if it were dragged) at a steady rate, but I’d like to be able to get touch events. So that if I want I can set it back to the origin, and after a timeout, it starts going up again.

Thanks & Cheers!

Hi @milicchio,

Welcome back! First one should be relatively simple… you need to set the width on the newText() object to restrict its width and force the lines to wrap. The width of the ScrollView will not automatically effect that change to the text. Remember that you can restrict the width of the “text box” but specify 0 for its height, which will make the text box adjust to whatever height is necessary to accommodate all of the text (within the device’s texture size limit).

#2 is a bit harder. Have you tried dispatching touch “move” events to the ScrollView in a Runtime listener using object:dispatchEvent()? It may not work, but it’s worth a try…

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Hope this helps,

Brent

Thanks, Brent! The text width worked perfectly.

For the auto-scroll, I’ve tried, but it didn’t do anything. I may have misunderstood how to create and properly dispatch events. That’s what I’ve tried: 

 timer.performWithDelay(1000, function() print("dispatch!") local eventB = { name = "touch", y = 100, yStart = 100, phase = "began" } scrollView:displatchEvent(eventB) local eventM = { name = "touch", y = 0, yStart = 100, phase = "moved" } scrollView:displatchEvent(eventM) end)

Initially I only dispatched the “moved” phase, but it didn’t work. Well, even starting a “began” before doesn’t do any good :frowning:

Hi @milicchio,

Is this a copy-paste from your actual code? I notice you spelled the command wrong: “displatch” when it should be “dispatch”. :slight_smile:

Brent

Curse you typos!

But it didn’t work even with the correct “displatch” :frowning:

Hi @milicchio,

Welcome back! First one should be relatively simple… you need to set the width on the newText() object to restrict its width and force the lines to wrap. The width of the ScrollView will not automatically effect that change to the text. Remember that you can restrict the width of the “text box” but specify 0 for its height, which will make the text box adjust to whatever height is necessary to accommodate all of the text (within the device’s texture size limit).

#2 is a bit harder. Have you tried dispatching touch “move” events to the ScrollView in a Runtime listener using object:dispatchEvent()? It may not work, but it’s worth a try…

http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html

Hope this helps,

Brent

Thanks, Brent! The text width worked perfectly.

For the auto-scroll, I’ve tried, but it didn’t do anything. I may have misunderstood how to create and properly dispatch events. That’s what I’ve tried: 

 timer.performWithDelay(1000, function() print("dispatch!") local eventB = { name = "touch", y = 100, yStart = 100, phase = "began" } scrollView:displatchEvent(eventB) local eventM = { name = "touch", y = 0, yStart = 100, phase = "moved" } scrollView:displatchEvent(eventM) end)

Initially I only dispatched the “moved” phase, but it didn’t work. Well, even starting a “began” before doesn’t do any good :frowning:

Hi @milicchio,

Is this a copy-paste from your actual code? I notice you spelled the command wrong: “displatch” when it should be “dispatch”. :slight_smile:

Brent

Curse you typos!

But it didn’t work even with the correct “displatch” :frowning: