1 module widgets.misc; 2 3 import dlangui; 4 5 class TimerTest : HorizontalLayout { 6 ulong timerId; 7 TextWidget _counter; 8 int _value; 9 Button _start; 10 Button _stop; 11 override bool onTimer(ulong id) { 12 _value++; 13 _counter.text = to!dstring(_value); 14 return true; 15 } 16 this() { 17 addChild(new TextWidget(null, "Timer test."d)); 18 _counter = new TextWidget(null, "0"d); 19 _counter.fontSize(32); 20 _start = new Button(null, "Start timer"d); 21 _stop = new Button(null, "Stop timer"d); 22 _stop.enabled = false; 23 _start.click = delegate(Widget src) { 24 _start.enabled = false; 25 _stop.enabled = true; 26 timerId = setTimer(1000); 27 return true; 28 }; 29 _stop.click = delegate(Widget src) { 30 _start.enabled = true; 31 _stop.enabled = false; 32 cancelTimer(timerId); 33 return true; 34 }; 35 addChild(_start); 36 addChild(_stop); 37 addChild(_counter); 38 } 39 } 40 41 class MiscExample : LinearLayout 42 { 43 this(string ID) 44 { 45 super(ID); 46 addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0")); 47 addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); 48 addChild(new ProgressBarWidget().progress(300).animationInterval(50)); 49 addChild(new ProgressBarWidget().progress(-1).animationInterval(50)); 50 addChild((new Button("BTN1")).textResource("EXIT")); //.textColor(0x40FF4000) 51 addChild(new TimerTest()); 52 53 MenuItem editPopupItem = new MenuItem(null); 54 editPopupItem.add(new Action(EditorActions.Copy, "MENU_EDIT_COPY"c, "edit-copy", KeyCode.KEY_C, KeyFlag.Control)); 55 editPopupItem.add(new Action(EditorActions.Paste, "MENU_EDIT_PASTE"c, "edit-paste", KeyCode.KEY_V, KeyFlag.Control)); 56 editPopupItem.add(new Action(EditorActions.Cut, "MENU_EDIT_CUT"c, "edit-cut", KeyCode.KEY_X, KeyFlag.Control)); 57 editPopupItem.add(new Action(EditorActions.Undo, "MENU_EDIT_UNDO"c, "edit-undo", KeyCode.KEY_Z, KeyFlag.Control)); 58 editPopupItem.add(new Action(EditorActions.Redo, "MENU_EDIT_REDO"c, "edit-redo", KeyCode.KEY_Y, KeyFlag.Control)); 59 editPopupItem.add(new Action(EditorActions.Indent, "MENU_EDIT_INDENT"c, "edit-indent", KeyCode.TAB, 0)); 60 editPopupItem.add(new Action(EditorActions.Unindent, "MENU_EDIT_UNINDENT"c, "edit-unindent", KeyCode.TAB, KeyFlag.Control)); 61 62 LinearLayout hlayout = new HorizontalLayout(); 63 hlayout.layoutWidth(FILL_PARENT); 64 //hlayout.addChild((new Button()).text("<<")); //.textColor(0x40FF4000) 65 hlayout.addChild((new TextWidget()).text("Several").alignment(Align.Center)); 66 hlayout.addChild((new ImageWidget()).drawableId("btn_radio").padding(Rect(5,5,5,5)).alignment(Align.Center)); 67 hlayout.addChild((new TextWidget()).text("items").alignment(Align.Center)); 68 hlayout.addChild((new ImageWidget()).drawableId("btn_check").padding(Rect(5,5,5,5)).alignment(Align.Center)); 69 hlayout.addChild((new TextWidget()).text("in horizontal layout")); 70 hlayout.addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5)).alignment(Align.Center)); 71 hlayout.addChild((new EditLine("editline", "Some text to edit"d)).popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); 72 hlayout.addChild((new EditLine("passwd", "Password"d)).passwordChar('*').popupMenu(editPopupItem).alignment(Align.Center).layoutWidth(FILL_PARENT)); 73 //hlayout.addChild((new Button()).text(">>")); //.textColor(0x40FF4000) 74 hlayout.backgroundColor = 0x8080C0; 75 addChild(hlayout); 76 77 LinearLayout vlayoutgroup = new HorizontalLayout(); 78 LinearLayout vlayout = new VerticalLayout(); 79 vlayout.addChild((new TextWidget()).text("VLayout line 1").textColor(0x40FF4000)); // 80 vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40FF8000)); 81 vlayout.addChild((new TextWidget()).text("VLayout line 2").textColor(0x40008000)); 82 vlayout.addChild(new RadioButton("rb1", "Radio button 1"d)); 83 vlayout.addChild(new RadioButton("rb2", "Radio button 2"d)); 84 vlayout.addChild(new RadioButton("rb3", "Radio button 3"d)); 85 vlayout.layoutWidth(FILL_PARENT); 86 vlayoutgroup.addChild(vlayout); 87 vlayoutgroup.layoutWidth(FILL_PARENT); 88 ScrollBar vsb = new ScrollBar("vscroll", Orientation.Vertical); 89 vlayoutgroup.addChild(vsb); 90 addChild(vlayoutgroup); 91 92 ScrollBar sb = new ScrollBar("hscroll", Orientation.Horizontal); 93 addChild(sb.layoutHeight(WRAP_CONTENT).layoutWidth(FILL_PARENT)); 94 95 addChild((new CheckBox("BTN2", "Some checkbox"d))); 96 addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); 97 addChild((new ImageWidget()).drawableId("exit").padding(Rect(5,5,5,5))); 98 addChild((new TextWidget()).textColor(0xFF4000).text("Text widget2").padding(Rect(5,5,5,5)).margins(Rect(5,5,5,5)).backgroundColor(0xA0A0A0)); 99 addChild((new RadioButton("BTN3", "Some radio button"d))); 100 addChild((new TextWidget(null, "Text widget3 with very long text"d)).textColor(0x004000)); 101 addChild(new VSpacer()); // vertical spacer to fill extra space 102 103 childById("BTN1").click = delegate (Widget w) { 104 Log.d("onClick ", w.id); 105 //w.backgroundImageId = null; 106 //w.backgroundColor = 0xFF00FF; 107 w.textColor = 0xFF00FF; 108 w.styleId = STYLE_BUTTON_NOMARGINS; 109 return true; 110 }; 111 childById("BTN2").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; 112 childById("BTN3").click = delegate (Widget w) { Log.d("onClick ", w.id); return true; }; 113 114 layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); 115 116 } 117 }