public static ICoreUIWindow DomExample(this ICoreUIWindow window) { var root = new Div(d => { var solidColoredBorder = new BorderStyle { Paint = Color.Black, Width = 1, }; d.Style.Width = 50f.Percent(); d.Style.Height = 400f.Px(); d.Style.Border = new BorderBox(solidColoredBorder); d.Style.Margin = new Box(20, 40); d.Style.Padding = new Box(6); d.Style.Background = Color.AliceBlue; d.Style.FontStyles.FontSize = 18; }); return(window.Renderer(context => { var document = new CoreUIDomDocument(context, root); var drawboxCalculator = new DrawBoxCalculator(); drawboxCalculator.CalculateDrawBoxesForTree(document.Body); var drawBox = document.Body.DrawBox; var style = document.Body.Style; context.Clear(); context.FillStyle = style.Background; context.BeginPath(); context.StrokeStyle = style.Border.Top.Paint; context.LineWidth = (int)style.Border.Top.Width.Value; context.MoveTo(drawBox.BorderBox.Location).LineTo(new Point(drawBox.BorderBox.Right, drawBox.BorderBox.Location.Y)); context.StrokeStyle = style.Border.Right.Paint; context.LineWidth = (int)style.Border.Right.Width.Value; context.LineTo(new Point(drawBox.BorderBox.Right, drawBox.BorderBox.Bottom)); context.StrokeStyle = style.Border.Bottom.Paint; context.LineWidth = (int)style.Border.Bottom.Width.Value; context.LineTo(new Point(drawBox.BorderBox.Location.X, drawBox.BorderBox.Bottom)); context.StrokeStyle = style.Border.Left.Paint; context.LineWidth = (int)style.Border.Left.Width.Value; context.ClosePath(); context.Fill().Stroke(); DrawText(context, "This is text contained into a div, it is a veeeery long one, so, it should be split into several lines depending on the container's size.", root); })); }
public static ICoreUIWindow DrawingExample(this ICoreUIWindow window) => window.Renderer(context => { context.Clear(); context.FillStyle = Color.DarkBlue; context.LineWidth = 5; context.Font.FontSize = 25; context.BeginPath() .MoveTo(new Point(0, 0)) .LineTo(new Point(300, 250)) .LineTo(new Point(300, 400)) .ClosePath() .Fill() .Stroke(); context.FillRect(new Rectangle(360, 0, 240, 400)); context.ClearRect(new Rectangle(380, 40, 60, 60)); var text = "Hello World!"; var measure = context.MeasureText(text); context.Save(); context.LineWidth = 2; context.StrokeStyle = GradientSpec.Linear(new Point(0, 460 - 2), new Point(measure.Width, 460 - 2)) .AddColorStop(0, Color.Black) .AddColorStop(0.5f, Color.Red); context.FillStyle = GradientSpec.Linear(new Point(0, 460 - 2), new Point(0, 460 + measure.Height)) .AddColorStop(0, Color.AliceBlue) .AddColorStop(0.9f, Color.Green); context.Rect(new Rectangle( new Point(0, 460 - 2), measure + new Size(2, 2) ) ).Fill().Stroke(); context.Restore(); context.FillText(text, new Point(2, 460)); context.Rect(new Rectangle(380, 460, 200, 100)) .Fill() .Stroke(); });