public void Arrange_should_layout_items_honoring_their_desired_size() { var area = new Rectangle(5, 5, 100, 100); var box = new HBox { Width = 100 }; var c1 = new Component { Width = 40, Height = 100 }; var c2 = new TestableComponent { Width = SizeUnit.Unlimited, Height = 100, OnMeasureCallback = _ => new Size(50, 100) }; var c3 = new Component { Width = 40, Height = 100 }; box.AddComponent(c1); box.AddComponent(c2); box.AddComponent(c3); box.Measure(area.Size, TestRendererContext.Instance); box.Arrange(area); c1.Layout.ShouldBe(new Rectangle(5, 5, 40, 100)); c2.Layout.ShouldBe(new Rectangle(45, 5, 50, 100)); c3.Layout.ShouldBe(new Rectangle(95, 5, 10, 100)); }
public void Arrange_should_distribute_remaining_width_between_components_with_unlimited_width() { var area = new Rectangle(5, 5, 100, 100); var box = new HBox { Width = 100 }; var c1 = new FixedMeasureComponent(20, 100) { Width = SizeUnit.Unlimited }; var c2 = new Component { Width = 25, Height = 100 }; var c3 = new FixedMeasureComponent(30, 100) { Width = SizeUnit.Unlimited }; box.AddComponent(c1); box.AddComponent(c2); box.AddComponent(c3); box.Measure(area.Size, TestRendererContext.Instance); box.Arrange(area); c1.Layout.ShouldBe(new Rectangle(5, 5, 20 + 12, 100)); c2.Layout.ShouldBe(new Rectangle(new Point(c1.Layout.Right, area.Top), new Size(25, 100))); c3.Layout.ShouldBe(new Rectangle(new Point(c2.Layout.Right, area.Top), new Size(30 + 13, 100))); }
public void Arrange_should_layout_children_horizontally_passing_max_height_but_limiting_area_to_not_expand_over_the_bounding_box() { var area = new Rectangle(5, 5, 30, 100); var box = new HBox(); var c1 = new Component { Width = 15, Height = 90 }; var c2 = new Component { Width = 20, Height = 110 }; var c3 = new Component { Width = 20, Height = 100 }; box.AddComponent(c1); box.AddComponent(c2); box.AddComponent(c3); box.Measure(area.Size, TestRendererContext.Instance); box.Arrange(area); c1.Layout.ShouldBe(new Rectangle(5, 5, 15, 90)); c2.Layout.ShouldBe(new Rectangle(5 + 15, 5, 15, 100)); c3.Layout.ShouldBe(new Rectangle(5 + 15 + 15, 5, 0, 100)); }
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 Measure_should_sum_width_and_take_biggest_height() { var box = new HBox(); box.AddComponent(new FixedMeasureComponent(22, 22)); box.AddComponent(new FixedMeasureComponent(11, 11)); box.AddComponent(new FixedMeasureComponent(33, 33)); box.Measure(new Size(100, 100), TestRendererContext.Instance); box.DesiredSize.ShouldBe(new Size(66, 33)); }
public void Measure_should_pass_size_to_the_component_with_width_decreased_by_the_width_of_previous_ones_but_not_smaller_than_0() { var box = new HBox(); var c1 = new Mock <IComponent>().WithDesiredSize(new Size(15, 10)); var c2 = new Mock <IComponent>().WithDesiredSize(new Size(20, 20)); var c3 = new Mock <IComponent>().WithDesiredSize(new Size(20, 20)); box.AddComponent(c1.Object); box.AddComponent(c2.Object); box.AddComponent(c3.Object); box.Measure(new Size(30, 100), TestRendererContext.Instance); c1.Verify(x => x.Measure(new Size(30, 100), TestRendererContext.Instance)); c2.Verify(x => x.Measure(new Size(15, 100), TestRendererContext.Instance)); c3.Verify(x => x.Measure(new Size(0, 100), TestRendererContext.Instance)); }
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_panels_and_hboxes() { var renderer = new PdfRenderer(); 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 doc = new PdfDocument(); var page = doc.AddPage(); page.Width = 50; page.Height = 40; renderer.Render(form, page); PdfImageComparer.ComparePdfs("panels_hbox", doc); }
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_rounded_panels_with_borders() { var renderer = new PdfRenderer(); var vbox = new VBox(); 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.Orange, Width = 24, Height = 24, Border = Border.Parse("1 black"), BorderRadius = BorderRadius.Parse(border) }); } vbox.AddComponent(hbox); } var doc = new PdfDocument(); var page = doc.AddPage(); renderer.Render(new Form(vbox), page, new PdfRendererOptions { AdjustPageSize = true }); PdfImageComparer.ComparePdfs("panels_rounded_border", doc); }
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); }
public void It_should_render_text_with_different_line_heights() { var renderer = new PdfRenderer(); 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 doc = new PdfDocument(); var page = doc.AddPage(); page.Width = 300; page.Height = 400; renderer.Render(form, page); PdfImageComparer.ComparePdfs("text_box_line_height", doc); }
public void Render_should_traverse_through_child_hierarchy_and_render_all_which_size_is_greater_than_0() { var panelRenderer = CreateMockRenderer <Panel>(); var hboxRenderer = CreateMockRenderer <HBox>(); var componentRenderer = CreateMockRenderer <Component>(); var renderer = new TestableRenderer(); renderer.RegisterRenderer(panelRenderer.Object); renderer.RegisterRenderer(hboxRenderer.Object); renderer.RegisterRenderer(componentRenderer.Object); var hbox = new HBox(); var vbox = new VBox(); var component1 = new Component { Width = 1, Height = 1 }; var component2 = new Component { Width = 1, Height = 1 }; var component3 = new Component { Width = 1, Height = 1 }; var component4 = new Component { Width = 1, Height = 1 }; var panel1 = new Panel { Width = 10, Height = 10, Inner = component1 }; var panel2 = new Panel { Width = 0, Height = 10, Inner = component2 }; var panel3 = new Panel { Width = 10, Height = 0, Inner = component3 }; var panel4 = new Panel { Width = 2, Height = 2, Inner = component4 }; hbox.AddComponent(vbox); hbox.AddComponent(panel1); vbox.AddComponent(panel2); vbox.AddComponent(panel3); vbox.AddComponent(panel4); var form = new Form(hbox); form.LayOut(new Size(int.MaxValue, int.MaxValue), TestRendererContext.Instance); var g = new object(); renderer.Render(g, form); hboxRenderer.Verify(x => x.Render(g, hbox, It.IsAny <Action <object, IComponent> >()), Times.Once); panelRenderer.Verify(x => x.Render(g, panel1, It.IsAny <Action <object, IComponent> >()), Times.Once); panelRenderer.Verify(x => x.Render(g, panel2, It.IsAny <Action <object, IComponent> >()), Times.Never); panelRenderer.Verify(x => x.Render(g, panel3, It.IsAny <Action <object, IComponent> >()), Times.Never); panelRenderer.Verify(x => x.Render(g, panel4, It.IsAny <Action <object, IComponent> >()), Times.Once); componentRenderer.Verify(x => x.Render(g, component1, It.IsAny <Action <object, IComponent> >()), Times.Once); componentRenderer.Verify(x => x.Render(g, component2, It.IsAny <Action <object, IComponent> >()), Times.Never); componentRenderer.Verify(x => x.Render(g, component3, It.IsAny <Action <object, IComponent> >()), Times.Never); componentRenderer.Verify(x => x.Render(g, component4, It.IsAny <Action <object, IComponent> >()), Times.Once); }