How to set the text of textarea center while textarea is set PASSWORD_MODE?

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

how to set the text of textarea center while textarea is set PASSWORD_MODE?

What MCU/Processor/Board and compiler are you using?

What LVGL version are you using?

What do you want to achieve?

What have you tried so far?

I had inited the textarea background style and add to the LV_PART_MAIN, but it seemed useless

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_align(&style, LV_TEXT_ALIGN_CENTER);

lv_obj_add_style(textarea, &style, LV_PART_MAIN);

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

For the textarea you should use lv_textarea_set_align.

I’ve updated the docs to mention it.

That is claimed to be deprecated right now. I am a noob and do not get it to work with the hint in the docu. Would appreciate help

You can use lv_obj_set_style_text_align(textarea, LV_TEXT_ALIGN_..., LV_PART_MAIN)

Thanks a lot - I had tried that but it did not work. I am trying to use it with a spinbox

I also cannot get the cusor invisible with: lv_obj_set_style_border_opa(spinbox, LV_PART_CURSOR, LV_STATE_DEFAULT); …

My complete code:

    lv_obj_t* spinbox = lv_spinbox_create(screen);
    lv_spinbox_set_range(spinbox, 1, 99);
    lv_spinbox_set_digit_format(spinbox, 2, 0);
    lv_spinbox_step_prev(spinbox);
    lv_obj_set_width(spinbox, 40);
    lv_obj_set_height(spinbox, 35);
    lv_obj_align(spinbox, LV_ALIGN_TOP_LEFT, 170, 185);
    lv_spinbox_set_rollover(spinbox, true);
    //lv_obj_set_style_border_opa(spinbox, LV_PART_CURSOR, LV_STATE_DEFAULT); // does not hide the cursor
    //lv_obj_set_style_opa(spinbox, LV_PART_CURSOR, LV_STATE_DEFAULT); //hides complete textbox
    lv_obj_set_style_pad_all(spinbox, 0, 0); // need to do that otherwise the value is jumping up and down
    lv_obj_set_style_text_align(spinbox, LV_TEXT_ALIGN_CENTER, LV_PART_MAIN); // Text is aligned at top of textbox with this
    lv_spinbox_set_cursor_pos(spinbox, 0);
    lv_coord_t h = lv_obj_get_height(spinbox);

Ah, you mean an issue with vertical alignment. LV_TEXT_ALIGN_... aligns the text horizontally.

To vertically center the text you can do 2 things:

  • Leave the height on the default value (LV_SIZE_CONTENT) and set the height with vertical padding: lv_obj_set_style_pad_ver(spinbox, 15, 0);
  • Set the height with lv_obj_set_height but than manually center align the label: lv_obj_center(lv_obj_get_child(spinbox, 0));

To remove the cursor style you can use
lv_obj_remove_style(spinbox, NULL, LV_PART_CURSOR | LV_STATE_ANY);