Monochrome Display Button

I am using a hardware button along with a lv_button on a monochrome display. I have successfully implemented on a color display.
On a monochrome display there are only two colors black and white.
I have implemented the lv_button with white background and black label. When the button is pressed the displayed white background goes to black (which makes sense) but the label is still black and does not show up. Is there a way the make the label white for the pressed condition and black for the released position when used with a button?

Are you using the mono theme? I believe this works properly if you use that.

Yes I am using mono theme.

Did you customize the style for the button, or are you using the default style? Did you set the current theme before you create the button, or afterward?

A code snippet would be useful.

1 Like

mono theme was set before creating button

// initialize and register a display driver
lv_disp_drv_init(&disp_drv);
disp_drv.buffer = &disp_buf;
disp_drv.flush_cb = sh1107_flush_cb;
disp_drv.set_px_cb = sh1107_set_px_cb;
disp_drv.rounder_cb = sh1107_rounder_cb;
disp_drv.user_data = this;
lv_disp_drv_register(&disp_drv);

// Set the mono system theme
theme = lv_theme_mono_init(0, NULL);
lv_theme_set_current(theme);

Button was created after mono theme set.

// create the button
lv_obj_t* btn = create_btn(parent);

// sets the GuiButton callback to call this on_clicked function
btn->user_data = this;

// create style for this button label
lv_style_copy(&gui_btn_style, &lv_style_plain);
gui_btn_style.text.font = &lv_font_unscii_8;
gui_btn_style.text.color = LV_COLOR_BLACK;

// set the size of the button
lv_obj_set_size(btn, 30, 12); 

// set the text for the button label
lv_obj_t* label = lv_label_create(btn, NULL);
lv_obj_set_style(label, &gui_btn_style);
lv_label_set_text(label, "->");

You should set the text colors in the button’s styles (pressed and released) and leave the label’s style. This way the label will inherit its style from the button.

However, it should work normally if you leave the styles unchanged after setting the mono theme.

Every things works as it should by removing style on label. So now the code looks like the following.

// set the text for the button label
lv_obj_t* label = lv_label_create(btn, NULL);
//lv_obj_set_style(label, &gui_btn_style); <----- commented out
lv_label_set_text(label, "->");

Thanks

1 Like