So here’s a more complete example to demonstrate the problem:
static lv_obj_t *menu_page=NULL;
static lv_obj_t *up_btn;
static lv_obj_t *dn_btn;
static void update_updn (void)
{
if (lv_page_on_edge (menu_page, LV_PAGE_EDGE_TOP))
lv_btn_set_state (up_btn, LV_BTN_STATE_DISABLED);
else
lv_btn_set_state (up_btn, LV_BTN_STATE_RELEASED);
if (lv_page_on_edge (menu_page, LV_PAGE_EDGE_BOTTOM))
lv_btn_set_state (dn_btn, LV_BTN_STATE_DISABLED);
else
lv_btn_set_state (dn_btn, LV_BTN_STATE_RELEASED);
printf ("ev top-edge:%d bottom-edge:%d\r\n",
lv_page_on_edge (menu_page, LV_PAGE_EDGE_TOP),
lv_page_on_edge (menu_page, LV_PAGE_EDGE_BOTTOM));
}
static void scroll_up (lv_obj_t *btn, lv_event_t event)
{
switch (event) {
case LV_EVENT_PRESSED: /* FALL THRU */
case LV_EVENT_LONG_PRESSED_REPEAT:
lv_page_scroll_ver (menu_page, 160);
update_updn ();
break;
}
}
static void scroll_dn (lv_obj_t *btn, lv_event_t event)
{
switch (event) {
case LV_EVENT_PRESSED: /* FALL THRU */
case LV_EVENT_LONG_PRESSED_REPEAT:
lv_page_scroll_ver (menu_page, -160);
update_updn ();
break;
}
}
void test_screen (void)
{
lv_style_t disabled;
lv_style_init (&disabled);
lv_style_set_bg_color (&disabled, LV_BTN_STATE_DISABLED, LV_COLOR_RED);
lv_style_set_border_color (&disabled, LV_BTN_STATE_DISABLED, LV_COLOR_RED);
menu_page = lv_page_create (lv_scr_act(), NULL);
lv_obj_set_size (menu_page, 350, 430);
lv_obj_align (menu_page, NULL, LV_ALIGN_CENTER, 0, 0);
lv_page_set_scrl_layout (menu_page, LV_LAYOUT_COLUMN_MID);
for (int i=0; i<10; i++) {
lv_obj_t *menu_btn = lv_btn_create (menu_page, NULL);
lv_obj_set_height (menu_btn, 60);
lv_obj_t *label = lv_label_create (menu_btn, NULL);
char text[100];
sprintf (text, "Menu-entry %d", i);
lv_label_set_text (label, text);
}
up_btn = lv_btn_create (lv_scr_act(), NULL);
dn_btn = lv_btn_create (lv_scr_act(), NULL);
lv_obj_align (up_btn, menu_page, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
lv_obj_align (dn_btn, menu_page, LV_ALIGN_OUT_RIGHT_BOTTOM, 0, 0);
lv_obj_set_event_cb (up_btn, scroll_up);
lv_obj_set_event_cb (dn_btn, scroll_dn);
lv_obj_add_style (up_btn, LV_BTN_PART_MAIN, &disabled);
lv_obj_add_style (dn_btn, LV_BTN_PART_MAIN, &disabled);
lv_obj_t *up_lbl = lv_label_create (up_btn, NULL);
lv_obj_t *dn_lbl = lv_label_create (dn_btn, NULL);
lv_label_set_text (up_lbl, "Up");
lv_label_set_text (dn_lbl, "Down");
}
BTW: for some reason the up/down buttons ignore the style setting which I have introduced to make the visualization more visible.
Any ideas what might be wrong here?