public interface ISizeProvider
Modifier and Type | Field and Description |
---|---|
static int |
INFINITE
Constant used to indicate infinite size.
|
Modifier and Type | Method and Description |
---|---|
int |
computePreferredSize(boolean width,
int availableParallel,
int availablePerpendicular,
int preferredResult)
Returns the best size for this part, given the available width and height
and the workbench's preferred size for the part.
|
int |
getSizeFlags(boolean width)
Returns a bitwise combination of flags indicating how and when computePreferredSize should
be used.
|
static final int INFINITE
int getSizeFlags(boolean width)
If the return value of this function ever changes, the part must call flushLayout
before
the changes will take effect.
width
- a value of true or false determines whether the return value applies when computing
widths or heights respectively. That is, getSizeFlags(true) will be used when calling
computePreferredSize(true,...)int computePreferredSize(boolean width, int availableParallel, int availablePerpendicular, int preferredResult)
Returns the best size for this part, given the available width and height and the workbench's preferred size for the part. Parts can overload this to enforce a minimum size, maximum size, or a quantized set of preferred sizes. If width == true, this method computes a width in pixels. If width == false, this method computes a height. availableParallel and availablePerpendicular contain the space available, and preferredParallel contains the preferred result.
This method returns an answer that is less than or equal to availableParallel and as close to preferredParallel as possible. Return values larger than availableParallel will be truncated.
Most presentations will define a minimum size at all times, and a maximum size that only applies when maximized.
The getSizeFlags method controls how frequently this method will be called and what information will be available when it is. Any subclass that specializes this method should also specialize getSizeFlags. computePreferredSize(width, INFINITE, someSize, 0) returns the minimum size of the control (if any). computePreferredSize(width, INFINITE, someSize, INFINITE) returns the maximum size of the control.
Examples:
{
if (width && preferredResult != INFINITE) {
int result = preferredResult - ((preferredResult + 50) % 100) + 50;
result = Math.max(100, Math.min(result, availableParallel - (availableParallel % 100)));
return result;
}
return preferredResult;
}
In this case, getSizeFlags(boolean width) must return (width ?
SWT.FILL | SWT.MIN: 0)
{return availablePerpendicular < 100 ? 1000 : 100000 / availablePerpendicular;}
getSizeFlags(boolean width) must return SWT.WRAP | SWT.MIN;width
- indicates whether a width (if true
) or a height
(if false
) is being computedavailableParallel
- available space. This is a width (pixels) if width == true,
and a height (pixels) if width == false. A return value larger
than this will be ignored.availablePerpendicular
- available space perpendicular to the direction being measured
or INFINITE if unbounded (pixels). This is a height if width
== true, or a height if width == false. Implementations will
generally ignore this argument unless they contain wrapping
widgets. Note this argument will only contain meaningful
information if the part returns the SWT.WRAP flag from
getSizeFlags(width)preferredResult
- preferred size of the control (pixels, <= availableParallel).
Set to INFINITE if unknown or unbounded.getSizeFlags(boolean)
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.