1 // Written in the D programming language.
2 /++
3  + Authors: KanzakiKino
4  + Copyright: KanzakiKino 2018
5  + License: LGPL-3.0
6 ++/
7 module w4d.layout.placer.lineup;
8 import w4d.layout.placer.base,
9        w4d.util.vector;
10 import gl3n.linalg;
11 import std.algorithm;
12 
13 /// A Placer object that lineups the children.
14 class LineupPlacer(bool H) : Placer
15 {
16     /// Whether the Placer lineups horizontally.
17     alias Horizon = H;
18 
19     protected vec2 _childSize;
20     protected vec2 _basePoint;
21     protected vec2 _usedSize;
22 
23     ///
24     this ( PlacerOwner owner )
25     {
26         super( owner );
27     }
28 
29     protected void clearStatus ()
30     {
31         _childSize = style.box.clientSize;
32         _basePoint = style.clientLeftTop;
33         _usedSize  = vec2(0,0);
34     }
35     protected void updateStatus ( vec2 placedSize )
36     {
37         const length = placedSize.getLength!H;
38         const weight = placedSize.getWeight!H;
39 
40         _basePoint.getLength!H += length;
41         _usedSize .getLength!H += length;
42 
43         _usedSize.getWeight!Horizon =
44             max( _usedSize.getWeight!H, weight );
45     }
46 
47     ///
48     override vec2 placeChildren ()
49     {
50         clearStatus();
51         foreach ( child; children ) {
52             auto sz = child.layout( _basePoint, _childSize );
53             if ( !child.style.floating ) {
54                 updateStatus( sz );
55             }
56         }
57         return _usedSize;
58     }
59 }
60 /// A Placer object that lineups the children horizontally.
61 alias HorizontalLineupPlacer = LineupPlacer!true;
62 /// A Placer object that lineups the children vertically.
63 alias VerticalLineupPlacer = LineupPlacer!false;