wctltya Posted March 3, 2017 Report Share Posted March 3, 2017 (edited) 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 March 3, 2017 by wctltya Link to comment Share on other sites More sharing options...
inmarket Posted March 3, 2017 Report Share Posted March 3, 2017 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 More sharing options...
wctltya Posted March 3, 2017 Author Report Share Posted March 3, 2017 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 More sharing options...
inmarket Posted March 3, 2017 Report Share Posted March 3, 2017 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 More sharing options...
Joel Bodenmann Posted March 4, 2017 Report Share Posted March 4, 2017 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 More sharing options...
wctltya Posted March 4, 2017 Author Report Share Posted March 4, 2017 Thank you both guys, Pixmap option sounds very good, but unfortunately I can't use it. As long as I remember it is not available for 'single file' projects. I'm using uGFX in a KDS project. Link to comment Share on other sites More sharing options...
inmarket Posted March 5, 2017 Report Share Posted March 5, 2017 You might be interested once uGFX v3 is released as that should fix the problem with pixmaps and single file make. Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted March 11, 2017 Report Share Posted March 11, 2017 @wctltya: Vertical alignment options have been added: https://git.ugfx.io/uGFX/uGFX/commit/d8c9ca184f29800f6c23d02bc450ea0e67981990 Link to comment Share on other sites More sharing options...
wctltya Posted March 23, 2017 Author Report Share Posted March 23, 2017 Hi Joel, Thank you. It really makes sense. But what I don't understand is how to use the mew "justify" options. Shall I create custom draw functions like these gwinLabelDrawJustifiedLeft/Right/Center in order to set it? Link to comment Share on other sites More sharing options...
inmarket Posted March 23, 2017 Report Share Posted March 23, 2017 Yes. You will need to create a custom draw that internally uses the new vertical justification options. Note the different options can be just added or or'd together eg justifyLeft + justifyTop Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted March 24, 2017 Report Share Posted March 24, 2017 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 More sharing options...
wctltya Posted March 24, 2017 Author Report Share Posted March 24, 2017 Yes, I saw that gwinLabelDraw(...) is static. And as a quick workaround I just removed static qualifier. This is a temporary solution only. BTW the new options works fine. Thank you again. Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted March 24, 2017 Report Share Posted March 24, 2017 Glad to hear that you managed to get everything up and running! Link to comment Share on other sites More sharing options...
AJJ Posted May 1, 2017 Report Share Posted May 1, 2017 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 More sharing options...
inmarket Posted May 2, 2017 Report Share Posted May 2, 2017 While semantically different, in uGFX they are actually the same thing. Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted May 2, 2017 Report Share Posted May 2, 2017 Also, welcome to the µGFX community! Link to comment Share on other sites More sharing options...
AJJ Posted May 2, 2017 Report Share Posted May 2, 2017 Are you saying that font->height and font->line_height are the same thing? When I look at DejaVuSans16 for instance they are initialized to 17 and 19, respectively. Link to comment Share on other sites More sharing options...
inmarket Posted May 3, 2017 Report Share Posted May 3, 2017 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 More sharing options...
AJJ Posted May 3, 2017 Report Share Posted May 3, 2017 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 More sharing options...
inmarket Posted May 3, 2017 Report Share Posted May 3, 2017 I will look at the code to check at the first opportunity. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now