Important: posts that do not use this template will be ignored or closed.
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. We will not respond in detail to posts where you haven’t read the relevant documentation.
- If applicable use the Simulator to eliminate hardware related issues.
Delete this section if you read and applied the mentioned points.
Description
What MCU/Processor/Board and compiler are you using?
visual studio 2017
What LVGL version are you using?
v7
What do you want to achieve?
how to overcome roller events influence each other
What have you tried so far?
Change the roller style and some other property
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:
/*You code here*/
/******************************roller_test.h*******************/
#pragma once
#ifndef ROLLER_TEST_H
#define ROLLER_TEST_H
#include "lvgl/lvgl.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
void SetupScreen(lv_obj_t *obj);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // ! UI_MORE_TIMER_H
/******************************roller_test.c*******************/
#include "lvgl/lvgl.h"
#include "roller_test.h"
static lv_obj_t *tabview = NULL;
static lv_obj_t *tab1 = NULL;
static lv_style_t rollerBgStyle, rollerSelStyle;
static char hourStrBuf[3] = { 0 };
static char minuteStrBuf[3] = { 0 };
static char secondStrBuf[3] = { 0 };
static lv_obj_t *hourRoller = NULL;
static lv_obj_t *minuteRoller = NULL;
static lv_obj_t *secondRoller = NULL;
static uint32_t timerTmp = 60;
static const char *HourBuf = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23";
static const char *MinuteBuf = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29"
"\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static const char *SecondBuf = "00\n01\n02\n03\n04\n05\n06\n07\n08\n09\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29"
"\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59";
static void InitTableview(lv_obj_t *obj)
{
static lv_style_t bgStyle;
static lv_style_t scrlStyle;
tabview = lv_tabview_create(obj, NULL);
lv_obj_set_size(tabview, LV_HOR_RES, LV_VER_RES);
lv_obj_add_style(tabview, LV_OBJ_PART_MAIN, &bgStyle);
lv_tabview_set_btns_pos(tabview, LV_TABVIEW_TAB_POS_NONE);
lv_obj_align(tabview, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
tab1 = lv_tabview_add_tab(tabview, "Tab1");
lv_page_set_scrlbar_mode(tab1, LV_SCRLBAR_MODE_OFF);
lv_obj_add_style(tab1, LV_PAGE_PART_SCROLLABLE, &scrlStyle);
lv_tabview_set_tab_act(tabview, 1, LV_ANIM_OFF);
}
static void RollerSetting(lv_obj_t *roller, const char *opt, lv_coord_t xpos, uint16_t index, lv_event_cb_t event)
{
roller = lv_roller_create(tab1, NULL);
lv_roller_set_options(roller, opt, LV_ROLLER_MODE_INIFINITE);
lv_obj_set_size(roller, 36, 150);
lv_obj_add_style(roller, LV_ROLLER_PART_BG, &rollerBgStyle);
lv_obj_add_style(roller, LV_ROLLER_PART_SELECTED, &rollerSelStyle);
lv_roller_set_auto_fit(roller, false);
lv_roller_set_visible_row_count(roller, 3);
lv_roller_set_selected(roller, index, LV_ANIM_OFF);
if (&event == NULL) {
lv_obj_set_event_cb(roller, event);
}
lv_obj_align(roller, NULL, LV_ALIGN_IN_TOP_LEFT, xpos, 40);
}
static void TimerHourRollerEventHandler(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_VALUE_CHANGED) {
memset(hourStrBuf, 0, sizeof(hourStrBuf));
lv_roller_get_selected_str(obj, hourStrBuf, sizeof(hourStrBuf));
}
}
static void TimerMinuteRollerEventHandler(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_VALUE_CHANGED) {
memset(minuteStrBuf, 0, sizeof(minuteStrBuf));
lv_roller_get_selected_str(obj, minuteStrBuf, sizeof(minuteStrBuf));
}
}
static void TimerSecondRollerEventHandler(lv_obj_t *obj, lv_event_t event)
{
if (event == LV_EVENT_VALUE_CHANGED) {
memset(secondStrBuf, 0, sizeof(secondStrBuf));
lv_roller_get_selected_str(obj, secondStrBuf, sizeof(secondStrBuf));
}
}
static void SettingTimerUI(void)
{
uint16_t hourIndex = timerTmp / 3600 + 2;
if (hourRoller == NULL) {
RollerSetting(hourRoller, HourBuf, 30, hourIndex, TimerHourRollerEventHandler);
}
uint16_t minuteIndex = timerTmp % 3600 / 60 + 5;
if (minuteRoller == NULL) {
RollerSetting(minuteRoller, MinuteBuf, 133, minuteIndex, TimerMinuteRollerEventHandler);
}
uint16_t secondIndex = timerTmp % 60 + 5;
if (secondRoller == NULL) {
RollerSetting(secondRoller, SecondBuf, 234, secondIndex, TimerSecondRollerEventHandler);
}
}
static void InitRollerStyle(void)
{
lv_style_reset(&rollerBgStyle);
lv_style_init(&rollerBgStyle);
lv_style_set_bg_color(&rollerBgStyle, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_grad_color(&rollerBgStyle, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_opa(&rollerBgStyle, LV_STATE_DEFAULT, LV_OPA_100);
lv_style_set_radius(&rollerBgStyle, LV_STATE_DEFAULT, 0);
lv_style_set_border_width(&rollerBgStyle, LV_STATE_DEFAULT, 0);
lv_style_set_text_opa(&rollerBgStyle, LV_STATE_DEFAULT, LV_OPA_100);
lv_style_set_text_line_space(&rollerBgStyle, LV_STATE_DEFAULT, 32);
lv_style_set_text_color(&rollerBgStyle, LV_STATE_DEFAULT, LV_COLOR_GRAY);
lv_style_reset(&rollerSelStyle);
lv_style_init(&rollerSelStyle);
lv_style_set_bg_color(&rollerSelStyle, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_bg_grad_color(&rollerSelStyle, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_style_set_text_color(&rollerSelStyle, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x00, 0xd8, 0xff));
}
void SetupScreen(lv_obj_t *obj)
{
InitTableview(obj);
InitRollerStyle();
SettingTimerUI();
}
## Screenshot and/or video
If possible, add screenshots and/or videos about the current state.
I build three roller and each of them has an event,but
when I rolling one of them with no stop exactly on an option and at this time rolling another,the previous even move.