Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement text alignment inside its content box for a text node using box-model. #67

Open
zwcloud opened this issue Nov 15, 2020 · 0 comments

Comments

@zwcloud
Copy link
Owner

zwcloud commented Nov 15, 2020

For metrics's box-model inspector, this is temporarily implemented via reusing LayoutGroup in Metrics.LayoutTextInRectCentered:

private static Rect LayoutTextInRectCentered(Rect rect, string text)
{
Node group = new Node(rect.GetHashCode());
group.AttachLayoutGroup(false);
group.ContentSize = rect.Size;
group.RuleSet.ApplyOptions(GUILayout.Width(rect.Width).Height(rect.Height));
group.RuleSet.AlignmentVertical = Alignment.Center;
group.RuleSet.AlignmentHorizontal = Alignment.Center;
var textNode = new Node(text.GetHashCode());
textNode.AttachLayoutEntry();
textNode.ContentSize = centeredLabelRuleSet.CalcSize(text);
textNode.RuleSet.AlignmentVertical = Alignment.Center;
textNode.RuleSet.AlignmentHorizontal = Alignment.Center;
group.AppendChild(textNode);
group.Layout(rect.TopLeft);
return textNode.Rect;
}

This should be somehow inlined to be used elsewhere.

@zwcloud zwcloud changed the title Implement text alignment inside its content box for a text node uses box-model. Implement text alignment inside its content box for a text node using box-model. Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant