Jump to content

Vertical position of the text in the Label widget


wctltya

Recommended Posts

Hi,

Seems that the text in the labels widget is vertically centered in the defined window. Is there any way the text to begin from the top left corner for example? My flag for word wrapping is set to true.

And another question - some time it is usable to display text in label widget in different ways, for example vertically, or vertically rotated to -90/+90 degree (top to bottom or bottom to top). is there any way to do that, except custom draw fiction?

Edited by wctltya
Link to comment
Share on other sites

I cannot answer the text wrapping problem. Joel will answer that.

With regard to changing the orientation of text, this is actually computationally quite difficult requiring all sorts of different hinting and even sometimes special fonts. As uGFX is designed to be small this has not been implemented and probably won't in the short term as it requires extensive work on a complex font engine.

There is however a workaround. 

If your display supports orientation changing you can change the orientation of the display, draw your text, and then change the orientation back. This works because uGFX strongly suggests for driver writers that orientation is taken to mean changing the drawing orientation rather than changing the mapping of the video ram to the display.

When you draw with the changed orientation remember to alter the drawing coordinates to the new orientation. If you are running multithreaded drawing also take a lock during the series of operations to draw the rotated text to stop other threads drawing while your orientation is altered.

Link to comment
Share on other sites

Thank you inmarket.

No, I don't have troubles whit word wrapping. It works fine. 

But, I'm looking for a way the text to begin from the upper left corner. Thus the text will not be vertically centered in a bigger area. 

The problem is if I have a bigger area and the text is small. Then it's looks ugly with empty spaces over and under it. I can't shrink the widget size, because then the bigger text will not fit. 

It is the same as you are writing on a sheet for example. The text begins from the upper left corner (for left-to-right writing style) but not at the middle if sheet, isn't it?

The other options is to calculate the given text size at desired font size and to put the proper widget size, but I don't know how I can do it.

So, any advices are welcome.

Link to comment
Share on other sites

What i was saying with the text wrapping is that i am unsure how the text wrapping affects the vertical alignment.

There are 2 solutions...

1. If you are using the gwin label widget you could write a custom draw for it that aligns it vertically how you want. There is already a right align custom draw in the code to demonstrate how this might be done.

2. Use the console widget (with history for data retention). It by default aligns from the top left.

Link to comment
Share on other sites

The current version of the label widget only allows to control horizontal alignment and always vertically centers the text. This behavior is not affected on whether a line gets wrapped or not. The entire text block will be centered vertically no matter how many lines it takes up.
There's no solution other than writing a custom rendering routine - which is the intended way of doing this.

Regarding text rotation: In addition to what @inmarket said you also have the option to render into a pixmap and blit that in a different orientation.

Link to comment
Share on other sites

  • 2 weeks later...

At the end you just need to create a wrapper or forwarding drawing function because the one that takes the justification parameters is internal only at the moment. You need something like this:

GFXINLINE void gwinLabelDrawJustified(GWidgetObject* gw, void* param) {
	gwinLabelDraw(gw, param);
}

That should do nicely.

I put adding that function to the repository on our ToDo list.

Link to comment
Share on other sites

  • 1 month later...

Regarding the default situation where text is vertically centered within the label widget, I'm not sure that it works properly when displaying a string with multiple lines using a font where 'height' is different from 'line_height'.  At line 3551 of gdisp.c the code calculates the total height as the number of lines times the font->height.  Shouldn't this total height instead be something like the following?

                    totalHeight = font->height + ((#lines-1) * font->line_height);
 

Link to comment
Share on other sites

No, I am saying that uGFX has always ignored line_height and used height instead. The reasons are historical and difficult to change without affecting previous application code.

If we make the change it will be on a major version change (eg the change to V3.0) and will be disabled for applications compiling with V2 compatibility.

Thanks for the reminder. I should add it to the V3.0 development list.

Link to comment
Share on other sites

Do you agree that because of this issue multi-line text is not vertically centered in a label?  This has been my experience and the above change fixed it for me.  But I'm new to uGFX and it's very possible that I'm doing something else wrong.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...