Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 56761 Details for
Bug 170201
And possibility to use percentage values for height and width for GridLayout/RowLayout
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
A better one including a snippet to give it a try
clipboard29614.txt (text/plain), 9.71 KB, created by
Thomas Schindl
on 2007-01-11 09:11:06 EST
(
hide
)
Description:
A better one including a snippet to give it a try
Filename:
MIME Type:
Creator:
Thomas Schindl
Created:
2007-01-11 09:11:06 EST
Size:
9.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.swt.snippets >Index: src/org/eclipse/swt/snippets/Snippet253.java >=================================================================== >RCS file: src/org/eclipse/swt/snippets/Snippet253.java >diff -N src/org/eclipse/swt/snippets/Snippet253.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/swt/snippets/Snippet253.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,52 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2004 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.swt.snippets; >+ >+/* >+ * example snippet: Hello World >+ * >+ * For a list of all SWT example snippets see >+ * http://www.eclipse.org/swt/snippets/ >+ */ >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.layout.RowData; >+import org.eclipse.swt.layout.RowLayout; >+import org.eclipse.swt.widgets.*; >+ >+public class Snippet253 { >+ >+public static void main (String [] args) { >+ Display display = new Display (); >+ Shell shell = new Shell(display); >+ shell.setLayout(new FillLayout()); >+ Group group = new Group(shell,SWT.NONE); >+ group.setLayout(new RowLayout()); >+ >+ Button b = new Button(group,SWT.PUSH); >+ b.setText("50%-Fixed"); >+ b.setLayoutData(new RowData(SWT.DEFAULT,SWT.DEFAULT,1,0)); >+ >+ b = new Button(group,SWT.PUSH); >+ b.setText("Fixed"); >+ b.setLayoutData(new RowData(100,SWT.DEFAULT)); >+ >+ b = new Button(group,SWT.PUSH); >+ b.setText("50%-Fixed"); >+ b.setLayoutData(new RowData(SWT.DEFAULT,SWT.DEFAULT,1,0)); >+ >+ shell.open (); >+ while (!shell.isDisposed ()) { >+ if (!display.readAndDispatch ()) display.sleep (); >+ } >+ display.dispose (); >+} >+} >#P org.eclipse.swt >Index: Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java,v >retrieving revision 1.34 >diff -u -r1.34 RowLayout.java >--- Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java 9 May 2006 19:47:04 -0000 1.34 >+++ Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java 11 Jan 2007 14:02:46 -0000 >@@ -196,12 +196,12 @@ > return extent; > } > >-Point computeSize (Control control, boolean flushCache) { >+Point computeSize (Control control, boolean flushCache, double totalWidthWeight, double totalHeightWeight, int containerWidth, int containerHeight) { > int wHint = SWT.DEFAULT, hHint = SWT.DEFAULT; > RowData data = (RowData) control.getLayoutData (); > if (data != null) { >- wHint = data.width; >- hHint = data.height; >+ wHint = Math.max(data.width, (data.widthWeight > 0)?(int)(data.widthWeight/totalWidthWeight*containerWidth):data.width ); >+ hHint = Math.max(data.height, (data.heightWeight > 0)?(int)(data.heightWeight/totalHeightWeight*containerHeight):data.height); > } > return control.computeSize (wHint, hHint, flushCache); > } >@@ -229,21 +229,46 @@ > Point layoutHorizontal (Composite composite, boolean move, boolean wrap, int width, boolean flushCache) { > Control [] children = composite.getChildren (); > int count = 0; >+ >+ Rectangle rect = composite.getClientArea (); >+ int totalWidthWeight = 0; >+ int totalHeightWeight = 0; >+ int heightToUse=rect.height - (marginTop + marginHeight * 2 + marginBottom); >+ int widthToUse=rect.width - (marginLeft + marginWidth * 2 + marginRight); >+ > for (int i=0; i<children.length; i++) { > Control control = children [i]; > RowData data = (RowData) control.getLayoutData (); > if (data == null || !data.exclude) { > children [count++] = children [i]; >+ if( data != null ) { >+ totalWidthWeight += data.widthWeight; >+ totalHeightWeight += data.heightWeight; >+ >+ if( data.height != SWT.DEFAULT && data.heightWeight == 0 ) { >+ heightToUse -= data.height; >+ } >+ >+ if( data.width != SWT.DEFAULT && data.widthWeight == 0 ) { >+ widthToUse -= data.width; >+ } >+ } > } > } >+ >+ heightToUse -= spacing * count; >+ widthToUse -= spacing * count; >+ > if (count == 0) { > return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); > } > int childWidth = 0, childHeight = 0, maxHeight = 0; >+ >+ > if (!pack) { > for (int i=0; i<count; i++) { > Control child = children [i]; >- Point size = computeSize (child, flushCache); >+ Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse); > childWidth = Math.max (childWidth, size.x); > childHeight = Math.max (childHeight, size.y); > } >@@ -251,7 +276,7 @@ > } > int clientX = 0, clientY = 0; > if (move) { >- Rectangle rect = composite.getClientArea (); >+ > clientX = rect.x; > clientY = rect.y; > } >@@ -266,7 +291,7 @@ > for (int i=0; i<count; i++) { > Control child = children [i]; > if (pack) { >- Point size = computeSize (child, flushCache); >+ Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse); > childWidth = size.x; > childHeight = size.y; > } >@@ -336,21 +361,46 @@ > Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) { > Control [] children = composite.getChildren (); > int count = 0; >+ >+ Rectangle rect = composite.getClientArea (); >+ int totalWidthWeight = 0; >+ int totalHeightWeight = 0; >+ int heightToUse=rect.height - (marginTop + marginHeight * 2 + marginBottom); >+ int widthToUse=rect.width - (marginLeft + marginWidth * 2 + marginRight); >+ > for (int i=0; i<children.length; i++) { > Control control = children [i]; > RowData data = (RowData) control.getLayoutData (); > if (data == null || !data.exclude) { > children [count++] = children [i]; >+ if( data != null ) { >+ totalWidthWeight += data.widthWeight; >+ totalHeightWeight += data.heightWeight; >+ >+ if( data.height != SWT.DEFAULT && data.heightWeight == 0 ) { >+ heightToUse -= data.height; >+ } >+ >+ if( data.width != SWT.DEFAULT && data.widthWeight == 0 ) { >+ widthToUse -= data.width; >+ } >+ } > } > } >+ >+ heightToUse -= spacing * count; >+ widthToUse -= spacing * count; >+ > if (count == 0) { > return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); > } > int childWidth = 0, childHeight = 0, maxWidth = 0; >+ >+ > if (!pack) { > for (int i=0; i<count; i++) { > Control child = children [i]; >- Point size = computeSize (child, flushCache); >+ Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse); > childWidth = Math.max (childWidth, size.x); > childHeight = Math.max (childHeight, size.y); > } >@@ -358,7 +408,7 @@ > } > int clientX = 0, clientY = 0; > if (move) { >- Rectangle rect = composite.getClientArea (); >+ > clientX = rect.x; > clientY = rect.y; > } >@@ -373,7 +423,7 @@ > for (int i=0; i<count; i++) { > Control child = children [i]; > if (pack) { >- Point size = computeSize (child, flushCache); >+ Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse); > childWidth = size.x; > childHeight = size.y; > } >Index: Eclipse SWT/common/org/eclipse/swt/layout/RowData.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/layout/RowData.java,v >retrieving revision 1.23 >diff -u -r1.23 RowData.java >--- Eclipse SWT/common/org/eclipse/swt/layout/RowData.java 9 May 2006 19:47:04 -0000 1.23 >+++ Eclipse SWT/common/org/eclipse/swt/layout/RowData.java 11 Jan 2007 14:02:46 -0000 >@@ -67,6 +67,22 @@ > */ > public boolean exclude = false; > >+ /** >+ * widthWeight specifies the preferred width in comparison with the other >+ * controls who are children of this container. In conjunction with this >+ * value {@link #width} acts as the minimum value which and the maximum >+ * is passed into Control.computeSize(int, int, boolean) >+ */ >+ public int widthWeight = 0; >+ >+ /** >+ * heightWeight specifies the preferred height in comparison with the other >+ * controls who are children of this container. In conjunction with this >+ * value {@link #height} acts as the minimum value which and the maximum >+ * is passed into Control.computeSize(int, int, boolean) >+ */ >+ public int heightWeight = 0; >+ > /** > * Constructs a new instance of RowData using > * default values. >@@ -88,6 +104,23 @@ > } > > /** >+ * Constructs a new instance of RowData according to the parameters. >+ * A value of SWT.DEFAULT indicates that no minimum width or >+ * no minimum height is specified. >+ * >+ * @param width a minimum width for the control >+ * @param height a minimum height for the control >+ * @param widthWeight the width weight of the control in comparison with other controls >+ * @param heightWeight the height weight of the control in comparison with other controls >+ */ >+public RowData (int width, int height, int widthWeight, int heightWeight) { >+ this.width = width; >+ this.height = height; >+ this.widthWeight = widthWeight; >+ this.heightWeight = heightWeight; >+} >+ >+/** > * Constructs a new instance of RowData according to the parameter. > * A value of SWT.DEFAULT indicates that no minimum width or > * no minimum height is specified.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 170201
:
56758
| 56761