zwcloud/ImGui

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

zwcloud opened this issue · 0 comments

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.