Mercurial > projects > dwt-samples
annotate snippets/sash/Snippet107.d @ 120:1f0a7a472680
fix rm snippets from module statements.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 20 Jul 2008 19:17:23 +0200 |
parents | 4a04b6759f98 |
children |
rev | line source |
---|---|
78 | 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 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
11 module sash.Snippet107; |
78 | 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 dwt.DWT; | |
19 import dwt.graphics.Rectangle; | |
20 import dwt.layout.FormAttachment; | |
21 import dwt.layout.FormData; | |
22 import dwt.layout.FormLayout; | |
23 import dwt.widgets.Button; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Event; | |
26 import dwt.widgets.Listener; | |
27 import dwt.widgets.Sash; | |
28 import dwt.widgets.Shell; | |
29 | |
30 import tango.math.Math; | |
31 | |
32 void main () { | |
33 auto display = new Display (); | |
34 auto shell = new Shell (display); | |
35 auto button1 = new Button (shell, DWT.PUSH); | |
36 button1.setText ("Button 1"); | |
37 auto sash = new Sash (shell, DWT.VERTICAL); | |
38 auto button2 = new Button (shell, DWT.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 (DWT.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 } |