1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet107"
5     dependency "dwt" path="../../../../../../"
6     libs \
7       "atk-1.0" \
8       "cairo" \
9       "dl" \
10       "fontconfig" \
11       "gdk-x11-2.0" \
12       "gdk_pixbuf-2.0" \
13       "glib-2.0" \
14       "gmodule-2.0" \
15       "gnomeui-2" \
16       "gnomevfs-2" \
17       "gobject-2.0" \
18       "gthread-2.0" \
19       "gtk-x11-2.0" \
20       "pango-1.0" \
21       "pangocairo-1.0" \
22       "X11" \
23       "Xcomposite" \
24       "Xcursor" \
25       "Xdamage" \
26       "Xext" \
27       "Xfixes" \
28       "Xi" \
29       "Xinerama" \
30       "Xrandr" \
31       "Xrender" \
32       "Xtst" \
33       platform="linux"
34 +/
35 
36 /*******************************************************************************
37  * Copyright (c) 2000, 2004 IBM Corporation and others.
38  * All rights reserved. This program and the accompanying materials
39  * are made available under the terms of the Eclipse Public License v1.0
40  * which accompanies this distribution, and is available at
41  * http://www.eclipse.org/legal/epl-v10.html
42  *
43  * Contributors:
44  *     IBM Corporation - initial API and implementation
45  *******************************************************************************/
46 module org.eclipse.swt.snippets.Snippet107;
47 /*
48  * Sash example snippet: implement a simple splitter (with a 20 pixel limit)
49  *
50  * For a list of all SWT example snippets see
51  * http://www.eclipse.org/swt/snippets/
52  */
53 import org.eclipse.swt.SWT;
54 import org.eclipse.swt.graphics.Rectangle;
55 import org.eclipse.swt.layout.FormAttachment;
56 import org.eclipse.swt.layout.FormData;
57 import org.eclipse.swt.layout.FormLayout;
58 import org.eclipse.swt.widgets.Button;
59 import org.eclipse.swt.widgets.Display;
60 import org.eclipse.swt.widgets.Event;
61 import org.eclipse.swt.widgets.Listener;
62 import org.eclipse.swt.widgets.Sash;
63 import org.eclipse.swt.widgets.Shell;
64 
65 import java.lang.all;
66 
67 void main () {
68     auto display = new Display ();
69     auto shell = new Shell (display);
70     auto button1 = new Button (shell, SWT.PUSH);
71     button1.setText ("Button 1");
72     auto sash = new Sash (shell, SWT.VERTICAL);
73     auto button2 = new Button (shell, SWT.PUSH);
74     button2.setText ("Button 2");
75     
76     auto form = new FormLayout ();
77     shell.setLayout (form);
78     
79     auto button1Data = new FormData ();
80     button1Data.left = new FormAttachment (0, 0);
81     button1Data.right = new FormAttachment (sash, 0);
82     button1Data.top = new FormAttachment (0, 0);
83     button1Data.bottom = new FormAttachment (100, 0);
84     button1.setLayoutData (button1Data);
85 
86     int limit = 20, percent = 50;
87     auto sashData = new FormData ();
88     sashData.left = new FormAttachment (percent, 0);
89     sashData.top = new FormAttachment (0, 0);
90     sashData.bottom = new FormAttachment (100, 0);
91     sash.setLayoutData (sashData);
92     sash.addListener (SWT.Selection, new class Listener {
93         public void handleEvent (Event e) {
94             auto sashRect = sash.getBounds ();
95             auto shellRect = shell.getClientArea ();
96             int right = shellRect.width - sashRect.width - limit;
97             e.x = Math.max (Math.min (e.x, right), limit);
98             if (e.x !is sashRect.x)  {
99                 sashData.left = new FormAttachment (0, e.x);
100                 shell.layout ();
101             }
102         }
103     });
104     
105     auto button2Data = new FormData ();
106     button2Data.left = new FormAttachment (sash, 0);
107     button2Data.right = new FormAttachment (100, 0);
108     button2Data.top = new FormAttachment (0, 0);
109     button2Data.bottom = new FormAttachment (100, 0);
110     button2.setLayoutData (button2Data);
111     
112     shell.pack ();
113     shell.open ();
114     while (!shell.isDisposed ()) {
115         if (!display.readAndDispatch ()) display.sleep ();
116     }
117     display.dispose ();
118 }