Mercurial > projects > dwt-addons
comparison dwtx/draw2d/StackLayout.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.draw2d.StackLayout; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 import dwtx.dwtxhelper.Collection; | |
17 | |
18 import dwtx.draw2d.geometry.Dimension; | |
19 import dwtx.draw2d.geometry.Rectangle; | |
20 import dwtx.draw2d.AbstractHintLayout; | |
21 import dwtx.draw2d.IFigure; | |
22 | |
23 /** | |
24 * Figures using the StackLayout as their layout manager have their children placed on top | |
25 * of one another. Order of placement is determined by the order in which the children | |
26 * were added, first child added placed on the bottom. | |
27 */ | |
28 public class StackLayout | |
29 : AbstractHintLayout | |
30 { | |
31 | |
32 /** | |
33 * Returns the minimum size required by the input container. This is the size of the | |
34 * largest child of the container, as all other children fit into this size. | |
35 * | |
36 * @see AbstractHintLayout#calculateMinimumSize(IFigure, int, int) | |
37 */ | |
38 protected Dimension calculateMinimumSize(IFigure figure, int wHint, int hHint) { | |
39 if (wHint > -1) | |
40 wHint = Math.max(0, wHint - figure.getInsets().getWidth()); | |
41 if (hHint > -1) | |
42 hHint = Math.max(0, hHint - figure.getInsets().getHeight()); | |
43 Dimension d = new Dimension(); | |
44 List children = figure.getChildren(); | |
45 IFigure child; | |
46 for (int i = 0; i < children.size(); i++) { | |
47 child = cast(IFigure)children.get(i); | |
48 if (!isObservingVisibility() || child.isVisible()) | |
49 d.union_(child.getMinimumSize(wHint, hHint)); | |
50 } | |
51 | |
52 d.expand(figure.getInsets().getWidth(), | |
53 figure.getInsets().getHeight()); | |
54 d.union_(getBorderPreferredSize(figure)); | |
55 return d; | |
56 | |
57 } | |
58 | |
59 /** | |
60 * Calculates and returns the preferred size of the given figure. This is the union of | |
61 * the preferred sizes of the widest and the tallest of all its children. | |
62 * | |
63 * @see AbstractLayout#calculatePreferredSize(IFigure, int, int) | |
64 */ | |
65 protected Dimension calculatePreferredSize(IFigure figure, int wHint, int hHint) { | |
66 if (wHint > -1) | |
67 wHint = Math.max(0, wHint - figure.getInsets().getWidth()); | |
68 if (hHint > -1) | |
69 hHint = Math.max(0, hHint - figure.getInsets().getHeight()); | |
70 Dimension d = new Dimension(); | |
71 List children = figure.getChildren(); | |
72 IFigure child; | |
73 for (int i = 0; i < children.size(); i++) { | |
74 child = cast(IFigure)children.get(i); | |
75 if (!isObservingVisibility() || child.isVisible()) | |
76 d.union_(child.getPreferredSize(wHint, hHint)); | |
77 } | |
78 | |
79 d.expand(figure.getInsets().getWidth(), | |
80 figure.getInsets().getHeight()); | |
81 d.union_(getBorderPreferredSize(figure)); | |
82 return d; | |
83 } | |
84 | |
85 /** | |
86 * @see dwtx.draw2d.LayoutManager#layout(IFigure) | |
87 */ | |
88 public void layout(IFigure figure) { | |
89 Rectangle r = figure.getClientArea(); | |
90 List children = figure.getChildren(); | |
91 IFigure child; | |
92 for (int i = 0; i < children.size(); i++) { | |
93 child = cast(IFigure)children.get(i); | |
94 child.setBounds(r); | |
95 } | |
96 } | |
97 | |
98 } |