-
Notifications
You must be signed in to change notification settings - Fork 182
Description
Currently SWT is heavy dependent on very generic datatypes (e.g. primitive int or simple containers like Rectangle and Point) and we try to circumvent this limitation with some extensions like Point/Rectangle with monitors, Float Points and so on but the general limitations stay:
- if using a int/float as a primitive value it is easy to mix up things and these can not carry internal data easily
Point
s andRectangle
s are used for different purposes, e.g. we use points to measure a size (e.g. Strings rendered with a font, or size of a Control) but also to express a location (e.g. where a shell should be shown or a click event or similar), also here it is absolutely possible to "mix" different things.- There is no way to give something as a unit of things, e.g. when specify the width of a control that shows some text, giving that in any absolute unit usually does not give good results as the font-size might vary per system, per OS or even per user account. Instead one would want to use relative units (e.g. percent, or em) what is quite common in CSS and responsive designs.
I therefore like to suggest we are adding new types and APIs to controls that account for that fact especially:
- A
Width
and aHeight
type that can carry a value and optionally a unit and aSize
that is a combination ofWidth
andHeight
- A
Position
and aBounds
what would be a combination of aPosition
and aSize
- ...
These types should then offer ways to perform mathematical operations on them in a type-safe fashion, e.g. one should not be able to add a Width
and a Height
directly and we need new API methods that accept and return such types.
With that for example a Width
given in pixels can easily carry a zoom factor or monitor from its control it was gathered from and return a value in Point
or ems.
As an example
public void setBounds (Bounds bound);
public Size computeSize (Width wHint, Height hHint);
Would then a layout manager allow to compute all values with type Width
when it comes to compute a size like this:
Bounds availableArea = control.getBounds();
Control[] childs = control.getChildren();
Width evenWidth = availableArea.divide(childs.length);
Position current = Position.origin();
foreach(Control c : childs) {
c.setBounds(Bounds.of(current, Size.of(evenWidth, c.computeSize(evenWidth, Height.DEFAULT).height());
current = current.add(evenWidth);
}
such code then can even use the native pixel values internally without any precision loss. Such values then even might be dynamically scaled base on the current Monitor position instead of being recomputed all the way long.