private static void DrawText(ICoreUIDrawContext context, string text, CoreUIDomElement container) { context.Font = container.Style.FontStyles; var words = text.Split(' ', StringSplitOptions.RemoveEmptyEntries); var lines = new List <string>(); var currentLine = string.Empty; foreach (var word in words) { var candidateLine = $"{currentLine} {word}"; if (context.MeasureText(candidateLine).Width <= container.DrawBox.ContentBox.Width) { currentLine = candidateLine; } else { lines.Add(currentLine); currentLine = word; } } lines.Add(currentLine); var drawPoint = container.DrawBox.ContentBox.Location; lines.ForEach(l => { var measure = context.MeasureText(l); context.FillText(l, drawPoint); drawPoint = new Point(drawPoint.X, drawPoint.Y + measure.Height); }); }
public void CalculateDrawBoxesForTree(CoreUIDomElement element) { var box = CalculateWidth(element); box = CalculateHeight(element, box); box = CalculatePositions(element, box); element.DrawBox = box; }
// Postition private DrawBox CalculatePositions(CoreUIDomElement element, DrawBox box) { var style = element.Style; var marginBox = box.MarginBox; var borderBox = box.BorderBox; var paddingBox = box.PaddingBox; var contentBox = box.ContentBox; var parentLocation = element.Parent.DrawBox.ContentBox.Location; var location = parentLocation; var previousSibling = element.Previous(); if (previousSibling != null) { if (element.Style.Display == DisplayStyle.Block) { location = location + new Size(0, previousSibling.DrawBox.BorderBox.Location.Y); } var previousElement = previousSibling as CoreUIDomElement; if (previousElement != null) { } } marginBox.Location = location; borderBox.Location = style.Margin.GetDrawPosition(marginBox); paddingBox.Location = style.Border.Box.GetDrawPosition(borderBox); contentBox.Location = style.Padding.GetDrawPosition(paddingBox); return(new DrawBox { BorderBox = borderBox, ContentBox = contentBox, MarginBox = marginBox, PaddingBox = paddingBox }); }
// Height private DrawBox CalculateHeight(CoreUIDomElement element, DrawBox currentBox) => element.Style.Display switch {