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.base; 8 import w4d.layout.exception, 9 w4d.style.widget; 10 import gl3n.linalg; 11 12 /// A baseclass of Layout object. 13 /// Layout object decides children position to place 14 /// and calculates all styles. 15 abstract class Layout 16 { 17 protected Layoutable _owner; 18 19 /// Owner of the layout. 20 inout @property owner () { return _owner; } 21 22 protected @property style () 23 { 24 return _owner.style; 25 } 26 27 protected @property children () 28 { 29 return _owner.childLayoutables; 30 } 31 32 /// 33 this ( Layoutable owner ) 34 { 35 enforce( owner, "Owner is null." ); 36 _owner = owner; 37 } 38 39 /// Calculates styles and decodes position of children. 40 void place ( vec2, vec2 ); 41 } 42 43 /// An interface of layoutable objects. 44 interface Layoutable 45 { 46 /// Style data. 47 @property WidgetStyle style (); 48 49 /// Children. 50 @property Layoutable[] childLayoutables (); 51 52 /// Wanted size. 53 @property vec2 wantedSize (); 54 55 /// Places at the pos with the size. 56 vec2 layout ( vec2, vec2 ); 57 58 /// Shifts children. 59 void shiftChildren ( vec2 ); 60 }