public async Task It_should_allow_concurrent_processing() { var bmps = await Task.WhenAll(Enumerable.Range(0, 100).Select(_ => Task.Run(Generate))); BitmapComparer.CompareBitmaps("form", bmps.First()); BitmapComparer.CompareBitmaps("form", bmps.Last()); }
public void It_should_render_rounded_panels() { var renderer = new BitmapRenderer(); var vbox = new HBox(); var borders = new[] { new [] { "10 0 0 0", "0 10 0 0", "0 0 10 0", "0 0 0 10" }, new [] { "10 10 0 0", "10 0 10 0", "10 0 0 10", "0 0 10 10" }, new [] { "10 10 10 0", "10 0 10 10", "10 10 0 10", "10 10 10 10" } }; foreach (var boxLine in borders) { var hbox = new HBox(); foreach (var border in boxLine) { hbox.AddComponent(new Panel { Margin = new Spacer(1), BackgroundColor = Color.Blue, Width = 22, Height = 22, BorderRadius = BorderRadius.Parse(border) }); } vbox.AddComponent(hbox); } var bmp = new Bitmap(300, 40); renderer.Render(new Form(vbox), bmp); BitmapComparer.CompareBitmaps("panels_rounded", bmp); }
public void It_should_render_text_with_different_line_heights() { var renderer = new BitmapRenderer(); var content = new HBox { Width = SizeUnit.Unlimited }; content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Inner = new Label { TextColor = Color.Red, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?", LineHeight = 1.2f } }); content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Inner = new Label { TextColor = Color.Red, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?", LineHeight = 2f } }); content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Inner = new Label { TextColor = Color.Red, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?", LineHeight = 0.8f } }); var form = new Form(content); var bmp = new Bitmap(300, 400); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("text_box_line_height", bmp); }
public void It_should_render_images() { var redBlue = CreateBitmap(Brushes.Red, Brushes.Blue, 400, 400); var blueYellow = CreateBitmap(Brushes.Blue, Brushes.Yellow, 30, 30); var renderer = new BitmapRenderer(); var vBox = new VBox(); var hBox = new HBox(); AddComponent(hBox, new Image { Src = redBlue, Width = 40, Height = 40, Scaling = ImageScaling.Uniform }); AddComponent(hBox, new Image { Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center }); AddComponent(hBox, new Image { Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center left") }); AddComponent(hBox, new Image { Src = redBlue, Width = 40, Height = 30, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("center right") }); vBox.AddComponent(hBox); hBox = new HBox(); AddComponent(hBox, new Image { Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Center }); AddComponent(hBox, new Image { Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("top center") }); AddComponent(hBox, new Image { Src = redBlue, Width = 30, Height = 40, Scaling = ImageScaling.Uniform, Alignment = Alignment.Parse("bottom center") }); vBox.AddComponent(hBox); hBox = new HBox(); AddComponent(hBox, new Image { Src = redBlue, Width = 10, Height = 20, Scaling = ImageScaling.Fill }); AddComponent(hBox, new Image { Src = blueYellow, Scaling = ImageScaling.None }); AddComponent(hBox, new Image { Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Center, Scaling = ImageScaling.None }); AddComponent(hBox, new Image { Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("top left"), Scaling = ImageScaling.None }); AddComponent(hBox, new Image { Src = blueYellow, Width = 20, Height = 20, Alignment = Alignment.Parse("bottom right"), Scaling = ImageScaling.None }); vBox.AddComponent(hBox); var form = new Form(vBox); var bmp = renderer.Render(form); BitmapComparer.CompareBitmaps("bitmaps", bmp); }
public void It_should_render_panels_and_hboxes() { var renderer = new BitmapRenderer(); var hbox = new HBox { Alignment = Alignment.Center }; hbox.AddComponent(new Panel { BackgroundColor = Color.Yellow, Padding = new Spacer(5), Border = new Border(3, Color.Red), Alignment = new Alignment(VerticalAlignment.Bottom) }); hbox.AddComponent(new Panel { BackgroundColor = Color.Green, Padding = new Spacer(10, 5), Border = new Border(2, Color.Red), Alignment = new Alignment(VerticalAlignment.Center) }); hbox.AddComponent(new Panel { BackgroundColor = Color.Blue, Padding = new Spacer(15, 5), Border = new Border(1, Color.Red) }); var panel = new Panel { Width = SizeUnit.Unlimited, Height = SizeUnit.Unlimited, BackgroundColor = Color.LightSteelBlue, Padding = new Spacer(2), Inner = hbox, }; var form = new Form(panel); var bmp = new Bitmap(50, 40); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("panels_hbox", bmp); }
public void It_should_render_viewports() { var renderer = new BitmapRenderer(); var stack = new Stack(); stack.AddComponent(new Panel { Width = 100, Height = 100, Border = Border.Parse("1 #808080"), BackgroundColor = Color.LightBlue, BorderRadius = BorderRadius.Parse("25") }); stack.AddComponent(new Viewport { Alignment = Alignment.Parse("center left"), Width = 10, Inner = new Panel { Width = 40, Height = 40, Border = Border.Parse("1 #808080"), BackgroundColor = Color.White, BorderRadius = BorderRadius.Parse("20") }, ContentAlignment = Alignment.Parse("center right") }); stack.AddComponent(new Viewport { Alignment = Alignment.Parse("top center"), Height = 10, Inner = new Panel { Width = 40, Height = 40, Border = Border.Parse("1 #808080"), BackgroundColor = Color.White, BorderRadius = BorderRadius.Parse("20") }, ContentAlignment = Alignment.Parse("bottom center") }); stack.AddComponent(new Viewport { Alignment = Alignment.Parse("center right"), Width = 10, Inner = new Panel { Width = 40, Height = 40, Border = Border.Parse("1 #808080"), BackgroundColor = Color.White, BorderRadius = BorderRadius.Parse("20") }, ContentAlignment = Alignment.Parse("center left") }); stack.AddComponent(new Viewport { Alignment = Alignment.Parse("bottom center"), Height = 10, Inner = new Panel { Width = 40, Height = 40, Border = Border.Parse("1 #808080"), BackgroundColor = Color.White, BorderRadius = BorderRadius.Parse("20") }, ContentAlignment = Alignment.Parse("top center") }); stack.AddComponent(new Viewport { Alignment = Alignment.Parse("center center"), ClipMargin = Spacer.Parse("3 1"), Inner = new Panel { Width = 40, Height = 40, BackgroundColor = Color.White, Border = Border.Parse("1 #808080"), BorderRadius = BorderRadius.Parse("20") }, ContentAlignment = Alignment.Parse("center center") }); var form = new Form(stack); var bmp = renderer.Render(form); BitmapComparer.CompareBitmaps("viewport", bmp); }
public void It_should_render_text_with_alignments() { var renderer = new BitmapRenderer(); var labelBox = new HBox { Width = SizeUnit.Unlimited }; foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify }) { labelBox.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Label { Width = SizeUnit.Unlimited, TextColor = Color.Red, TextAlignment = align, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?" } }); } var areaBox = new HBox { Width = SizeUnit.Unlimited }; foreach (var align in new[] { TextAlignment.Left, TextAlignment.Right, TextAlignment.Center, TextAlignment.Justify }) { var textBox = new TextBox { Width = SizeUnit.Unlimited, TextAlignment = align }; textBox.AddComponent(new Label { TextColor = Color.Red, Text = "Hi Bob!", Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic) }); textBox.AddComponent(new Link { TextColor = Color.Black, Text = "Check out this: ", Font = new FontInfo(TestFontFamily.Serif, 12, FontInfoStyle.Regular) }); textBox.AddComponent(new Link { TextColor = Color.Purple, Text = "great link!!!", Font = new FontInfo(TestFontFamily.Serif, 8, FontInfoStyle.Underline), Uri = "http://google.com" }); areaBox.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Green, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = textBox }); } var content = new VBox { Width = SizeUnit.Unlimited }; content.AddComponent(labelBox); content.AddComponent(areaBox); var form = new Form(content); var bmp = new Bitmap(400, 400); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("text_box_align", bmp); }
public void It_should_render_text() { var renderer = new BitmapRenderer(); var content = new HBox { Width = SizeUnit.Unlimited }; content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.Yellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Label { TextColor = Color.Red, Font = new FontInfo(TestFontFamily.Serif, 10, FontInfoStyle.Underline | FontInfoStyle.Italic), Text = "Hello my friend!\nIt's nice to see you!\n\nWhat is a nice and sunny day, is not it?" } }); content.AddComponent(new Panel { Width = 100, Height = SizeUnit.Unlimited, BackgroundColor = Color.DarkSeaGreen, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = new Link { TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.Serif, 14, FontInfoStyle.Bold), Text = "How are you doing today?", Uri = "http://google.com" } }); var textBox = new TextBox(); textBox.AddComponent(new Label { Text = "Hello!\n", TextColor = Color.Green, Font = new FontInfo(TestFontFamily.Monospace, 20, FontInfoStyle.Underline) }); textBox.AddComponent(new Label { Text = "Hi Bob, nice to see you after", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Label { Text = "20", TextColor = Color.Red, Font = new FontInfo(TestFontFamily.SansSerif, 10, FontInfoStyle.Bold) }); textBox.AddComponent(new Label { Text = "years!\n", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Label { Text = "I'm sure you'd love to see my new", TextColor = Color.Black, Font = new FontInfo(TestFontFamily.SansSerif, 10) }); textBox.AddComponent(new Link { Text = "web", TextColor = Color.Blue, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com" }); textBox.AddComponent(new Link { Text = "site", TextColor = Color.Green, TextContinuation = true, Font = new FontInfo(TestFontFamily.SansSerif, 12, FontInfoStyle.Italic), Uri = "http://google.com" }); content.AddComponent(new Panel { Width = SizeUnit.Unlimited, Height = SizeUnit.Unlimited, BackgroundColor = Color.LightYellow, Margin = new Spacer(1), Border = new Border(1, Color.White), Padding = new Spacer(2), Inner = textBox }); var form = new Form(content); var bmp = new Bitmap(320, 400); renderer.Render(form, bmp); BitmapComparer.CompareBitmaps("text_box", bmp); }