I have a label problem help me please?

I try developing a calculator. i desinged a gui and now i developing event functions, i want do if a button come event, take the button name(number) and add my label. But now i have a problem. The problem is this; I can take text from label and i add my new value with printf() function but sprintf() function dont take after from 2 value. Why ? How can finf solition?
there below the output on simulator and console;





there below my code in event function ;

static const char * number_BtnMapValues[10] = { "9", "8", "7", 
														"6", "5", "4", 
														"3", "2", "1", 
														"0"};
		const uint8_t * number_BtnValuesInt[10] = {	9,8,7,6,5,4,3,2,1,0};

			for (int sayac = 0; sayac < 10; sayac++) {
				if (0 == strcmp(number_BtnMapValues[sayac], lv_btnm_get_active_btn_text(obj))) {
					if (lv_obj_get_screen(tos_calculatorDisplayLabel) == lv_scr_act()) {
						if (0 == strcmp("0", lv_label_get_text(tos_calculatorDisplayLabel))) {
							snprintf(calculatorBuf, 32, "%s",lv_btnm_get_active_btn_text(obj));
							printf("%s\n", lv_btnm_get_active_btn_text(obj));
						}
						else {
							snprintf(calculatorBuf, 32, "%s%s",
								lv_label_get_text(tos_calculatorDisplayLabel), lv_btnm_get_active_btn_text(obj));
							printf("%s%s\n",
								lv_label_get_text(tos_calculatorDisplayLabel), lv_btnm_get_active_btn_text(obj));
						}
						
						lv_label_set_text(tos_calculatorDisplayLabel, calculatorBuf);
						
					}
				
				}
				
			}
			if (0 == strcmp(".", lv_btnm_get_active_btn_text(obj))) {
				printf(". was pressed\n");

			}
			else if (0 == strcmp("=", lv_btnm_get_active_btn_text(obj))) {
				printf("= was pressed\n");

			}

I don’t use snprintf so I am not sure of the nuances with using it. Is there any reason you don’t use strcat instead to concatenate the value to the end? The obvious benefit of snprintf that I see is you can more easily limit the number of characters entered into it, but you could easily keep track of this with a counter.

I wouldn’t think this is an issue with the textarea, but I suggest printing the value of calculatorBuf to verify that it contains the correct area ( printf("%s\n", calculatorBuf); ).

Ok, calculatorBuf is taking numbers. i found real problem, the problem is this;
calculatorBuf take new value but label align is constant therefore new value dont come from 2th after value on the display, when increase the align coordinate of x then come new value

lv_obj_align(tos_calculatorDisplayLabel, NULL, LV_ALIGN_IN_RIGHT_MID, -(LV_DPI / 10) + 3, 0);

Interesting. I have not used the object alignment stuff enough to have thought of that. In any case I’m glad you found your answer!

1 Like

thank u for feedback. :slight_smile:

Take a look at lv_obj_set_auto_realign.
With this the alignment can be reapplied automatically.

2 Likes