... | @@ -50,6 +50,7 @@ Writing such a component is not extremely hard but also requires some thinking. |
... | @@ -50,6 +50,7 @@ Writing such a component is not extremely hard but also requires some thinking. |
|
|
|
|
|
* changing the display based on the input
|
|
* changing the display based on the input
|
|
* Managing horizontal and vertical scrollbars if required
|
|
* Managing horizontal and vertical scrollbars if required
|
|
|
|
* Cleaning up everything once the widget is no longer used
|
|
* Displaying a mouse cursor in the correct shape as long as it is located over the editor
|
|
* Displaying a mouse cursor in the correct shape as long as it is located over the editor
|
|
* Displaying the text in different Fonts (that is the type, its size and styling)
|
|
* Displaying the text in different Fonts (that is the type, its size and styling)
|
|
* Allowing the user to wrap the editor lines, based on the current size of the widget
|
|
* Allowing the user to wrap the editor lines, based on the current size of the widget
|
... | @@ -184,10 +185,21 @@ How do we know, whether those bars are not ```null```?. Rememebr when you create |
... | @@ -184,10 +185,21 @@ How do we know, whether those bars are not ```null```?. Rememebr when you create |
|
public ATHENEditorWidget(Composite parent, int style) {
|
|
public ATHENEditorWidget(Composite parent, int style) {
|
|
|
|
|
|
```
|
|
```
|
|
This second argument are so called stylebits. An ```int``` value is internally made of 32 Bits so we got 32 positions to store a value. This allows for a very flexible styling of a widget. In our case, if the 8th Bit is set, our widget has an horizontal bar and if the 9th Bit is set we got a vertical bar. This is delegated to the canvas constructor which in turn creates those objects for us.
|
|
This second argument are so called **stylebits**. An ```int``` value is internally made of 32 Bits so we got 32 positions to store a value. This allows for a very flexible styling of a widget. In our case, if the 8th Bit is set, our widget has an horizontal bar and if the 9th Bit is set we got a vertical bar. This is delegated to the canvas constructor which in turn creates those objects for us.
|
|
An object with both bits set would require the following call:
|
|
An object with both bits set would require the following call:
|
|
|
|
|
|
```java
|
|
```java
|
|
new ATHENEditorWidget(parent,SWT.H_SCROLL|SWT.V_SCROLL);
|
|
new ATHENEditorWidget(parent,SWT.H_SCROLL|SWT.V_SCROLL);
|
|
|
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
Now we can start to discuss why the horizontal bar stores **pixel** while the vertical bar stored **lines**. This is a decision i made and origins from the following thought process:
|
|
|
|
|
|
|
|
**Vertical Scrolling**
|
|
|
|
|
|
|
|
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**
|
|
|
|
|
|
|
|
The maximum width can only be calculated in pixel, since the other metric (character) is not reliable between different fonts.
|
|
|
|
|