1、initial code
This commit is contained in:
1 parent
9686a7ff68
commit
aa3defb948
14 files changed
+2893
-161
No files matched your search
+20
-15
@@ -6,6 +6,8 @@
|
||||
|
||||
#define MY_CLASS (&lv_battery_indicator_class)
|
||||
|
||||
LV_FONT_DECLARE(lv_font_din_16);
|
||||
|
||||
static void lv_battery_indicator_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj);
|
||||
static void lv_battery_indicator_event(const lv_obj_class_t* class_p, lv_event_t* e);
|
||||
|
||||
@@ -25,29 +27,32 @@ lv_obj_t* lv_battery_indicator_create(lv_obj_t* parent) {
|
||||
LV_LOG_INFO("begin");
|
||||
lv_obj_t* obj = lv_obj_class_create_obj(MY_CLASS, parent);
|
||||
lv_obj_class_init_obj(obj);
|
||||
lv_obj_set_layout(obj, LV_LAYOUT_FLEX);
|
||||
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW);
|
||||
|
||||
lv_battery_indicator_t* self = (lv_battery_indicator_t*)obj;
|
||||
|
||||
|
||||
LV_IMG_DECLARE(battery_icon);
|
||||
lv_obj_t* battery_container = obj;
|
||||
lv_obj_set_style_bg_img_src(battery_container, &battery_icon, 0);
|
||||
lv_obj_set_size(battery_container, 26, 16);
|
||||
lv_obj_set_style_margin_right(battery_container, 4, 0);
|
||||
lv_obj_t* indicator_container = lv_obj_create(obj);
|
||||
|
||||
lv_obj_set_style_pad_all(battery_container, 2, 0);
|
||||
lv_obj_set_style_pad_left(battery_container, 3, 0);
|
||||
lv_obj_set_style_pad_right(battery_container, 6, 0);
|
||||
lv_obj_set_style_bg_img_src(indicator_container, &battery_icon, 0);
|
||||
lv_obj_set_size(indicator_container, 26, 16);
|
||||
lv_obj_set_style_margin_right(indicator_container, 4, 0);
|
||||
|
||||
self->indicator = lv_obj_create(battery_container);
|
||||
lv_obj_set_style_pad_all(indicator_container, 2, 0);
|
||||
lv_obj_set_style_pad_left(indicator_container, 3, 0);
|
||||
lv_obj_set_style_pad_right(indicator_container, 6, 0);
|
||||
|
||||
self->indicator = lv_obj_create(indicator_container);
|
||||
lv_obj_set_size(self->indicator, lv_pct(self->percentage), lv_pct(90));
|
||||
lv_obj_set_style_radius(self->indicator, 2, 0);
|
||||
lv_obj_set_align(self->indicator, LV_ALIGN_LEFT_MID);
|
||||
|
||||
|
||||
self->label = lv_label_create(parent);
|
||||
self->label = lv_label_create(obj);
|
||||
lv_obj_set_style_bg_color(self->label, lv_color_hex(0x040507), 0);
|
||||
lv_obj_set_size(self->label, 40, LV_SIZE_CONTENT);
|
||||
lv_obj_set_size(self->label, 24, LV_SIZE_CONTENT);
|
||||
lv_obj_set_style_text_font(self->label, &lv_font_din_16, 0);
|
||||
lv_obj_set_style_text_color(self->label, lv_color_hex(0xffffff), 0);
|
||||
|
||||
lv_battery_indicator_set_percentage(obj, lv_battery_indicator_get_percentage(obj));
|
||||
@@ -57,19 +62,19 @@ lv_obj_t* lv_battery_indicator_create(lv_obj_t* parent) {
|
||||
|
||||
void lv_battery_indicator_set_text_color_hex(lv_obj_t* obj, uint32_t c) {
|
||||
lv_battery_indicator_t* self = (lv_battery_indicator_t*)obj;
|
||||
lv_obj_set_style_bg_color(self->label, lv_color_hex(c), 0);
|
||||
lv_obj_set_style_text_color(self->label, lv_color_hex(c), 0);
|
||||
}
|
||||
|
||||
void lv_battery_indicator_set_text_bg_color_hex(lv_obj_t* obj, uint32_t c) {
|
||||
lv_battery_indicator_t* self = (lv_battery_indicator_t*)obj;
|
||||
lv_obj_set_style_text_color(self->label, lv_color_hex(c), 0);
|
||||
lv_obj_set_style_bg_color(self->label, lv_color_hex(c), 0);
|
||||
}
|
||||
|
||||
void lv_battery_indicator_set_percentage(lv_obj_t* obj, uint8_t value) {
|
||||
lv_battery_indicator_t* self = (lv_battery_indicator_t*)obj;
|
||||
self->percentage = value;
|
||||
self->percentage = LV_CLAMP(0, value, 100);
|
||||
lv_label_set_text_fmt(self->label, "%d%%", self->percentage);
|
||||
lv_obj_set_width(self->indicator, lv_pct(max(self->percentage, 10)));
|
||||
lv_obj_set_width(self->indicator, lv_pct(LV_MAX(self->percentage, 10)));
|
||||
if (self->percentage >= 60) {
|
||||
lv_obj_set_style_bg_color(self->indicator, lv_color_hex(0x00ff00), 0);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user