1 module awebview.gui.widgets.checkbox; 2 3 import awebview.gui.widgets.button; 4 import awebview.gui.html; 5 import awebview.wrapper; 6 7 interface ICheckbox : IButton 8 { 9 @property 10 bool isChecked(); 11 12 @property 13 bool isChecked(bool bChecked); 14 } 15 16 17 abstract class Checkbox : DeclareSignals!(HTMLElement, "onClick"), ICheckbox 18 { 19 this(string id) 20 { 21 super(id, true); 22 } 23 24 25 override 26 void onClick(WeakRef!(const(JSArrayCpp))); 27 } 28 29 30 class InputCheckbox(alias attrs = null) 31 : TemplateHTMLElement!(DefineSignals!(Button, "onClick"), `<input type="checkbox" id="%[id%]" ` ~ buildHTMLTagAttr(attrs) ~ `>`) 32 { 33 this(string id) { super(id); } 34 35 36 override 37 void onStart(HTMLPage page) 38 { 39 super.onStart(page); 40 this["checked"] = _defaultValue; 41 } 42 43 44 override 45 @property 46 bool isChecked() 47 { 48 if(activity) 49 return this["checked"].get!bool; 50 else 51 return _defaultValue; 52 } 53 54 55 override 56 @property 57 void isChecked(bool bChecked) 58 { 59 if(activity) 60 this["checked"] = bChecked; 61 else 62 _defaultValue = bChecked; 63 } 64 65 66 private: 67 bool _defaultValue; 68 }