1use Test::More tests => 43;
2
3use Graphics::Primitive::Insets;
4use Geometry::Primitive::Point;
5use Layout::Manager::Compass;
6use Graphics::Primitive::Container;
7use Graphics::Primitive::Component;
8
9BEGIN {
10    use_ok('Layout::Manager::Compass');
11}
12
13my $legend = Graphics::Primitive::Container->new(
14    layout_manager => Layout::Manager::Compass->new, name => 'legend'
15);
16my $text1 = Graphics::Primitive::Component->new( minimum_width => 10, minimum_height => 15);
17my $text2 = Graphics::Primitive::Component->new( minimum_width => 15, minimum_height => 10);
18$legend->add_component($text1, 'e');
19$legend->add_component($text2, 'w');
20
21my $legend2 = Graphics::Primitive::Container->new(
22    layout_manager => Layout::Manager::Compass->new, name => 'legend2'
23);
24my $text3 = Graphics::Primitive::Component->new( minimum_width => 10, minimum_height => 15);
25my $text4 = Graphics::Primitive::Component->new( minimum_width => 10, minimum_height => 10);
26$legend2->add_component($text3, 'n');
27$legend2->add_component($text4, 'w');
28
29my $legend3 = Graphics::Primitive::Container->new(
30    layout_manager => Layout::Manager::Compass->new, name => 'legend3'
31);
32my $text5 = Graphics::Primitive::Component->new( minimum_width => 10, minimum_height => 15);
33my $text6 = Graphics::Primitive::Component->new( minimum_width => 15, minimum_height => 10);
34my $text7 = Graphics::Primitive::Component->new( minimum_width => 10, minimum_height => 5);
35$legend3->add_component($text5, 'c');
36$legend3->add_component($text6, 'e');
37$legend3->add_component($text7, 'n');
38
39my $cont = new Graphics::Primitive::Container(
40    width => 120, height => 100,
41    padding => Graphics::Primitive::Insets->new(
42        top => 5, left => 4, right => 3, bottom => 2
43    )
44);
45
46$cont->add_component($legend, 's');
47$cont->add_component($legend2, 'n');
48$cont->add_component($legend3, 'w');
49
50cmp_ok($cont->component_count, '==', 3, 'root component_count');
51cmp_ok($legend->component_count, '==', 2, 'legend component_count');
52cmp_ok($legend2->component_count, '==', 2, 'legend2 component_count');
53cmp_ok($legend3->component_count, '==', 3, 'legend3 component_count');
54
55my $lm = Layout::Manager::Compass->new;
56$cont->layout_manager($lm);
57$cont->do_layout($cont);
58
59cmp_ok($legend->origin->x, '==', 4, 'legend origin x');
60cmp_ok($legend->origin->y, '==', 83, 'legend origin y');
61cmp_ok($legend->width, '==', 113, 'legend width');
62cmp_ok($legend->height, '==', 15, 'legend height');
63
64# cmp_ok($text1->origin->x, '==', 107, 'text1 origin x');
65cmp_ok($text1->origin->y, '==', 0, 'text1 origin y');
66cmp_ok($text1->width, '==', 10, 'text1 width');
67cmp_ok($text1->height, '==', 15, 'text1 height');
68
69cmp_ok($text2->origin->x, '==', 0, 'text2 origin x');
70cmp_ok($text2->origin->y, '==', 0, 'text2 origin y');
71cmp_ok($text2->width, '==', 15, 'text2 width');
72cmp_ok($text2->height, '==', 15, 'text2 height');
73
74cmp_ok($legend2->origin->x, '==', 4, 'legend2 origin x');
75cmp_ok($legend2->origin->y, '==', 5, 'legend2 origin y');
76cmp_ok($legend2->width, '==', 113, 'legend2 width');
77cmp_ok($legend2->height, '==', 25, 'legend2 height');
78
79cmp_ok($text3->origin->x, '==', 0, 'text3 origin x');
80cmp_ok($text3->origin->y, '==', 0, 'text3 origin y');
81cmp_ok($text3->width, '==', 113, 'text3 width');
82cmp_ok($text3->height, '==', 15, 'text3 height');
83
84cmp_ok($text4->origin->x, '==', 0, 'text4 origin x');
85cmp_ok($text4->origin->y, '==', 15, 'text4 origin y');
86cmp_ok($text4->width, '==', 10, 'text4 width');
87cmp_ok($text4->height, '==', 10, 'text4 height');
88
89cmp_ok($legend3->origin->x, '==', 4, 'legend 3 origin x');
90cmp_ok($legend3->origin->y, '==', 30, 'legend 3 origin y');
91cmp_ok($legend3->width, '==', 25, 'legend 3 width');
92# cmp_ok($legend3->height, '==', 25, 'legend 3 height');
93
94cmp_ok($text5->origin->x, '==', 0, 'text5 origin x');
95cmp_ok($text5->origin->y, '==', 5, 'text5 origin y');
96cmp_ok($text5->width, '==', 10, 'text5 width');
97cmp_ok($text5->height, '==', 48, 'text5 height');
98
99cmp_ok($text6->origin->x, '==', 10, 'text6 origin x');
100cmp_ok($text6->origin->y, '==', 5, 'text6 origin y');
101cmp_ok($text6->width, '==', 15, 'text6 width');
102cmp_ok($text6->height, '==', 48, 'text6 height');
103
104cmp_ok($text7->origin->x, '==', 0, 'text7 origin x');
105cmp_ok($text7->origin->y, '==', 0, 'text7 origin y');
106cmp_ok($text7->width, '==', 25, 'text7 width');
107cmp_ok($text7->height, '==', 5, 'text7 height');