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 CoreUIDomDocument(ICoreUIDrawContext context, CoreUIDomElement body) { _context = context; Body = body; Add(body); }
public static ICoreUIDrawContext StrokeRect(this ICoreUIDrawContext self, Rectangle rectangle) => self.Rect(rectangle) .Stroke();
public static ICoreUIDrawContext Rect(this ICoreUIDrawContext self, Rectangle rectangle) => self.BeginPath() .MoveTo(rectangle.Location) .LineTo(new Point(rectangle.Right, rectangle.Location.Y)) .LineTo(new Point(rectangle.Right, rectangle.Bottom)) .LineTo(new Point(rectangle.X, rectangle.Bottom)) .ClosePath();
public static ICoreUIDrawContext FillRect(this ICoreUIDrawContext self, Rectangle rectangle) => self.Rect(rectangle) .Fill();