Allow StyledLabel to return each line's height. |
|||
Issue descriptionWe have such a use case: 1. A list of item views. We use vertical BoxLayout to align the item views. 2. Each item view has two StyledLabel views: left and right. 3. The right StyledLabel has custom view, so the first line height will >= the first line height in the left StyledLabel. 4. We want to align the first line of the left and right views. In the GetHeightForWidth(int w) of the item view, we want to shift the left view by a delta and get the correct height. But this delta depends on if there is a custom view on the right StyledLabel. To implement this requirement, we only need to know the first line height of StyledLabel. But msw@ also suggested that the client can query any line height.
,
Feb 21 2018
In order to align StyledLabel A's top line with the top line of StyledLabel B, you'll need to layout StyledLabel B first. (You need to know/set the width of StyledLabel B to determine if line breaking puts a tall custom view on the first line) If the StyledLabel functionality of embedding custom views in text was implemented in RenderText, the equivalent function would be |Vector2d RenderText::GetLineOffset(size_t line_number);|. One alternative is to ensure all lines have a fixed height (depending on the font/language and custom view heights). Getting the [first] line's height is needed for the Keyboard Shortcut Viewer to align eg. "Copy" with "[CTRL] + [C]".
,
Feb 21 2018
Thanks for comments, msw@! I am trying the alternative in #1 before I add new functions in StyledLabel. Will update soon.
,
Feb 22 2018
It might be easier to implement GetLineOffset in StyledLabel. The way to Layout explicitly seems too much tricky code. I will upload a cl soon.
,
Feb 22 2018
,
Feb 22 2018
A corner case in #2, is that the top line of StyledLabel B may not have the custom view. So in this case, the top line height of A and B are already the same.
,
Feb 22 2018
As I said, you need to layout StyledLabel B first to determine an offset for A.
,
Feb 22 2018
Find a workaround without changing StyledLabel. I need to layout StyledLabel B and A in GetHeightForWidth of the item view. I will discard the cl if there is no other use cases to get line height. Thanks!
,
Feb 23 2018
This feature is not necessary for now. |
|||
►
Sign in to add a comment |
|||
Comment 1 by wutao@chromium.org
, Feb 21 2018