Here's the setup I encountered issue
let imageText = Node(
direction: .Column,
padding: Edges(top: 20, bottom: 20),
children: strings.map { (text : String) -> Node in
let image = Node(
size: CGSizeMake(100, 100)
)
let text = Node(
measure: { w in
println("\(w)") // Nan
label.text = text
label.preferredMaxLayoutWidth = w
return label.sizeThatFits(CGSizeMake(w, CGFloat.max))
})
let row = Node(
direction: Direction.Row,
children:[image, text]
)
return row
}
)
println(imageText.layout(maxWidth: 375).frame) // (0.0, 0.0, 7704.0, 240.0)
Notice the width wasn't obeying the maxWidth
we've put into our layout.
So Basically I want to implement something like this:
I had some sample data setup here:
let strings : [String] = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ex dolor, imperdiet vel tellus sollicitudin, ultrices maximus nunc. Ut non vehicula magna. Etiam sit amet varius lectus, et luctus dui. Sed eget blandit turpis. Nullam laoreet at felis non fermentum. Integer elit sem, tempus eget ex non, mattis porta lorem. Sed ut quam vel nibh luctus bibendum quis sed mi.",
"Fusce scelerisque rhoncus elementum. Maecenas ultricies est ex, ut varius mauris cursus at. Maecenas sollicitudin orci posuere, ultricies lacus vel, scelerisque nibh. Nullam a turpis a urna elementum posuere. Integer porttitor vestibulum urna lobortis tincidunt. Aliquam consectetur sem metus, et laoreet libero rutrum nec. Donec sed justo dapibus, mollis nibh volutpat, sollicitudin sem. Suspendisse tempor, velit ac ullamcorper pretium, sapien risus molestie enim, aliquam cursus ex massa a nisl. Duis gravida, diam eget rutrum sagittis, dui est malesuada mi, a dapibus eros odio sit amet tellus. Nunc porttitor nunc nec massa mollis, et pellentesque est egestas. Vivamus venenatis dignissim massa in euismod. Vestibulum rutrum ex a interdum varius. Donec convallis gravida dui eget viverra. Suspendisse tempor, lorem sit amet consequat mattis, libero ex dictum quam, eget iaculis felis velit eu nunc. Morbi eros lectus, aliquet at pulvinar sed, tempor malesuada elit. Integer blandit gravida felis.",
]
// Also setting up a label to calculate the size
let label = UILabel()
label.numberOfLines = 0
I tried a simpler setup and works as expected:
let textOnly = Node(
direction: .Column,
padding: Edges(top: 20, bottom: 20),
children: strings.map { (text : String) -> Node in
let text = Node(
measure: { w in
println("\(w)") // 375
label.text = text
label.preferredMaxLayoutWidth = w
return label.sizeThatFits(CGSizeMake(w, CGFloat.max))
})
return text
}
)
println(textOnly.layout(maxWidth: 375).frame) // (0.0, 0.0, 375.0, 669.0)
So is there something wrong with my setup or it's a bug that I encountered?
Thanks for helping out!