Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

display.newText API Docs
Started by jack95 Aug 04 2018 12:59 AM

3 replies to this topic

Best Answer Rob Miracle , 06 August 2018 - 01:40 PM

Your display.newText() in your onRowRender() function never specifies a width:

            local rowTitle = display.newText({
                parent = rowParent,
                text = row.params.message,
                x = 15,
                y = 45/2
            })

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jack95

[GLOBAL: userInfoPane.html]
jack95
  • Contributor

  • 189 posts
  • Corona SDK

https://docs.coronalabs.com/api/library/display/newText.html

 

Not sure if this indicates a build (since it links to one) that the API is against, or if the docs were updated via

Revision 2018.3340

 

Either way, the API describes:

width (optional)

Number. If supplied, text will be wrapped at this width.

 

When i use the text string:

 

                local group = display.newGroup()

                local tmp = display.newText({
                    parent = group,
                    text = "[General] testQUXXE: testing time - 1533400997 super duper ever any way can this work",
                    width = 400
                })
 
I don't see it wrapping. This seems like the docs are incorrect or a bug in the existing build. Can someone tell me if I'm missing something that would explain this inconsistency?


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 posts
  • Corona Staff

How is it not working? I used this simple project (with an 800x1200 config.lua):
 

local centerX, centerY = display.contentCenterX, display.contentCenterY
  
local group = display.newGroup()

local tmp = display.newText({
    parent = group, 
    text = "[General] testQUXXE: testing time - 1533400997 super duper ever any way can this work",
    width = 400     
})              

tmp.x = centerX
tmp.y = centerY
tmp:setFillColor(1)

and this is what I see in the simulator:

Attached File  Screen Shot 2018-08-05 at 3.25.15 PM.png   185.13KB   0 downloads

 

Rob



[TOPIC: post.html]
#3

jack95

[GLOBAL: userInfoPane.html]
jack95
  • Contributor

  • 189 posts
  • Corona SDK

This is very odd. When in a tableView, it does not.

local widget = require( "widget" )

local screenLeft = display.screenOriginX
local screenWidth = display.contentWidth - screenLeft * 2
local screenTop = display.screenOriginY
local screenHeight = display.contentHeight - screenTop * 2

local screenTopSB = display.screenOriginY + display.topStatusBarContentHeight
local screenHeightSB = display.contentHeight - screenTopSB

local group = display.newGroup()
--local background = display.newImageRect( group, "bg.jpg", screenWidth, screenHeightSB )
--background.x = screenWidth/2
--background.y = screenHeightSB/2+display.topStatusBarContentHeight

local topRect = display.newRect(
    group,
    screenWidth/2,
    screenTopSB,
    screenWidth,
    300
)
topRect:setFillColor(0.5,1,0)

local textToAdd = "Testing time - "..os.time(os.date("!*t")).." --------- ----------- ----------- ---------- -------"

local tableView = widget.newTableView({
    left = screenLeft,
    top = screenTopSB+200,
    width = screenWidth,
    height = screenHeightSB-200,
    hideBackground = true,
    noLines = true,
    topPadding = 30,
    bottomPadding = 30,
    isBounceEnabled = false,
    hideScrollBar = true
})

function testCase1NoCustomRender()
    local msgText = "[start]"..textToAdd..textToAdd..textToAdd
    local newTextObj = display.newText({
        text = msgText,
        width = screenWidth
    })
    local msgHeight = newTextObj.height
    print("Msg Height calculated to be:"..msgHeight.." width:"..screenWidth)
    tableView:insertRow(newTextObj)
end

function testCase2CustomRender()
    local tableView2 = widget.newTableView({
        left = screenLeft,
        top = screenTopSB+200,
        width = screenWidth,
        height = screenHeightSB-200,
        hideBackground = true,
        noLines = true,
        topPadding = 30,
        bottomPadding = 30,
        isBounceEnabled = false,
        hideScrollBar = true,
        onRowRender = function( event )
            -- Get reference to the row group
            local row = event.row
            local rowParent = event.row

            local rowWidth = row.contentWidth
            local rowHeight = row.contentHeight
            print("rowWidth:"..rowWidth)
            print("rowHeight:"..rowHeight)

            local containerPanel = display.newRect(rowParent, rowWidth/2, rowHeight/2, screenWidth, rowHeight)
            containerPanel:setFillColor(1)

            print("render row:"..row.params.message)

            local rowTitle = display.newText({
                parent = rowParent,
                text = row.params.message,
                x = 15,
                y = 45/2
            })
            rowTitle:setFillColor( 0 )
            rowTitle.anchorX = 0
        end
    })

    local msgText = "[start]"..textToAdd..textToAdd..textToAdd
    print("msg:"..msgText)
    local group = display.newGroup()
    local tmp = display.newText({
        parent = group,
        text = msgText,
        width = 400
    })
    local msgHeight = tmp.height
    print("Msg Height calculated to be:"..msgHeight.." width:"..screenWidth)
    group:removeSelf()
    group = nil
    tableView2:insertRow{
        isCategory = false,
        rowHeight = msgHeight,
        rowColor = {
            default = { 255, 255, 255, 0 }
        },
        params = {
            message = msgText
        }
    }
end
--testCase1NoCustomRender()
testCase2CustomRender()



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,714 posts
  • Corona Staff

  Best Answer

Your display.newText() in your onRowRender() function never specifies a width:

            local rowTitle = display.newText({
                parent = rowParent,
                text = row.params.message,
                x = 15,
                y = 45/2
            })

Rob




[topic_controls]
[/topic_controls]