1 #!/usr/bin/env dub 2 /+ 3 dub.sdl: 4 name "snippet6" 5 dependency "dwt" path="../../../../../../" version="*" 6 libs \ 7 "atk-1.0" \ 8 "cairo" \ 9 "dl" \ 10 "fontconfig" \ 11 "gdk-x11-2.0" \ 12 "gdk_pixbuf-2.0" \ 13 "gio-2.0" \ 14 "glib-2.0" \ 15 "gmodule-2.0" \ 16 "gobject-2.0" \ 17 "gthread-2.0" \ 18 "gtk-x11-2.0" \ 19 "pango-1.0" \ 20 "pangocairo-1.0" \ 21 "X11" \ 22 "Xcomposite" \ 23 "Xcursor" \ 24 "Xdamage" \ 25 "Xext" \ 26 "Xfixes" \ 27 "Xi" \ 28 "Xinerama" \ 29 "Xrandr" \ 30 "Xrender" \ 31 "Xtst" \ 32 platform="linux" 33 +/ 34 /******************************************************************************* 35 * Copyright (c) 2000, 2016 IBM Corporation and others. 36 * All rights reserved. This program and the accompanying materials 37 * are made available under the terms of the Eclipse Public License v1.0 38 * which accompanies this distribution, and is available at 39 * http://www.eclipse.org/legal/epl-v10.html 40 * 41 * Contributors: 42 * IBM Corporation - initial API and implementation 43 * D Port: 44 * alice <stigma@disroot.org> 45 *******************************************************************************/ 46 module org.eclipse.swt.snippets.Snippet6; 47 48 /* 49 * GridLayout example snippet: insert widgets into a grid layout 50 * 51 * For a list of all SWT example snippets see 52 * http://www.eclipse.org/swt/snippets/ 53 */ 54 import org.eclipse.swt.all; 55 import org.eclipse.swt.layout.all; 56 import org.eclipse.swt.widgets.all; 57 58 void main(string[] args) { 59 Display display = new Display(); 60 Shell shell = new Shell(display); 61 shell.setLayout(new GridLayout()); 62 Composite c = new Composite(shell, SWT.NONE); 63 GridLayout layout = new GridLayout(); 64 layout.numColumns = 3; 65 c.setLayout(layout); 66 for (int i = 0; i < 10; i++) { 67 Button b = new Button(c, SWT.PUSH); 68 b.setText("Button " ~ i.toString); 69 } 70 71 Button b = new Button(shell, SWT.PUSH); 72 b.setText("add a new button at row 2 column 1"); 73 int[] index = new int[1]; 74 b.addListener(SWT.Selection, new class Listener { 75 override void handleEvent (Event e) { 76 Button s = new Button(c, SWT.PUSH); 77 s.setText("Special " ~ index[0].toString); 78 index[0]++; 79 Control[] children = c.getChildren(); 80 s.moveAbove(children[3]); 81 shell.layout([s]); 82 } 83 }); 84 85 shell.open(); 86 while (!shell.isDisposed()) { 87 if (!display.readAndDispatch()) display.sleep(); 88 } 89 display.dispose(); 90 }