V8 cant get a simple text align to work

I have been using V7.x.x for a while, just going through the very painful process of switching over to Version 8.

In V7 I have the following code (omitted some of the irrelevant position/sizing code)

	btn2 = lv_btn_create(screenMain, NULL);
	lv_obj_t * label2 = lv_label_create(btn2, NULL);
	lv_label_set_text(label2, "Goodbye");

This worked fine and defaults to center the 7 text characters horizontally within btn2.

In version 8, it no longer fits the text by default centrally within btn2. It is offset to the right meaning the visible text is “Goodb”.

	lv_obj_t * label2 = lv_label_create(btn2);
	lv_obj_set_style_text_align(label2, LV_TEXT_ALIGN_LEFT, 0);
	lv_obj_align(label2, LV_ALIGN_LEFT_MID, 0, 0);
	lv_obj_align_to(label2, btn2, LV_ALIGN_LEFT_MID, 0, 0);

There are now a confusing range of ways to seemingly align my button text to force it to the left of the button. However none of these lines moved the text, it was still too far to the right and truncating.

Any suggestions please as to how to get this text aligned left and actually work ? Thanks

Version 7 was great and intuitive to use, so far I am having lots of problems with version 8.


I’ve tried your code, and with v8 it looks like this in the simulator:

    lv_obj_t* btn2 = lv_btn_create(lv_scr_act());
    lv_obj_t* label2 = lv_label_create(btn2);
    lv_label_set_text(label2, "Goodbye");


Maybe some settings (padding) for the default theme is different?

Hello Jojo
Thanks for taking the time to reply. I think I have now figured out now why the text string fitted perfectly on V7 and is now screwed up on V8.

lv_obj_set_style_text_align(label, LV_TEXT_ALIGN_LEFT, 0); doesnt seem to do anything for me on V8 so I abandoned that. However
lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0) does work and left justifies the label text.

The reason why I initially thought it wasnt working was due to the fact I have got quite a small button area where i am fitting the text into. For V7 it defaults to fitting it in perfectly with just a few blank pixels either side. When I use V8 and specify LV_ALIGN_LEFT_MID, surprisingly the text comes out positioned farther to the right than the default behavior in V7 and loses 2 characters. No wonder I was confused by it. Now I understand whats going on, I can workaround the problem in V8 by using something like lv_obj_align(label, LV_ALIGN_LEFT_MID, -15, 0); and tweaking the Xoffs.

Having subtle pixel accuracy changes going from V7 to V8 is horrible, must be a nightmare if you are trying to convert a big complex App.

I think its because of the default padding, have you tried

    lv_obj_set_style_pad_left(label, 0, LV_PART_MAIN);

This applies also to a grid, I was also wondering why my grid did not fit in screen width.

I have skipped v7 and don’t have to worry about changes :slight_smile: Ok, I was missing the tasks from v6.


Thanks for the extra idea, for completeness I just tried your suggested padding line. Unfortunately that doesnt fix it. The fix is to left justify and then add a further X offset by -12 pixels to get back to exactly what V7 did.
lv_obj_align(label2, LV_ALIGN_LEFT_MID, -12, 0);