/cui/label.d
D | 97 lines | 60 code | 24 blank | 13 comment | 4 complexity | f615d547d224aba3033adb1ca1e265b8 MD5 | raw file
1module cui.label; 2 3import djehuty; 4 5import io.console; 6 7import cui.widget; 8 9// Section: Console 10 11// Description: This console control abstracts a simple static text field. 12class CuiLabel : CuiWidget { 13 14 this( uint x, uint y, uint width, string text, 15 Color fgclr = Color.Blue, 16 Color bgclr = Color.Black ) { 17 super(x,y,width,1); 18 19 _forecolor = fgclr; 20 _backcolor = bgclr; 21 22 _value = text.dup; 23 } 24 25 override void onAdd() { 26 } 27 28 override void onInit() { 29 } 30 31 // Properties 32 33 // Description: this peroperty sets the value of the field 34 // newValue: the new value of the field 35 void text(string newValue) { 36 _value = newValue.dup; 37 onDraw(); 38 } 39 40 // Description: this property returns the value of the field 41 string text() { 42 return _value.dup; 43 } 44 45 // Description: this property sets the foreground color of the field 46 // fgclr: the color to set the foreground to 47 void forecolor(Color fgclr) { 48 _forecolor = fgclr; 49 onDraw(); 50 } 51 52 // Description: this property returns the foreground color of the field 53 Color forecolor() { 54 return _forecolor; 55 } 56 57 // Description: this property sets the background color of the field 58 // bgclr: the color to set the background to 59 void backcolor(Color bgclr) { 60 _backcolor = bgclr; 61 onDraw(); 62 } 63 64 // Description: this property returns the background color of the field 65 Color backcolor() { 66 return _backcolor; 67 } 68 69 override void onDraw() { 70 if (canDraw) { 71 Console.position(0, 0); 72 Console.forecolor = _forecolor; 73 Console.backcolor = _backcolor; 74 75 // draw as much as we can 76 77 if (_value.length > this.width) { 78 Console.put((_value[0..width])); 79 } 80 else { 81 Console.put(_value); 82 for (uint i; i < this.width - _value.length; i++) { 83 Console.put(" "); 84 } 85 } 86 } 87 } 88 89protected: 90 91private: 92 93 Color _forecolor = Color.Blue; 94 Color _backcolor = Color.Black; 95 96 string _value; 97}