checkbox: use lv_switch instead of lv_checkbox

`lv_checkbox` is actually a radio button with a mandatory label on the right side.
This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent a8c449c014
commit 8761b423c6
+9 -26
View File
@@ -20,8 +20,6 @@
#include "checkbox.h" #include "checkbox.h"
#include "theme.h" #include "theme.h"
lv_style_t style_indicator;
lv_style_t style_edit;
static void checkbox_event_handler(lv_event_t* e) static void checkbox_event_handler(lv_event_t* e)
{ {
@@ -35,38 +33,23 @@ static void checkbox_event_handler(lv_event_t* e)
CheckBox::CheckBox(Window* parent, const rect_t& rect, CheckBox::CheckBox(Window* parent, const rect_t& rect,
std::function<uint8_t()> getValue, std::function<uint8_t()> getValue,
std::function<void(uint8_t)> setValue, WindowFlags flags) : std::function<void(uint8_t)> setValue, WindowFlags flags) :
FormField(parent, rect, flags, 0, lv_checkbox_create), FormField(parent, rect, flags, 0, lv_switch_create),
_getValue(std::move(getValue)), _getValue(std::move(getValue)),
_setValue(std::move(setValue)) _setValue(std::move(setValue))
{ {
coord_t size = min(rect.w, rect.h); // TODO: migrate to default theme
setWidth(size);
setHeight(size);
//TODO: migrate to default theme if (height() > 0)
lv_obj_set_width(lvobj, (lv_coord_t)(height() * 1.7f));
// BORDER // PART_MAIN
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_DISABLED), LV_PART_MAIN);
LV_PART_INDICATOR); lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_DISABLED), LV_STATE_FOCUSED);
lv_obj_set_style_border_width(lvobj, 1, LV_PART_INDICATOR);
lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS),
LV_PART_INDICATOR | LV_STATE_FOCUSED);
lv_obj_set_style_border_width(lvobj, 2, LV_PART_INDICATOR | LV_STATE_FOCUSED);
// UNCHECKED BACKGROUND
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
LV_PART_INDICATOR);
lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2),
LV_PART_INDICATOR | LV_STATE_CHECKED);
lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1),
LV_PART_INDICATOR | LV_STATE_CHECKED);
if (_getValue()) lv_obj_add_state(lvobj, LV_STATE_CHECKED); if (_getValue()) lv_obj_add_state(lvobj, LV_STATE_CHECKED);
lv_obj_add_event_cb(lvobj, checkbox_event_handler, LV_EVENT_VALUE_CHANGED, lv_obj_add_event_cb(lvobj, checkbox_event_handler,
this); LV_EVENT_VALUE_CHANGED, this);
} }
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)