From 955dda60c5a58ff905da012307b1fbb2b973c467 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 19 May 2022 23:12:35 +0300 Subject: [PATCH] Use lambda to reduce code duplication --- src/displayapp/widgets/Counter.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/displayapp/widgets/Counter.cpp b/src/displayapp/widgets/Counter.cpp index 92af89f4..ecf39613 100644 --- a/src/displayapp/widgets/Counter.cpp +++ b/src/displayapp/widgets/Counter.cpp @@ -109,17 +109,18 @@ void Counter::Create() { linePoints[0] = {0, 0}; linePoints[1] = {width, 0}; - upperLine = lv_line_create(counterContainer, nullptr); - lv_line_set_points(upperLine, linePoints, 2); - lv_obj_set_style_local_line_width(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 1); - lv_obj_set_style_local_line_color(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_obj_set_style_local_line_opa(upperLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + auto LineCreate = [&]() { + lv_obj_t* line = lv_line_create(counterContainer, nullptr); + lv_line_set_points(line, linePoints, 2); + lv_obj_set_style_local_line_width(line, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 1); + lv_obj_set_style_local_line_color(line, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_line_opa(line, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + return line; + }; + + upperLine = LineCreate(); lv_obj_align(upperLine, upBtn, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); - lowerLine = lv_line_create(counterContainer, nullptr); - lv_line_set_points(lowerLine, linePoints, 2); - lv_obj_set_style_local_line_width(lowerLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 1); - lv_obj_set_style_local_line_color(lowerLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_obj_set_style_local_line_opa(lowerLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_20); + lowerLine = LineCreate(); lv_obj_align(lowerLine, downBtn, LV_ALIGN_OUT_TOP_MID, 0, -1); }