Description
I’m trying to set the text colour for a label when it is disabled.
What MCU/Processor/Board and compiler are you using?
Windows, VisualStudio 22
What LVGL version are you using?
8.3.6
What do you want to achieve?
Have the text colour change when I set the state to LV_STATE_DISABLED on a label.
What have you tried so far?
In my theme apply callback:
} else if( lv_obj_check_type( obj, &lv_label_class )){
lv_obj_add_style( obj, &textEnbldStyle, LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_add_style( obj, &textDisbldStyle, LV_PART_MAIN | LV_STATE_DISABLED );
lv_obj_refresh_style( obj, LV_PART_MAIN, LV_STYLE_TEXT_COLOR );
}
elsewhere I set up the styles beforehand:
lv_style_set_text_color( &textEnbldStyle, lv_color_hsv_to_rgb( 100, 100, 100 )); // green
lv_style_set_text_color( &textDisbldStyle, lv_color_hsv_to_rgb( 0, 100, 100 )); // red
I have tried it with the refresh_style() call and without. I have tried removing all styles from the obj beforehand as well. The text colour for LV_STATE_DISABLED is still grey. The label is being disabled as the text does change from grren to grey, but I cannot get it to change to red. Then I tried:
} else if( lv_obj_check_type( obj, &lv_label_class )){
lv_obj_set_style_text_color( obj, lv_color_hsv_to_rgb( 0, 100, 100 ), LV_PART_MAIN | LV_STATE_DISABLED );
lv_obj_set_style_text_color( obj, lv_color_hsv_to_rgb( 100, 100, 100 ), LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_refresh_style( obj, LV_PART_MAIN, LV_STYLE_TEXT_COLOR );
}
It does exactly the same thing. I can’t get the disabled text to change color.