Description
I’m using a button matrix to create a scrollable (matrix height is set larger than screen resolution height) menu on one of my screens. I’ve set the control of all buttons in the button matrix to have LV_VALUE_CHANGED on CLICK instead of pressed, yet when I scroll through my menu my buttons are still being triggered.
What MCU/Processor/Board and compiler are you using?
I’m using a LPCxpresso54628 Development Board.
What LVGL version are you using?
Version 8.0.2
What do you want to achieve?
The buttons in my menu to not be triggered when scrolling through the menu, only when clicked.
What have you tried so far?
Using the provided function “lv_btnmatrix_set_btn_ctrl_all(my_matrix, LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT)”
Code to reproduce
Below is a link to the micropython simulator using lvgl version 8.1, I reproduced the problem but with a simple numberpad. You can see that if you scroll around on the numberpad and then release (on a key) it’ll still trigger the event to add what key was press into the textarea.
https://sim.lvgl.io/v8.1/micropython/ports/javascript/index.html?script_direct=4ffd88de0342cfdd2ab8b5602ddb564e68dec0a5
For those that don’t like links, here’s the code from the micropython simulator:
# Initialize
import display_driver
import lvgl as lv
########################################
# Create a button matrix as a numberpad
########################################
scr = lv.obj()
matrix_cont = lv.obj(scr)
matrix_cont.set_size(200, 320)
matrix_cont.set_pos(220, 0)
# Text area for testing
text = lv.textarea(scr)
text.set_size(220, 320)
# Styling for the textarea
text_style = lv.style_t()
text_style.init()
text_style.set_radius(0)
text_style.set_border_width(0)
text_style.set_text_color(lv.color_make(0x00, 0x00, 0x00))
text.add_style(text_style, 0)
# The numberpad button matrix
matrix_map = [
"1","2","3"," ","\n",
"4","5","6"," ","\n",
"7","8","9"," ","\n",
"<-","0",".","-",""]
matrix = lv.btnmatrix(matrix_cont)
matrix.set_size(200, 400)
matrix.set_pos(0,0)
matrix.set_map(matrix_map)
matrix.set_btn_ctrl(3, lv.btnmatrix.CTRL.HIDDEN)
matrix.set_btn_ctrl(7, lv.btnmatrix.CTRL.HIDDEN)
matrix.set_btn_ctrl(11, lv.btnmatrix.CTRL.HIDDEN)
# Styling for the button matrix
matrix_style = lv.style_t()
matrix_style.init()
matrix_style.set_radius(0)
matrix_style.set_bg_color(lv.color_make(0x40, 0x65, 0xFF))
matrix_style.set_border_width(0)
matrix_style.set_pad_left(0)
matrix_style.set_pad_right(0)
matrix_style.set_pad_top(0)
matrix_style.set_pad_bottom(0)
matrix_style.set_pad_row(0)
matrix_style.set_pad_column(0)
# Styling for the button matrix buttons
matrix_button_style = lv.style_t()
matrix_button_style.init()
matrix_button_style.set_radius(0)
matrix_button_style.set_bg_color(lv.color_make(0x40, 0x65, 0xFF))
matrix_button_style.set_border_width(1)
matrix_button_style.set_border_color(lv.color_make(0xFF, 0xFF, 0xFF))
matrix_button_style.set_text_color(lv.color_make(0xFF, 0xFF, 0xFF))
matrix.add_style(matrix_style, 0)
matrix.add_style(matrix_button_style, lv.PART.ITEMS)
# Comment out this line below to see how the event handler would process the numberpad
# Using lv.EVENT.VALUE_CHANGED on pressed instead of on clicked
matrix.set_btn_ctrl_all(lv.btnmatrix.CTRL.CLICK_TRIG|lv.btnmatrix.CTRL.NO_REPEAT)
# From documentation, LV_EVENT_CLICKED: Called on release if an object did not
# scroll (regardless of long press)
def event_handler(e):
code = e.get_code()
obj = e.get_target()
if code == lv.EVENT.VALUE_CHANGED:
btn_id = obj.get_selected_btn()
text.add_text(obj.get_btn_text(btn_id))
matrix.add_event_cb(event_handler, lv.EVENT.ALL, None)
lv.scr_load(scr)