Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet107.d @ 29:4e5843b771cc
First snippets buildable on windows
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 22 Mar 2009 19:55:00 +0100 |
parents | 69b1fa94a4a8 |
children |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module org.eclipse.swt.snippets.Snippet107; | |
12 /* | |
13 * Sash example snippet: implement a simple splitter (with a 20 pixel limit) | |
14 * | |
15 * For a list of all SWT example snippets see | |
16 * http://www.eclipse.org/swt/snippets/ | |
17 */ | |
18 import org.eclipse.swt.SWT; | |
19 import org.eclipse.swt.graphics.Rectangle; | |
20 import org.eclipse.swt.layout.FormAttachment; | |
21 import org.eclipse.swt.layout.FormData; | |
22 import org.eclipse.swt.layout.FormLayout; | |
23 import org.eclipse.swt.widgets.Button; | |
24 import org.eclipse.swt.widgets.Display; | |
25 import org.eclipse.swt.widgets.Event; | |
26 import org.eclipse.swt.widgets.Listener; | |
27 import org.eclipse.swt.widgets.Sash; | |
28 import org.eclipse.swt.widgets.Shell; | |
29 | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
30 import java.lang.all; |
28 | 31 |
32 void main () { | |
33 auto display = new Display (); | |
34 auto shell = new Shell (display); | |
35 auto button1 = new Button (shell, SWT.PUSH); | |
36 button1.setText ("Button 1"); | |
37 auto sash = new Sash (shell, SWT.VERTICAL); | |
38 auto button2 = new Button (shell, SWT.PUSH); | |
39 button2.setText ("Button 2"); | |
40 | |
41 auto form = new FormLayout (); | |
42 shell.setLayout (form); | |
43 | |
44 auto button1Data = new FormData (); | |
45 button1Data.left = new FormAttachment (0, 0); | |
46 button1Data.right = new FormAttachment (sash, 0); | |
47 button1Data.top = new FormAttachment (0, 0); | |
48 button1Data.bottom = new FormAttachment (100, 0); | |
49 button1.setLayoutData (button1Data); | |
50 | |
51 int limit = 20, percent = 50; | |
52 auto sashData = new FormData (); | |
53 sashData.left = new FormAttachment (percent, 0); | |
54 sashData.top = new FormAttachment (0, 0); | |
55 sashData.bottom = new FormAttachment (100, 0); | |
56 sash.setLayoutData (sashData); | |
57 sash.addListener (SWT.Selection, new class Listener { | |
58 public void handleEvent (Event e) { | |
59 auto sashRect = sash.getBounds (); | |
60 auto shellRect = shell.getClientArea (); | |
61 int right = shellRect.width - sashRect.width - limit; | |
62 e.x = Math.max (Math.min (e.x, right), limit); | |
63 if (e.x !is sashRect.x) { | |
64 sashData.left = new FormAttachment (0, e.x); | |
65 shell.layout (); | |
66 } | |
67 } | |
68 }); | |
69 | |
70 auto button2Data = new FormData (); | |
71 button2Data.left = new FormAttachment (sash, 0); | |
72 button2Data.right = new FormAttachment (100, 0); | |
73 button2Data.top = new FormAttachment (0, 0); | |
74 button2Data.bottom = new FormAttachment (100, 0); | |
75 button2.setLayoutData (button2Data); | |
76 | |
77 shell.pack (); | |
78 shell.open (); | |
79 while (!shell.isDisposed ()) { | |
80 if (!display.readAndDispatch ()) display.sleep (); | |
81 } | |
82 display.dispose (); | |
83 } |