nyx: Add unsaved config changes pop up

This commit is contained in:
CTCaer 2020-05-05 19:19:12 +03:00
parent cc18a7b146
commit b1636fbb96
3 changed files with 64 additions and 0 deletions

View file

@ -1835,6 +1835,8 @@ static lv_res_t _save_options_action(lv_obj_t *btn)
lv_mbox_add_btns(mbox, mbox_btn_map, NULL);
lv_obj_set_top(mbox, true);
nyx_options_clear_ini_changes_made();
return LV_RES_OK;
}
@ -1900,6 +1902,44 @@ static void _create_status_bar(lv_theme_t * th)
lv_btn_set_action(btn_mid, LV_BTN_ACTION_CLICK, _save_options_action);
}
static lv_res_t _create_mbox_save_changes_action(lv_obj_t *btns, const char * txt)
{
int btn_idx = lv_btnm_get_pressed(btns);
mbox_action(btns, txt);
if (!btn_idx)
_save_options_action(NULL);
return LV_RES_INV;
}
void nyx_check_ini_changes()
{
if (nyx_options_get_ini_changes_made())
{
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style(dark_bg, &mbox_darken);
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
static const char * mbox_btn_map[] = { "\222Save", "\222Cancel", "" };
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
lv_mbox_set_recolor_text(mbox, true);
lv_mbox_set_text(mbox,
"#FF8000 Main configuration#\n\n"
"You changed your configuration!\n\n"
"Do you want to save it?");
lv_mbox_add_btns(mbox, mbox_btn_map, _create_mbox_save_changes_action);
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_top(mbox, true);
nyx_options_clear_ini_changes_made();
}
}
static lv_res_t _show_hide_save_button(lv_obj_t *tv, uint16_t tab_idx)
{
if (tab_idx == 4) // Options.
@ -1913,6 +1953,8 @@ static lv_res_t _show_hide_save_button(lv_obj_t *tv, uint16_t tab_idx)
lv_obj_set_click(status_bar.mid, false);
}
nyx_check_ini_changes();
return LV_RES_OK;
}

View file

@ -35,9 +35,22 @@ extern nyx_config n_cfg;
static lv_obj_t *autoboot_btn;
static bool autoboot_first_time = true;
static bool ini_changes_made = false;
void nyx_options_clear_ini_changes_made()
{
ini_changes_made = false;
}
bool nyx_options_get_ini_changes_made()
{
return ini_changes_made;
}
static lv_res_t auto_hos_poweroff_toggle(lv_obj_t *btn)
{
h_cfg.autohosoff = !h_cfg.autohosoff;
ini_changes_made = true;
if (!h_cfg.autohosoff)
lv_btn_set_state(btn, LV_BTN_STATE_REL);
@ -52,6 +65,7 @@ static lv_res_t auto_hos_poweroff_toggle(lv_obj_t *btn)
static lv_res_t auto_nogc_toggle(lv_obj_t *btn)
{
h_cfg.autonogc = !h_cfg.autonogc;
ini_changes_made = true;
if (!h_cfg.autonogc)
lv_btn_set_state(btn, LV_BTN_STATE_REL);
@ -66,6 +80,7 @@ static lv_res_t auto_nogc_toggle(lv_obj_t *btn)
static lv_res_t _update_r2p_action(lv_obj_t *btn)
{
h_cfg.updater2p = !h_cfg.updater2p;
ini_changes_made = true;
if (!h_cfg.updater2p)
lv_btn_set_state(btn, LV_BTN_STATE_REL);
@ -118,6 +133,7 @@ static lv_res_t _autoboot_disable_action(lv_obj_t *btn)
{
h_cfg.autoboot = 0;
h_cfg.autoboot_list = 0;
ini_changes_made = true;
lv_btn_set_state(autoboot_btn, LV_BTN_STATE_REL);
nyx_generic_onoff_toggle(autoboot_btn);
@ -135,6 +151,7 @@ static lv_res_t _autoboot_enable_main_action(lv_obj_t *btn)
{
h_cfg.autoboot = lv_list_get_btn_index(auto_main_list, btn) + 1;
h_cfg.autoboot_list = 0;
ini_changes_made = true;
lv_btn_set_state(autoboot_btn, LV_BTN_STATE_TGL_REL);
nyx_generic_onoff_toggle(autoboot_btn);
@ -151,6 +168,7 @@ static lv_res_t _autoboot_enable_more_action(lv_obj_t *btn)
{
h_cfg.autoboot = lv_list_get_btn_index(auto_more_list, btn) + 1;
h_cfg.autoboot_list = 1;
ini_changes_made = true;
lv_btn_set_state(autoboot_btn, LV_BTN_STATE_TGL_REL);
nyx_generic_onoff_toggle(autoboot_btn);
@ -281,6 +299,7 @@ static lv_res_t _autoboot_hide_delay_action(lv_obj_t *btn)
static lv_res_t _autoboot_delay_action(lv_obj_t *ddlist)
{
h_cfg.bootwait = lv_ddlist_get_selected(ddlist);
ini_changes_made = true;
return LV_RES_OK;
}
@ -289,6 +308,7 @@ static lv_res_t _slider_brightness_action(lv_obj_t * slider)
{
display_backlight_brightness(lv_slider_get_value(slider) - 20, 0);
h_cfg.backlight = lv_slider_get_value(slider);
ini_changes_made = true;
return LV_RES_OK;
}

View file

@ -19,6 +19,8 @@
#include "../libs/lvgl/lvgl.h"
void nyx_options_clear_ini_changes_made();
bool nyx_options_get_ini_changes_made();
lv_res_t create_win_nyx_options(lv_obj_t *parrent_btn);
void create_tab_options(lv_theme_t *th, lv_obj_t *parent);