Text Y axis in scrollView

Well, I created a scrollView and inserted a long text in it and scroll height is alright but there is a problem

When I insert the text it appears from its middle and not from the first word…

I can change that by changing the Y axis but I have really many texts so is there a calculation or a way for making the text appear from the first word ?

Corona SDK display objects are by definition referenced from their center.  To change this, change their anchor positions:

local myText = display.newText(...) myText.anchorX = 0 myText.anchorY = 0

now when you say:

myText.x = 0 myText.y = 0

They will be drawn from their top left corner.

Worked! Thanks,

I have one other question

I just noticed that when I got my text from the .txt file text the text is not all appearing its not a ScrollHeight.

It seems like a Text height problem but I have set the text height to 0 so it automatically set it…

It may be that the text has exceeded its limit but how can I know ?

And if Yes, how can I create a text object with the rest string when I don’t know where did it reach the limit…

Usually if you exceed the maximum texture limit, you will get a white block, not your text.  We  have a tutorial for working with large blocks of text:

https://coronalabs.com/blog/2014/06/17/tutorial-working-with-large-blocks-of-text/

Rob

then the problem wasn’t about exceeding the text limit . the problem is after inserting the text into the scroll view not all the text appears.and i have set the height of the text to 0 for an automatic setting the height.

Maybe you should post a screen shot of what’s going on as well as the relevant code.

Rob

[lua]local function createText(text, y)

    local scrollText = display.newText {

        text=text,

x=10,

y=y,

width = 290,

height = 0,

font=native.systemFontBold,

fontSize=20,

align = “center”

}

    scrollText.anchorX = 0

scrollText.anchorY = 0

    return scrollText

end

local sceneChapterPath

function scene:create( event )

    sceneGroup = self.view

    --Removed lines that doesn’t contain anything to do with the problem

    local scrollView = widget.newScrollView

{

    top = 100,

    left = 10,

    width = 300,

    height = 400,

    backgroundColor = { 1, 1, 1, 0.5 },

    --scrollWidth = 600,

    --scrollHeight = 800,

horizontalScrollDisabled = true,

}

local fileHandle, errorString = io.open( system.pathForFile(sceneChapterPath), “r” )

if fileHandle then

   local contents = fileHandle:read( “*a” )

local chapterText = createText(contents, 0)

print(chapterText.text)

        scrollView:insert( chapterText )

–scrollView:setScrollHeight(5000)

    else

   print(errorString)

end

end[/lua]

The text printed from this line

print(chapterText.text)

is not the same that is visible in the scrollView…

the printed one shows all of the text, the one in the scrollView looks like in the images

Images:

http://i.imgur.com/5W2e677.png

http://i.imgur.com/PdKLlJp.png

EDIT: I found out that when I change the font the text is all appearing and well, but is that considered a limit problem ?

Corona SDK display objects are by definition referenced from their center.  To change this, change their anchor positions:

local myText = display.newText(...) myText.anchorX = 0 myText.anchorY = 0

now when you say:

myText.x = 0 myText.y = 0

They will be drawn from their top left corner.

Worked! Thanks,

I have one other question

I just noticed that when I got my text from the .txt file text the text is not all appearing its not a ScrollHeight.

It seems like a Text height problem but I have set the text height to 0 so it automatically set it…

It may be that the text has exceeded its limit but how can I know ?

And if Yes, how can I create a text object with the rest string when I don’t know where did it reach the limit…

Usually if you exceed the maximum texture limit, you will get a white block, not your text.  We  have a tutorial for working with large blocks of text:

https://coronalabs.com/blog/2014/06/17/tutorial-working-with-large-blocks-of-text/

Rob

then the problem wasn’t about exceeding the text limit . the problem is after inserting the text into the scroll view not all the text appears.and i have set the height of the text to 0 for an automatic setting the height.

Maybe you should post a screen shot of what’s going on as well as the relevant code.

Rob

[lua]local function createText(text, y)

    local scrollText = display.newText {

        text=text,

x=10,

y=y,

width = 290,

height = 0,

font=native.systemFontBold,

fontSize=20,

align = “center”

}

    scrollText.anchorX = 0

scrollText.anchorY = 0

    return scrollText

end

local sceneChapterPath

function scene:create( event )

    sceneGroup = self.view

    --Removed lines that doesn’t contain anything to do with the problem

    local scrollView = widget.newScrollView

{

    top = 100,

    left = 10,

    width = 300,

    height = 400,

    backgroundColor = { 1, 1, 1, 0.5 },

    --scrollWidth = 600,

    --scrollHeight = 800,

horizontalScrollDisabled = true,

}

local fileHandle, errorString = io.open( system.pathForFile(sceneChapterPath), “r” )

if fileHandle then

   local contents = fileHandle:read( “*a” )

local chapterText = createText(contents, 0)

print(chapterText.text)

        scrollView:insert( chapterText )

–scrollView:setScrollHeight(5000)

    else

   print(errorString)

end

end[/lua]

The text printed from this line

print(chapterText.text)

is not the same that is visible in the scrollView…

the printed one shows all of the text, the one in the scrollView looks like in the images

Images:

http://i.imgur.com/5W2e677.png

http://i.imgur.com/PdKLlJp.png

EDIT: I found out that when I change the font the text is all appearing and well, but is that considered a limit problem ?