1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation; either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * gtkD is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with gtkD; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 17 */ 18 19 module gtk.OtherTests; 20 21 import glib.Timeout; 22 import gtk.AboutDialog; 23 import gtk.Application; 24 import gtk.ApplicationWindow; 25 import gtk.Box; 26 import gtk.Button; 27 import gtk.Dialog; 28 import gtk.GestureClick; 29 import gtk.Label; 30 import gtk.Window; 31 32 import std.stdio; 33 34 public class OtherTests : ApplicationWindow 35 { 36 37 Label byeLabel; 38 Timeout timeout; 39 40 this(Application application) 41 { 42 super(application); 43 setTitle("GtkD"); 44 45 Box box = new Box(GtkOrientation.VERTICAL, 2); 46 box.setMarginStart(10); 47 box.setMarginEnd(10); 48 box.setMarginTop(10); 49 box.setMarginBottom(10); 50 51 box.append(new Label("Hello World")); 52 53 Button button = new Button("About"); 54 button.addOnClicked(&onClicked); 55 button.addOnClicked(&popupAbout); 56 button.addOnClicked(delegate void(Button b){ 57 writefln("\nliterally clicked"); 58 }); 59 60 GestureClick gesture = new GestureClick(); 61 gesture.setPropagationPhase(PropagationPhase.CAPTURE); 62 gesture.addOnPressed(&mousePressed); 63 button.addController(gesture); 64 65 box.append(button); 66 67 byeLabel = new Label("Bye-bye World"); 68 box.append(byeLabel); 69 setChild(box); 70 71 addOnCloseRequest(&onCloseRequest); 72 show(); 73 74 timeout = new Timeout(1000, &changeLabel); 75 } 76 77 void mousePressed(int nPress, double x, double y, GestureClick gesture) 78 { 79 writefln("mousePressed"); 80 } 81 82 bool changeLabel() 83 { 84 switch ( byeLabel.getText() ) 85 { 86 case "Bye-bye World": byeLabel.setText("still here"); break; 87 case "still here": byeLabel.setText("close window"); break; 88 case "close window": byeLabel.setText("to terminate"); break; 89 default : byeLabel.setText("Bye-bye World"); break; 90 } 91 return true; 92 } 93 94 void onClicked(Button button) 95 { 96 writefln("\nOn click from Hello World %s", button); 97 } 98 99 void popupAbout(Button button) 100 { 101 with (new AboutDialog()) 102 { 103 104 string[] names; 105 names ~= "Antonio Monteiro (binding/wrapping/proxying/decorating for D)"; 106 names ~= "www.gtk.org (base C library)"; 107 setAuthors(names); 108 setDocumenters(names); 109 setArtists(names); 110 setLicenseType(License.LGPL_3_0); 111 setWebsite("https://gtkd.org"); 112 show(); 113 } 114 } 115 116 bool onCloseRequest(Window window) 117 { 118 destroy(); 119 writefln("Exit by request from HelloWorld"); 120 return false; 121 } 122 123 override string toString() 124 { 125 return "I Am HelloWorld"; 126 } 127 } 128 129 int main(string[] args) 130 { 131 auto application = new Application("org.gtkd.demo.othertests", GApplicationFlags.FLAGS_NONE); 132 application.addOnActivate(delegate void(_) { new OtherTests(application); }); 133 return application.run(args); 134 } 135