1 // Written in the D programming language. 2 /++ 3 + Authors: KanzakiKino 4 + Copyright: KanzakiKino 2018 5 + License: LGPL-3.0 6 ++/ 7 module w4d.widget.wrapper; 8 import w4d.layout.placer.lineup, 9 w4d.layout.fill, 10 w4d.widget.base, 11 w4d.exception; 12 import std.conv; 13 14 /// A widget that wraps other wraps. 15 class WrapperWidget : Widget 16 { 17 protected Widget _child; 18 19 /// 20 override @property Widget[] children () 21 { 22 return _child? [_child]: []; 23 } 24 /// Child widget that is wrapped. 25 @property T child (T = Widget) () 26 { 27 return _child.to!T; 28 } 29 30 /// 31 this () 32 { 33 super(); 34 setLayout!( FillLayout, VerticalLineupPlacer ); 35 36 _child = null; 37 } 38 39 /// Changes the child widget. 40 Widget setChild ( Widget child ) 41 { 42 enforce( child, "Null is not a valid child." ); 43 _child = child; 44 requestLayout(); 45 return child; 46 } 47 /// Removes the child widget. 48 void removeChild () 49 { 50 _context.forget( _child ); 51 _child = null; 52 requestLayout(); 53 } 54 55 protected static template DisableModifyChild () 56 { 57 import w4d.widget.base, 58 w4d.exception; 59 60 enum DisableModifyChild_ErrorMes = "Modifying a child is not allowed."; 61 62 override Widget setChild ( Widget child ) 63 { 64 throw new W4dException( DisableModifyChild_ErrorMes ); 65 } 66 override void removeChild () 67 { 68 throw new W4dException( DisableModifyChild_ErrorMes ); 69 } 70 } 71 72 /// 73 override @property bool trackable () { return false; } 74 /// 75 override @property bool focusable () { return false; } 76 }