From 45b8364b0e7b3dfd99857a51d5410872f860cb3f Mon Sep 17 00:00:00 2001 From: Gabor Date: Mon, 11 Sep 2017 12:43:14 +0200 Subject: [PATCH] lv_roller: lv_ddlist_set_selected() updated to work with roller too --- lv_objx/lv_ddlist.c | 8 +++++--- lv_objx/lv_roller.c | 6 ++---- lv_objx/lv_roller.h | 7 ------- lvgl.h | 1 + 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lv_objx/lv_ddlist.c b/lv_objx/lv_ddlist.c index a19ecfcbf..b05d17038 100644 --- a/lv_objx/lv_ddlist.c +++ b/lv_objx/lv_ddlist.c @@ -234,7 +234,7 @@ void lv_ddlist_set_selected(lv_obj_t * ddlist, uint16_t sel_opt) { lv_ddlist_ext_t * ext = lv_obj_get_ext(ddlist); - ext->sel_opt = sel_opt; + ext->sel_opt = sel_opt < ext->num_opt ? sel_opt : ext->num_opt - 1; /*Move the list to show the current option*/ if(ext->opened == 0) { @@ -540,9 +540,11 @@ static void lv_ddlist_pos_act_option(lv_obj_t * ddlist) cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; lv_style_t * label_style = lv_obj_get_style(ext->opt_label); lv_obj_t * scrl = lv_page_get_scrl(ddlist); - lv_style_t * style_scrl = lv_obj_get_style(scrl); - lv_obj_set_y(scrl, -(ext->sel_opt * (font_h + label_style->line_space) - label_style->line_space) - style_scrl->hpad); + cord_t h = lv_obj_get_height(ddlist); + cord_t line_y1 = ext->sel_opt * (font_h + label_style->line_space) + ext->opt_label->cords.y1 - scrl->cords.y1; + + lv_obj_set_y(scrl, - line_y1 + (h - font_h) / 2); } diff --git a/lv_objx/lv_roller.c b/lv_objx/lv_roller.c index 57fb9585d..e25a8c3ef 100644 --- a/lv_objx/lv_roller.c +++ b/lv_objx/lv_roller.c @@ -180,8 +180,6 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m } /*Draw the object*/ else if(mode == LV_DESIGN_DRAW_MAIN) { - - lv_style_t * style = lv_obj_get_style(roller); lv_draw_rect(&roller->cords, mask, style); @@ -189,7 +187,7 @@ static bool lv_roller_design(lv_obj_t * roller, const area_t * mask, lv_design_m lv_roller_ext_t * ext = lv_obj_get_ext(roller); cord_t font_h = font_get_height(font) >> FONT_ANTIALIAS; area_t rect_area; - rect_area.y1 = lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; + rect_area.y1 = roller->cords.y1 + lv_obj_get_height(roller) / 2 - font_h / 2 - style->line_space - 2; rect_area.y2 = rect_area.y1 + font_h + style->line_space; rect_area.x1 = ext->ddlist.opt_label->cords.x1 - style->hpad; @@ -221,7 +219,7 @@ bool roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, void * param) lv_roller_ext_t * ext = lv_obj_get_ext(roller); lv_style_t * style_label = lv_obj_get_style(ext->ddlist.opt_label); - cord_t label_y1 = ext->ddlist.opt_label->cords.y1; + cord_t label_y1 = ext->ddlist.page.scrl->cords.y1 - roller->cords.y1; cord_t label_unit = (font_get_height(style_label->font) >> FONT_ANTIALIAS) + style_label->line_space / 2; cord_t mid = (roller->cords.y2 - roller->cords.y1) / 2; diff --git a/lv_objx/lv_roller.h b/lv_objx/lv_roller.h index 4a95cdf3e..873254763 100644 --- a/lv_objx/lv_roller.h +++ b/lv_objx/lv_roller.h @@ -3,13 +3,6 @@ * */ - -/*Search an replace: roller -> object normal name with lower case (e.g. button, label etc.) - * roller -> object short name with lower case(e.g. btn, label etc) - * ROLLER -> object short name with upper case (e.g. BTN, LABEL etc.) - * - */ - #ifndef LV_ROLLER_H #define LV_ROLLER_H diff --git a/lvgl.h b/lvgl.h index 3cdee0c7e..ef7144498 100644 --- a/lvgl.h +++ b/lvgl.h @@ -33,6 +33,7 @@ extern "C" { #include "lv_objx/lv_btnm.h" #include "lv_objx/lv_kb.h" #include "lv_objx/lv_ddlist.h" +#include "lv_objx/lv_roller.h" #include "lv_objx/lv_ta.h" #include "lv_objx/lv_win.h" #include "lv_objx/lv_tabview.h"