Concept of max width/height for custom measure function #160

Closed
opened 2016-01-05 06:37:09 -08:00 by emilsjolander · 2 comments
emilsjolander commented 2016-01-05 06:37:09 -08:00 (Migrated from github.com)

When implementing a custom measure function there is currently no way of knowing of the width and height passed in refer to an exact height and width or a maximum value. For example when centering a node with a custom measure function it will be passed the width and height of its parent as this is the maximum size it can be measured at. The node being measured does not have this information however and will have to make a guess.

I suggest we add something along the lines of android's concept of measurement modes (MeasureSpec). so that nodes being measured know whether they must measure to a size exactly, at most, or if the can just ignore it totally (this is currently encoded in the size by looking for NaN).

@lucasr @vjeux

When implementing a custom measure function there is currently no way of knowing of the width and height passed in refer to an exact height and width or a maximum value. For example when centering a node with a custom measure function it will be passed the width and height of its parent as this is the maximum size it can be measured at. The node being measured does not have this information however and will have to make a guess. I suggest we add something along the lines of android's concept of measurement modes (MeasureSpec). so that nodes being measured know whether they must measure to a size exactly, at most, or if the can just ignore it totally (this is currently encoded in the size by looking for NaN). @lucasr @vjeux
NekR commented 2016-01-19 16:12:12 -08:00 (Migrated from github.com)

Just hit same problem today. I expected measure function to have both width and height as NaN for centered element with no sizes. But only height is NaN in this situation, while weight is the width of parent.

Just hit same problem today. I expected measure function to have both `width` and `height` as `NaN` for centered element with no sizes. But only `height` is `NaN` in this situation, while `weight` is the width of parent.
NekR commented 2016-01-19 16:20:42 -08:00 (Migrated from github.com)

Sounds more like a bug to me, does measure function really expects sizes of parent node?

For example this makes it impossible to implement measurement for text views, I have following algorithm in mind and it doesn't work: if dimension of node is set -- use it, else -- use size of contained text.

UPD: Okay, I can use node.layout.dimensions to get real metrics of node. What is the point of width and height arguments then?

Sounds more like a bug to me, does measure function really expects sizes of parent node? For example this makes it impossible to implement measurement for text views, I have following algorithm in mind and it doesn't work: if dimension of node is set -- use it, else -- use size of contained text. **UPD:** Okay, I can use `node.layout.dimensions` to get real metrics of node. What is the point of `width` and `height` arguments then?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#160
No description provided.