... | @@ -199,7 +199,23 @@ Now we can start to discuss why the horizontal bar stores **pixel** while the ve |
... | @@ -199,7 +199,23 @@ Now we can start to discuss why the horizontal bar stores **pixel** while the ve |
|
|
|
|
|
At some time during our process, we need to calculate the complete height of the content of the widget. Otherwise we could not scale the scrollbar accordingly. Since all we draw is text and text usually comes in lines, the total height is just the sum of the heights of all individual lines + a constant space in between them. While it would be possible to store the height in pixel, no one can actually read lines that are just partly visible. This is why i decided to only scroll full lines.
|
|
At some time during our process, we need to calculate the complete height of the content of the widget. Otherwise we could not scale the scrollbar accordingly. Since all we draw is text and text usually comes in lines, the total height is just the sum of the heights of all individual lines + a constant space in between them. While it would be possible to store the height in pixel, no one can actually read lines that are just partly visible. This is why i decided to only scroll full lines.
|
|
|
|
|
|
** Horizontal scrolling**
|
|
**Horizontal scrolling**
|
|
|
|
|
|
The maximum width can only be calculated in pixel, since the other metric (character) is not reliable between different fonts.
|
|
The maximum width can only be calculated in pixel, since the other metric (character) is not reliable between different fonts.
|
|
|
|
|
|
|
|
## Cleaning up everything once the widget is no longer used
|
|
|
|
|
|
|
|
Coding SWT is a little bit inconvenient for a java developer. Why? Well, SWT creates its widgets similar to the underlying Operating System(OS) This is a cool feature, because once the OS changes our application will immediately adapt its styling as well! But here comes the down fall - Every resource we use is given by the OS (Resources are Fonts,Colors,Images, etc...) which means the OS allocates memory for us. If we do not notify the OS that we do no longer need the resource, that memory is lost for the entiretiy of out applications life time! And at some point, the OS wont let us reserve any more of a given resource because either there is no more ram or there aren any left!
|
|
|
|
This is why whenever you create such a resource you are responsible of disposing it accordingly. Let me give you an example of a code that does not work!
|
|
|
|
|
|
|
|
```java
|
|
|
|
Color colorWhite=null;
|
|
|
|
|
|
|
|
int i=100;
|
|
|
|
while(i>0){
|
|
|
|
colorWhite = new Color(Display.getCurrent(), new RGBA(255, 255, 255, 0));
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|