Skip to content

Commit

Permalink
Merge pull request #369 from Master92/disable_items
Browse files Browse the repository at this point in the history
Improve configuration user experience
  • Loading branch information
ligenxxxx authored Nov 30, 2023
2 parents 608762e + 62ad82e commit 0f8cabf
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 28 deletions.
3 changes: 3 additions & 0 deletions src/ui/page_autoscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ static lv_obj_t *page_autoscan_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);

create_select_item(arr, cont);
lv_obj_set_grid_cell(pp_autoscan.p_arr.panel[1], LV_GRID_ALIGN_STRETCH, 0, 6,
LV_GRID_ALIGN_STRETCH, 1, 2);
lv_obj_clear_flag(pp_autoscan.p_arr.panel[2], FLAG_SELECTABLE);

btn_group_t btn_group;
create_btn_group_item(&btn_group0, cont, 3, "Auto Scan", "On", "Last", "Off", "", 0);
Expand Down
56 changes: 55 additions & 1 deletion src/ui/page_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void create_select_item(panel_arr_t *arr, lv_obj_t *parent) {
arr->panel[i] = lv_obj_create(parent);
lv_obj_clear_flag(arr->panel[i], LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_flag(arr->panel[i], LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(arr->panel[i], FLAG_SELECTABLE);
lv_obj_add_style(arr->panel[i], &style_select, LV_PART_MAIN);
lv_obj_set_grid_cell(arr->panel[i], LV_GRID_ALIGN_STRETCH, 0, 6,
LV_GRID_ALIGN_STRETCH, i, 1);
Expand Down Expand Up @@ -98,6 +99,7 @@ lv_obj_t *create_label_item_compact(lv_obj_t *parent, const char *name, int col,
lv_obj_set_size(label, 120 * cols, height);

lv_label_set_recolor(label, true);
lv_obj_set_style_text_color(label, COLOR_DISABLED, STATE_DISABLED);

lv_obj_set_grid_cell(label, col_align, col, cols,
LV_GRID_ALIGN_CENTER, row, 1);
Expand All @@ -114,6 +116,7 @@ lv_obj_t *create_label_item(lv_obj_t *parent, const char *name, int col, int row
lv_obj_set_size(label, 320 * cols, 60);

lv_label_set_recolor(label, true);
lv_obj_set_style_text_color(label, COLOR_DISABLED, STATE_DISABLED);

lv_obj_set_grid_cell(label, LV_GRID_ALIGN_START, col, cols,
LV_GRID_ALIGN_CENTER, row, 1);
Expand Down Expand Up @@ -146,16 +149,22 @@ void create_slider_item_compact(slider_group_t *slider_group, lv_obj_t *parent,
lv_obj_set_size(slider_group->name, 200, 40);
lv_obj_set_grid_cell(slider_group->name, LV_GRID_ALIGN_START, 1, 1,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(slider_group->name, COLOR_DISABLED, STATE_DISABLED);

slider_group->slider = lv_slider_create(parent);

lv_obj_remove_style_all(slider_group->slider);
lv_obj_add_style(slider_group->slider, &style_silder_main, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_MAIN | STATE_DISABLED);

lv_obj_add_style(slider_group->slider, &style_silder_indicator, LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_INDICATOR | STATE_DISABLED);
lv_obj_add_style(slider_group->slider, &style_silder_pressed_color, LV_PART_INDICATOR | LV_STATE_PRESSED);

lv_obj_set_style_bg_opa(slider_group->slider, LV_OPA_COVER, LV_PART_KNOB);
lv_obj_set_style_pad_ver(slider_group->slider, 10, LV_PART_KNOB);
lv_obj_set_style_pad_hor(slider_group->slider, 2, LV_PART_KNOB);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_KNOB | STATE_DISABLED);
lv_obj_add_style(slider_group->slider, &style_silder_pressed_color, LV_PART_KNOB | LV_STATE_PRESSED);

lv_obj_set_size(slider_group->slider, 0, 2);
Expand All @@ -176,6 +185,7 @@ void create_slider_item_compact(slider_group_t *slider_group, lv_obj_t *parent,
lv_obj_set_size(slider_group->label, 160, 40);
lv_obj_set_grid_cell(slider_group->label, LV_GRID_ALIGN_START, 4, 1,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(slider_group->label, COLOR_DISABLED, STATE_DISABLED);
}

void create_slider_item(slider_group_t *slider_group, lv_obj_t *parent, const char *name, int range, int default_value, int row) {
Expand All @@ -188,14 +198,20 @@ void create_slider_item(slider_group_t *slider_group, lv_obj_t *parent, const ch
lv_obj_set_size(slider_group->name, 320, 60);
lv_obj_set_grid_cell(slider_group->name, LV_GRID_ALIGN_START, 1, 2,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(slider_group->name, COLOR_DISABLED, STATE_DISABLED);

slider_group->slider = lv_slider_create(parent);

lv_obj_remove_style_all(slider_group->slider);
lv_obj_add_style(slider_group->slider, &style_silder_main, LV_PART_MAIN);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_MAIN | STATE_DISABLED);

lv_obj_add_style(slider_group->slider, &style_silder_indicator, LV_PART_INDICATOR);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_INDICATOR | STATE_DISABLED);
lv_obj_add_style(slider_group->slider, &style_silder_pressed_color, LV_PART_INDICATOR | LV_STATE_PRESSED);

lv_obj_add_style(slider_group->slider, &style_silder_knob, LV_PART_KNOB);
lv_obj_set_style_bg_color(slider_group->slider, COLOR_DISABLED, LV_PART_KNOB | STATE_DISABLED);
lv_obj_add_style(slider_group->slider, &style_silder_pressed_color, LV_PART_KNOB | LV_STATE_PRESSED);

lv_obj_set_size(slider_group->slider, 320, 3);
Expand All @@ -216,6 +232,7 @@ void create_slider_item(slider_group_t *slider_group, lv_obj_t *parent, const ch
lv_obj_set_size(slider_group->label, 160, 60);
lv_obj_set_grid_cell(slider_group->label, LV_GRID_ALIGN_START, 5, 1,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(slider_group->label, COLOR_DISABLED, STATE_DISABLED);
}

void update_slider_item_with_value(slider_group_t *slider_group, int value) {
Expand All @@ -236,6 +253,7 @@ void create_btn_item(lv_obj_t *parent, const char *name, int col, int row) {
lv_obj_set_style_text_font(btn, &lv_font_montserrat_26, 0);
lv_obj_set_style_text_align(btn, LV_TEXT_ALIGN_LEFT, 0);
lv_obj_set_style_bg_color(btn, lv_color_make(19, 19, 19), 0);
lv_obj_set_style_bg_color(btn, COLOR_DISABLED, STATE_DISABLED);
lv_obj_set_style_bg_opa(btn, 0x0, 0);
lv_obj_set_style_shadow_width(btn, 0, 0);
lv_obj_set_style_pad_top(btn, 0, 0);
Expand All @@ -252,6 +270,7 @@ lv_obj_t *create_dropdown_item(lv_obj_t *parent, const char *options, int col, i
lv_obj_set_style_shadow_width(obj, 0, 0);
lv_obj_set_style_pad_top(obj, pad_top, 0);
lv_obj_set_size(obj, width, height);
lv_obj_set_style_text_color(obj, COLOR_DISABLED, STATE_DISABLED);

lv_obj_set_grid_cell(obj, column_align, col, col_span, LV_GRID_ALIGN_CENTER, row, 1);

Expand Down Expand Up @@ -293,6 +312,7 @@ static void create_btn_with_arrow(lv_obj_t *parent, btn_with_arr_t *btn_a, const
lv_obj_set_size(btn_a->btn, 160, 60);
lv_obj_set_grid_cell(btn_a->btn, LV_GRID_ALIGN_START, 1, 1,
LV_GRID_ALIGN_CENTER, 0, 1);
lv_obj_set_style_text_color(btn_a->label, COLOR_DISABLED, STATE_DISABLED);

lv_obj_set_style_pad_column(btn_a->container, 0, 0);
}
Expand Down Expand Up @@ -360,6 +380,7 @@ static void create_btn_with_arrow_compact(lv_obj_t *parent, btn_with_arr_t *btn_
lv_obj_set_style_bg_color(btn_a->btn, lv_color_make(19, 19, 19), 0);
lv_obj_set_style_bg_opa(btn_a->btn, 0x0, 0);
lv_obj_set_style_shadow_width(btn_a->btn, 0, 0);
lv_obj_set_style_text_color(btn_a->label, COLOR_DISABLED, STATE_DISABLED);

lv_obj_set_style_pad_top(btn_a->btn, 0, 0);
lv_obj_set_style_pad_bottom(btn_a->btn, 0, 0);
Expand Down Expand Up @@ -414,6 +435,7 @@ void create_btn_group_item(btn_group_t *btn_group, lv_obj_t *parent, int count,
lv_obj_set_size(btn_group->label, 320, 60);
lv_obj_set_grid_cell(btn_group->label, LV_GRID_ALIGN_START, 1, 2,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(btn_group->label, COLOR_DISABLED, STATE_DISABLED);

create_btn_with_arrow(parent, &btn_group->btn_a[0], name0, row, 2);
if (count >= 2) {
Expand Down Expand Up @@ -443,6 +465,7 @@ void create_btn_group_item2(btn_group_t *btn_group, lv_obj_t *parent, int count,
lv_obj_set_size(label, 320, 60);
lv_obj_set_grid_cell(label, LV_GRID_ALIGN_START, 1, 2,
LV_GRID_ALIGN_CENTER, row, 1);
lv_obj_set_style_text_color(label, COLOR_DISABLED, STATE_DISABLED);

create_btn_with_arrow(parent, &btn_group->btn_a[0], name0, row, 2);
if (count >= 2) {
Expand Down Expand Up @@ -480,6 +503,18 @@ void slider_show(slider_group_t *slider_group, bool visible) {
}
}

void slider_enable(slider_group_t *slider_group, bool enable) {
if (enable) {
lv_obj_clear_state(slider_group->slider, STATE_DISABLED);
lv_obj_clear_state(slider_group->label, STATE_DISABLED);
lv_obj_clear_state(slider_group->name, STATE_DISABLED);
} else {
lv_obj_add_state(slider_group->slider, STATE_DISABLED);
lv_obj_add_state(slider_group->label, STATE_DISABLED);
lv_obj_add_state(slider_group->name, STATE_DISABLED);
}
}

void btn_group_show(btn_group_t *btn_group, bool visible) {
for (int i = 0; i < btn_group->valid; ++i) {
if (visible) {
Expand All @@ -499,4 +534,23 @@ void btn_group_show(btn_group_t *btn_group, bool visible) {
lv_obj_add_flag(btn_group->btn_a[sel].label, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(btn_group->label, LV_OBJ_FLAG_HIDDEN);
}
}
}

void btn_group_enable(btn_group_t *btn_group, bool enable) {
for (int i = 0; i < btn_group->valid; ++i) {
if (enable) {
lv_obj_clear_state(btn_group->btn_a[i].label, STATE_DISABLED);
} else {
lv_obj_add_state(btn_group->btn_a[i].label, STATE_DISABLED);
}
}

const int sel = btn_group_get_sel(btn_group);
if (enable) {
lv_obj_clear_state(btn_group->label, STATE_DISABLED);
lv_obj_clear_flag(btn_group->btn_a[sel].arrow, LV_OBJ_FLAG_HIDDEN);
} else {
lv_obj_add_state(btn_group->label, STATE_DISABLED);
lv_obj_add_flag(btn_group->btn_a[sel].arrow, LV_OBJ_FLAG_HIDDEN);
}
}
6 changes: 6 additions & 0 deletions src/ui/page_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ extern "C" {

#define MAX_PANELS 9

#define FLAG_SELECTABLE LV_OBJ_FLAG_USER_1
#define STATE_DISABLED LV_STATE_USER_1
#define COLOR_DISABLED (lv_color_darken(lv_color_white(), 127))

typedef enum {
SOURCE_HDZERO = 0,
SOURCE_HDMI_IN = 1,
Expand Down Expand Up @@ -171,7 +175,9 @@ void create_select_item(panel_arr_t *arr, lv_obj_t *parent);
void set_select_item(const panel_arr_t *arr, int row);

void slider_show(slider_group_t *slider_group, bool visible);
void slider_enable(slider_group_t *slider_group, bool enable);
void btn_group_show(btn_group_t *btn_group, bool visible);
void btn_group_enable(btn_group_t *btn_group, bool enable);

#ifdef __cplusplus
}
Expand Down
38 changes: 37 additions & 1 deletion src/ui/page_elrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ static lv_obj_t *btn_vtx_send;
static btn_group_t elrs_group;
static bool binding = false;

static void update_visibility() {
const bool backpackIsActive = elrs_group.current == 0;

if (backpackIsActive) {
lv_obj_clear_state(btn_wifi, STATE_DISABLED);
lv_obj_clear_state(label_wifi_status, STATE_DISABLED);
lv_obj_clear_state(label_wifi_status, STATE_DISABLED);
lv_obj_clear_state(btn_bind, STATE_DISABLED);
lv_obj_clear_state(label_bind_status, STATE_DISABLED);
lv_obj_clear_state(btn_vtx_send, STATE_DISABLED);

lv_obj_add_flag(pp_elrs.p_arr.panel[0], FLAG_SELECTABLE);
lv_obj_add_flag(pp_elrs.p_arr.panel[2], FLAG_SELECTABLE);
lv_obj_add_flag(pp_elrs.p_arr.panel[3], FLAG_SELECTABLE);
} else {
lv_obj_add_state(btn_wifi, STATE_DISABLED);
lv_obj_add_state(label_wifi_status, STATE_DISABLED);
lv_obj_add_state(label_wifi_status, STATE_DISABLED);
lv_obj_add_state(btn_bind, STATE_DISABLED);
lv_obj_add_state(label_bind_status, STATE_DISABLED);
lv_obj_add_state(btn_vtx_send, STATE_DISABLED);

lv_obj_clear_flag(pp_elrs.p_arr.panel[0], FLAG_SELECTABLE);
lv_obj_clear_flag(pp_elrs.p_arr.panel[2], FLAG_SELECTABLE);
lv_obj_clear_flag(pp_elrs.p_arr.panel[3], FLAG_SELECTABLE);
}
}

static lv_obj_t *page_elrs_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *page = lv_menu_page_create(parent, NULL);
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
Expand Down Expand Up @@ -85,6 +113,8 @@ static lv_obj_t *page_elrs_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_label_set_long_mode(cancel_label, LV_LABEL_LONG_WRAP);
lv_obj_set_grid_cell(cancel_label, LV_GRID_ALIGN_START, 1, 3, LV_GRID_ALIGN_START, POS_MAX, 2);

update_visibility();

return page;
}

Expand Down Expand Up @@ -129,7 +159,11 @@ static void elrs_enable_timer(struct _lv_timer_t *timer) {
static void page_elrs_enter() {
lv_label_set_text(label_wifi_status, "Click to start");
lv_label_set_text(label_bind_status, "Click to start");
request_uid();
if (elrs_group.current == 0) {
request_uid();
} else {
pp_elrs.p_arr.cur = 1;
}
}

static void page_elrs_on_click(uint8_t key, int sel) {
Expand All @@ -142,6 +176,8 @@ static void page_elrs_on_click(uint8_t key, int sel) {
enable_esp32();
else
disable_esp32();

update_visibility();
} else if (sel == POS_VTX) // Send VTX freq
{
msp_channel_update();
Expand Down
13 changes: 13 additions & 0 deletions src/ui/page_fans.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ static btn_group_t btn_group_fans;

static slider_group_t slider_group[2];

static void update_visibility() {
slider_enable(&slider_group[1], btn_group_fans.current != 0);

if (btn_group_fans.current == 0) {
lv_obj_clear_flag(pp_fans.p_arr.panel[2], FLAG_SELECTABLE);
} else {
lv_obj_add_flag(pp_fans.p_arr.panel[2], FLAG_SELECTABLE);
}
}

static lv_obj_t *page_fans_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *page = lv_menu_page_create(parent, NULL);
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
Expand Down Expand Up @@ -74,6 +84,8 @@ static lv_obj_t *page_fans_create(lv_obj_t *parent, panel_arr_t *arr) {
sprintf(buf, "%d", g_setting.fans.left_speed);
lv_label_set_text(slider_group[1].label, buf);

update_visibility();

return page;
}

Expand Down Expand Up @@ -203,6 +215,7 @@ static void page_fans_mode_on_click(uint8_t key, int sel) {
btn_group_toggle_sel(&btn_group_fans);
g_setting.fans.auto_mode = btn_group_get_sel(&btn_group_fans) == 0;
settings_put_bool("fans", "auto", g_setting.fans.auto_mode);
update_visibility();
return;
} else if (sel == 1) {
slider = slider_group[0].slider;
Expand Down
27 changes: 26 additions & 1 deletion src/ui/page_headtracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,34 @@ static btn_group_t btn_group;
static lv_coord_t col_dsc[] = {160, 160, 160, 160, 160, 160, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {60, 60, 60, 60, 60, 60, 40, 40, 40, 60, LV_GRID_TEMPLATE_LAST};
static lv_obj_t *label_cali;
static lv_obj_t *label_center;
static lv_timer_t *timer;
static lv_obj_t *pan;
static lv_obj_t *tilt;
static lv_obj_t *roll;
static slider_group_t slider_group;
bool angle_slider_selected;

static void update_visibility() {
slider_enable(&slider_group, g_setting.ht.enable);

if (g_setting.ht.enable) {
lv_obj_clear_state(label_cali, STATE_DISABLED);
lv_obj_clear_state(label_center, STATE_DISABLED);

lv_obj_add_flag(pp_headtracker.p_arr.panel[1], FLAG_SELECTABLE);
lv_obj_add_flag(pp_headtracker.p_arr.panel[2], FLAG_SELECTABLE);
lv_obj_add_flag(pp_headtracker.p_arr.panel[3], FLAG_SELECTABLE);
} else {
lv_obj_add_state(label_cali, STATE_DISABLED);
lv_obj_add_state(label_center, STATE_DISABLED);

lv_obj_clear_flag(pp_headtracker.p_arr.panel[1], FLAG_SELECTABLE);
lv_obj_clear_flag(pp_headtracker.p_arr.panel[2], FLAG_SELECTABLE);
lv_obj_clear_flag(pp_headtracker.p_arr.panel[3], FLAG_SELECTABLE);
}
}

static lv_obj_t *page_headtracker_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_t *page = lv_menu_page_create(parent, NULL);
lv_obj_clear_flag(page, LV_OBJ_FLAG_SCROLLABLE);
Expand Down Expand Up @@ -50,7 +71,7 @@ static lv_obj_t *page_headtracker_create(lv_obj_t *parent, panel_arr_t *arr) {

label_cali = create_label_item(cont, "Calibrate", 1, 1, 1);

create_label_item(cont, "Set Center", 1, 2, 1);
label_center = create_label_item(cont, "Set Center", 1, 2, 1);

create_slider_item(&slider_group, cont, "Max Angle", 360, g_setting.ht.max_angle, 3);
lv_slider_set_range(slider_group.slider, 0, 360);
Expand Down Expand Up @@ -97,6 +118,8 @@ static lv_obj_t *page_headtracker_create(lv_obj_t *parent, panel_arr_t *arr) {
lv_obj_set_style_radius(roll, 0, LV_PART_INDICATOR);
lv_obj_set_grid_cell(roll, LV_GRID_ALIGN_START, 2, 1,
LV_GRID_ALIGN_CENTER, 8, 1);

update_visibility();
return page;
}

Expand Down Expand Up @@ -164,6 +187,8 @@ static void page_headtracker_on_click(uint8_t key, int sel) {
ht_enable();
else
ht_disable();

update_visibility();
} else if (sel == 1) {
lv_label_set_text(label_cali, "Calibrating...");
lv_timer_handler();
Expand Down
Loading

0 comments on commit 0f8cabf

Please sign in to comment.