// This file was generated by SquareLine Studio
// SquareLine Studio version: SquareLine Studio 1.6.0
// LVGL version: 8.3.11
// Project name: Lcd_Pro

#include "../ui.h"
#include "ui_ScreenImg.h"  // 用于调用 ui_ScreenImg_show_delete_container
#include "../../pages/include/pages.h"
#include "../../sleep_mgr/include/sleep_mgr.h"
#include "esp_lvgl_port.h"  // LVGL锁机制
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

lv_obj_t *ui_ScreenSet = NULL;lv_obj_t *ui_GlobalContainer = NULL;lv_obj_t *ui_ContainerTop = NULL;lv_obj_t *ui_ImgLowPower = NULL;lv_obj_t *ui_ImgFlashlight = NULL;lv_obj_t *ui_ImgDelete = NULL;lv_obj_t *ui_ContainerCentral = NULL;lv_obj_t *ui_SliderBrightness = NULL;lv_obj_t *ui_ImgSun = NULL;lv_obj_t *ui_LabelBrightness = NULL;lv_obj_t *ui_ArcPowerLevel = NULL;lv_obj_t *ui_ImgLightning = NULL;lv_obj_t *ui_LabelPowerLevel = NULL;

// 记录从哪个界面进入ScreenSet（用于返回）
static lv_obj_t **previous_screen = NULL;
static void (*previous_screen_init)(void) = NULL;

// 设置前一个界面（在切换到ScreenSet前调用）
void ui_ScreenSet_set_previous(lv_obj_t **screen, void (*init_func)(void)) {
    previous_screen = screen;
    previous_screen_init = init_func;
}

// ==================== 手电筒功能 ====================
static lv_obj_t *flashlight_overlay = NULL;  // 手电筒全屏遮罩层
static lv_timer_t *flashlight_timer = NULL;  // 闪烁定时器
static uint8_t flashlight_color_index = 0;   // 当前颜色索引
static bool flashlight_bright = true;        // 当前亮度状态（true=亮，false=暗）
static uint8_t saved_brightness = 50;        // 保存进入手电筒前的亮度

// 手电筒颜色数组（RGB三原色，可扩展）
// 使用24位RGB值，LVGL会自动转换为RGB565
static const uint32_t flashlight_color_values[] = {
    0xFF0000,  // 红色
    0x00FF00,  // 绿色
    0x0000FF,  // 蓝色
    // 可在此添加更多颜色，例如：
    // 0xFFFF00,  // 黄色
    // 0xFF00FF,  // 品红
    // 0x00FFFF,  // 青色
    // 0xFFFFFF,  // 白色
};
#define FLASHLIGHT_COLOR_COUNT (sizeof(flashlight_color_values) / sizeof(flashlight_color_values[0]))

// 手电筒闪烁定时器回调（每500ms切换亮度，总周期1000ms）
static void flashlight_blink_timer_cb(lv_timer_t *timer) {
    if (!flashlight_overlay) return;

    // 切换亮暗状态
    flashlight_bright = !flashlight_bright;

    // 调整PWM亮度：亮=100%，暗=20%
    if (flashlight_bright) {
        pwm_set_brightness(100);
    } else {
        pwm_set_brightness(20);
    }
}

// PWM淡入淡出步进定时器（用于平滑过渡）
static lv_timer_t *fade_timer = NULL;
static uint8_t target_brightness = 100;
static int8_t fade_step = 0;  // 正数=淡入，负数=淡出

// 前向声明
static void fade_in_delayed_cb(lv_timer_t *timer);
static void flashlight_overlay_event_cb(lv_event_t *e);

// PWM淡入淡出定时器回调（每2ms调整一次亮度）
static void fade_brightness_cb(lv_timer_t *timer) {
    uint8_t current = pwm_get_brightness();

    if (fade_step > 0) {
        // 淡入：逐步增加亮度
        if (current < target_brightness) {
            current += fade_step;
            if (current > target_brightness) current = target_brightness;
            pwm_set_brightness(current);
        } else {
            // 淡入完成，停止定时器
            lv_timer_del(fade_timer);
            fade_timer = NULL;
        }
    } else if (fade_step < 0) {
        // 淡出：逐步减少亮度
        if (current > 0) {
            current += fade_step;  // fade_step是负数
            if (current < 0 || current > 100) current = 0;
            pwm_set_brightness(current);
        } else {
            // 淡出完成，停止定时器
            lv_timer_del(fade_timer);
            fade_timer = NULL;
        }
    }
}

// 启动PWM淡入淡出（fade_out=true为淡出，false为淡入）
static void start_fade(bool fade_out, uint8_t target_bright) {
    // 停止之前的淡入淡出
    if (fade_timer) {
        lv_timer_del(fade_timer);
        fade_timer = NULL;
    }

    target_brightness = target_bright;
    fade_step = fade_out ? -25 : 25;  // 每次调整25%亮度（优化：4次完成，8ms）
    fade_timer = lv_timer_create(fade_brightness_cb, 2, NULL);  // 2ms间隔
}

// 颜色切换延迟回调（简化版：只修改样式）
static void color_switch_delayed_cb(lv_timer_t *timer) {
    // 切换到下一个颜色
    flashlight_color_index = (flashlight_color_index + 1) % FLASHLIGHT_COLOR_COUNT;

    lvgl_port_lock(-1);

    // 只修改颜色样式，不重建对象（资源消耗更低）
    if (flashlight_overlay) {
        lv_obj_set_style_bg_color(flashlight_overlay,
                                   lv_color_hex(flashlight_color_values[flashlight_color_index]),
                                   0);
        lv_obj_invalidate(flashlight_overlay);  // 标记对象需要重绘
    }

    lvgl_port_unlock();

    // 延迟90ms后淡入（优化v2：减少保守等待时间）
    // 理论刷新时间约30-50ms，90ms足够安全
    lv_timer_t *fade_in_timer = lv_timer_create(fade_in_delayed_cb, 90, NULL);
    lv_timer_set_repeat_count(fade_in_timer, 1);
}

// 淡入延迟回调
static void fade_in_delayed_cb(lv_timer_t *timer) {
    start_fade(false, 100);  // 淡入到100%
}

// 手电筒遮罩层事件处理
static void flashlight_overlay_event_cb(lv_event_t *e) {
    lv_event_code_t code = lv_event_get_code(e);

    // 处理点击事件：切换颜色（优化版v2：缩短等待时间）
    if (code == LV_EVENT_CLICKED) {
        // 步骤1: 立即黑屏（不淡出，直接设置0%）
        if (fade_timer) {
            lv_timer_del(fade_timer);  // 停止任何进行中的淡入淡出
            fade_timer = NULL;
        }
        pwm_set_brightness(0);  // 立即设置亮度为0

        // 步骤2: 延迟2ms后切换颜色（PWM设置是立即的，减少等待）
        lv_timer_t *switch_timer = lv_timer_create(color_switch_delayed_cb, 2, NULL);
        lv_timer_set_repeat_count(switch_timer, 1);

        // 总流程: 立即黑屏 → 切换颜色(2ms) → 等待刷新(90ms) → 淡入(8ms) ≈ 100ms
        // 用户体验: 点击 → 瞬间黑屏 → 等待 → 新颜色平滑淡入（完全无可见刷新）
    }
}

// 退出手电筒模式（外部调用）
// 注意：此函数不会恢复亮度，需要调用者在界面切换完成后手动恢复亮度
void flashlight_exit(void) {
    // 优化退出时序，避免闪烁：
    // 1. 先将亮度降到0（黑屏）
    pwm_set_brightness(0);

    // 2. 在LVGL锁保护下删除所有对象和定时器
    if (lvgl_port_lock(100)) {
        // 停止闪烁定时器
        if (flashlight_timer) {
            lv_timer_del(flashlight_timer);
            flashlight_timer = NULL;
        }

        // 停止淡入淡出定时器
        if (fade_timer) {
            lv_timer_del(fade_timer);
            fade_timer = NULL;
        }

        // 删除遮罩层（此时屏幕已黑，看不到overlay删除的过程）
        if (flashlight_overlay) {
            lv_obj_del(flashlight_overlay);
            flashlight_overlay = NULL;
        }

        lvgl_port_unlock();
    }

    // 注意：不在这里恢复亮度，避免看到ScreenSet和Home界面混合显示
    // 亮度恢复由调用者（boot_btn_handler）在界面切换完成后执行
}

// 查询手电筒是否激活
bool flashlight_is_active(void) {
    return (flashlight_overlay != NULL);
}

// 获取手电筒模式前保存的亮度值
uint8_t flashlight_get_saved_brightness(void) {
    return saved_brightness;
}

// 显示手电筒模式
static void show_flashlight(void) {
    // 如果已经显示，则不重复创建
    if (flashlight_overlay) return;

    // 保存当前亮度
    saved_brightness = pwm_get_brightness();

    // 创建全屏遮罩层
    flashlight_overlay = lv_obj_create(lv_layer_top());
    lv_obj_remove_style_all(flashlight_overlay);
    lv_obj_set_size(flashlight_overlay, LV_HOR_RES, LV_VER_RES);
    lv_obj_set_pos(flashlight_overlay, 0, 0);

    // 清除SCROLLABLE标志，添加CLICKABLE标志
    lv_obj_clear_flag(flashlight_overlay, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_add_flag(flashlight_overlay, LV_OBJ_FLAG_CLICKABLE);

    // 设置初始颜色（红色）
    flashlight_color_index = 0;
    lv_obj_set_style_bg_color(flashlight_overlay, lv_color_hex(flashlight_color_values[0]), 0);
    lv_obj_set_style_bg_opa(flashlight_overlay, LV_OPA_COVER, 0);

    // 添加事件回调
    lv_obj_add_event_cb(flashlight_overlay, flashlight_overlay_event_cb, LV_EVENT_ALL, NULL);

    // 启动闪烁定时器（500ms周期）
    flashlight_bright = true;
    flashlight_timer = lv_timer_create(flashlight_blink_timer_cb, 500, NULL);

    // 立即设置为高亮度
    pwm_set_brightness(100);
}

// ImgFlashlight点击事件：显示手电筒
static void ui_event_ImgFlashlight(lv_event_t *e) {
    lv_event_code_t code = lv_event_get_code(e);
    if (code == LV_EVENT_CLICKED) {
        show_flashlight();
    }
}

// ImgDelete 点击事件：跳转到 ScreenImg 并显示删除容器
static void ui_event_ImgDelete(lv_event_t *e) {
    lv_event_code_t code = lv_event_get_code(e);
    if (code == LV_EVENT_CLICKED) {
        // 跳转到 ScreenImg 界面
        _ui_screen_change(&ui_ScreenImg, LV_SCR_LOAD_ANIM_NONE, 0, 0, &ui_ScreenImg_screen_init);
        // 显示删除容器
        ui_ScreenImg_show_delete_container();
    }
}

// event funtions
void ui_event_ScreenSet( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);

if ( event_code == LV_EVENT_GESTURE &&  lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_TOP  ) {
lv_indev_wait_release(lv_indev_get_act());
      // 返回到之前的界面，如果没有记录则默认返回Home
      if (previous_screen && previous_screen_init) {
          _ui_screen_change(previous_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, previous_screen_init);
      } else {
          _ui_screen_change(&ui_ScreenHome, LV_SCR_LOAD_ANIM_NONE, 0, 0, &ui_ScreenHome_screen_init);
      }
}
}

void ui_event_SliderBrightness( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);lv_obj_t * target = lv_event_get_target(e);

if ( event_code == LV_EVENT_VALUE_CHANGED) {
      int32_t val = lv_slider_get_value(target);
      if (val < 10) { val = 10; lv_slider_set_value(target, 10, LV_ANIM_OFF); }
      pwm_set_brightness((uint8_t)val);
      _ui_slider_set_text_value( ui_LabelBrightness, target, "", "%");
}
}

// ImgLowPower点击事件：切换休眠模式
void ui_event_ImgLowPower( lv_event_t * e) {
    lv_event_code_t event_code = lv_event_get_code(e);
    if ( event_code == LV_EVENT_VALUE_CHANGED) {
        lv_obj_t * target = lv_event_get_target(e);
        // checked=true时显示s12(休眠模式)，false时显示s11(正常模式)
        bool checked = lv_obj_has_state(target, LV_STATE_CHECKED);
        sleep_mgr_set_enabled(checked);
    }
}

// build funtions

void ui_ScreenSet_screen_init(void)
{
ui_ScreenSet = lv_obj_create(NULL);
lv_obj_clear_flag( ui_ScreenSet, LV_OBJ_FLAG_SCROLLABLE );    /// Flags
lv_obj_set_style_bg_color(ui_ScreenSet, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_set_style_bg_opa(ui_ScreenSet, 255, LV_PART_MAIN| LV_STATE_DEFAULT);

ui_GlobalContainer = lv_obj_create(ui_ScreenSet);
lv_obj_remove_style_all(ui_GlobalContainer);
lv_obj_set_width( ui_GlobalContainer, 360);
lv_obj_set_height( ui_GlobalContainer, 360);
lv_obj_set_align( ui_GlobalContainer, LV_ALIGN_CENTER );
lv_obj_clear_flag( ui_GlobalContainer, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_ContainerTop = lv_obj_create(ui_GlobalContainer);
lv_obj_remove_style_all(ui_ContainerTop);
lv_obj_set_width( ui_ContainerTop, 240);
lv_obj_set_height( ui_ContainerTop, 80);
lv_obj_set_x( ui_ContainerTop, 0 );
lv_obj_set_y( ui_ContainerTop, -40 );
lv_obj_set_align( ui_ContainerTop, LV_ALIGN_CENTER );
lv_obj_clear_flag( ui_ContainerTop, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_ImgLowPower = lv_imgbtn_create(ui_ContainerTop);
lv_imgbtn_set_src(ui_ImgLowPower, LV_IMGBTN_STATE_RELEASED, NULL, &ui_img_s11_png, NULL);
lv_imgbtn_set_src(ui_ImgLowPower, LV_IMGBTN_STATE_PRESSED, NULL, &ui_img_s11_png, NULL);
lv_imgbtn_set_src(ui_ImgLowPower, LV_IMGBTN_STATE_DISABLED, NULL, &ui_img_s12_png, NULL);
lv_imgbtn_set_src(ui_ImgLowPower, LV_IMGBTN_STATE_CHECKED_PRESSED, NULL, &ui_img_s12_png, NULL);
lv_imgbtn_set_src(ui_ImgLowPower, LV_IMGBTN_STATE_CHECKED_RELEASED, NULL, &ui_img_s12_png, NULL);
lv_obj_set_width( ui_ImgLowPower, 64);
lv_obj_set_height( ui_ImgLowPower, 64);
lv_obj_set_x( ui_ImgLowPower, -86 );
lv_obj_set_y( ui_ImgLowPower, -1 );
lv_obj_set_align( ui_ImgLowPower, LV_ALIGN_CENTER );
lv_obj_add_flag( ui_ImgLowPower, LV_OBJ_FLAG_CHECKABLE );   /// Flags

ui_ImgFlashlight = lv_img_create(ui_ContainerTop);
lv_img_set_src(ui_ImgFlashlight, &ui_img_s9_png);
lv_obj_set_width( ui_ImgFlashlight, LV_SIZE_CONTENT);  /// 1
lv_obj_set_height( ui_ImgFlashlight, LV_SIZE_CONTENT);   /// 1
lv_obj_set_x( ui_ImgFlashlight, -2 );
lv_obj_set_y( ui_ImgFlashlight, -1 );
lv_obj_set_align( ui_ImgFlashlight, LV_ALIGN_CENTER );
lv_obj_add_flag( ui_ImgFlashlight, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_CLICKABLE );   /// Flags
lv_obj_clear_flag( ui_ImgFlashlight, LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_ImgDelete = lv_img_create(ui_ContainerTop);
lv_img_set_src(ui_ImgDelete, &ui_img_s6_png);
lv_obj_set_width( ui_ImgDelete, LV_SIZE_CONTENT);  /// 1
lv_obj_set_height( ui_ImgDelete, LV_SIZE_CONTENT);   /// 1
lv_obj_set_x( ui_ImgDelete, 82 );
lv_obj_set_y( ui_ImgDelete, -1 );
lv_obj_set_align( ui_ImgDelete, LV_ALIGN_CENTER );
lv_obj_add_flag( ui_ImgDelete, LV_OBJ_FLAG_ADV_HITTEST | LV_OBJ_FLAG_CLICKABLE );   /// Flags
lv_obj_clear_flag( ui_ImgDelete, LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_ContainerCentral = lv_obj_create(ui_GlobalContainer);
lv_obj_remove_style_all(ui_ContainerCentral);
lv_obj_set_width( ui_ContainerCentral, 230);
lv_obj_set_height( ui_ContainerCentral, 70);
lv_obj_set_x( ui_ContainerCentral, 6 );
lv_obj_set_y( ui_ContainerCentral, 44 );
lv_obj_set_align( ui_ContainerCentral, LV_ALIGN_CENTER );
lv_obj_clear_flag( ui_ContainerCentral, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_SliderBrightness = lv_slider_create(ui_ContainerCentral);
lv_slider_set_value( ui_SliderBrightness, 50, LV_ANIM_OFF);
if (lv_slider_get_mode(ui_SliderBrightness)==LV_SLIDER_MODE_RANGE ) lv_slider_set_left_value( ui_SliderBrightness, 0, LV_ANIM_OFF);
lv_obj_set_width( ui_SliderBrightness, 220);
lv_obj_set_height( ui_SliderBrightness, 60);
lv_obj_set_x( ui_SliderBrightness, -3 );
lv_obj_set_y( ui_SliderBrightness, 0 );
lv_obj_set_align( ui_SliderBrightness, LV_ALIGN_CENTER );
lv_obj_set_style_radius(ui_SliderBrightness, 50, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_set_style_bg_grad_dir(ui_SliderBrightness, LV_GRAD_DIR_NONE, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_set_style_blend_mode(ui_SliderBrightness, LV_BLEND_MODE_NORMAL, LV_PART_MAIN| LV_STATE_DEFAULT);

lv_obj_set_style_radius(ui_SliderBrightness, 0, LV_PART_INDICATOR| LV_STATE_DEFAULT);
lv_obj_set_style_bg_color(ui_SliderBrightness, lv_color_hex(0x64A8EB), LV_PART_INDICATOR | LV_STATE_DEFAULT );
lv_obj_set_style_bg_opa(ui_SliderBrightness, 255, LV_PART_INDICATOR| LV_STATE_DEFAULT);

lv_obj_set_style_bg_color(ui_SliderBrightness, lv_color_hex(0xFFFFFF), LV_PART_KNOB | LV_STATE_DEFAULT );
lv_obj_set_style_bg_opa(ui_SliderBrightness, 0, LV_PART_KNOB| LV_STATE_DEFAULT);

ui_ImgSun = lv_img_create(ui_ContainerCentral);
lv_img_set_src(ui_ImgSun, &ui_img_s10_png);
lv_obj_set_width( ui_ImgSun, LV_SIZE_CONTENT);  /// 1
lv_obj_set_height( ui_ImgSun, LV_SIZE_CONTENT);   /// 1
lv_obj_set_x( ui_ImgSun, -78 );
lv_obj_set_y( ui_ImgSun, 0 );
lv_obj_set_align( ui_ImgSun, LV_ALIGN_CENTER );
lv_obj_add_flag( ui_ImgSun, LV_OBJ_FLAG_ADV_HITTEST );   /// Flags
lv_obj_clear_flag( ui_ImgSun, LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_LabelBrightness = lv_label_create(ui_ContainerCentral);
lv_obj_set_width( ui_LabelBrightness, LV_SIZE_CONTENT);  /// 1
lv_obj_set_height( ui_LabelBrightness, LV_SIZE_CONTENT);   /// 1
lv_obj_set_x( ui_LabelBrightness, 6 );
lv_obj_set_y( ui_LabelBrightness, 0 );
lv_obj_set_align( ui_LabelBrightness, LV_ALIGN_CENTER );
lv_label_set_text(ui_LabelBrightness,"50%");
lv_obj_set_style_text_color(ui_LabelBrightness, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_set_style_text_opa(ui_LabelBrightness, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_LabelBrightness, &lv_font_montserrat_18, LV_PART_MAIN| LV_STATE_DEFAULT);

ui_ArcPowerLevel = lv_arc_create(ui_GlobalContainer);
lv_obj_set_width( ui_ArcPowerLevel, 320);
lv_obj_set_height( ui_ArcPowerLevel, 320);
lv_obj_set_align( ui_ArcPowerLevel, LV_ALIGN_CENTER );
lv_obj_clear_flag( ui_ArcPowerLevel, LV_OBJ_FLAG_CLICKABLE );    /// Flags
lv_arc_set_value(ui_ArcPowerLevel, 50);
lv_obj_set_style_arc_color(ui_ArcPowerLevel, lv_color_hex(0x39393E), LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_set_style_arc_opa(ui_ArcPowerLevel, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_set_style_arc_width(ui_ArcPowerLevel, 16, LV_PART_MAIN| LV_STATE_DEFAULT);

lv_obj_set_style_arc_color(ui_ArcPowerLevel, lv_color_hex(0x19FA29), LV_PART_INDICATOR | LV_STATE_DEFAULT );
lv_obj_set_style_arc_opa(ui_ArcPowerLevel, 255, LV_PART_INDICATOR| LV_STATE_DEFAULT);
lv_obj_set_style_arc_width(ui_ArcPowerLevel, 16, LV_PART_INDICATOR| LV_STATE_DEFAULT);

lv_obj_set_style_bg_color(ui_ArcPowerLevel, lv_color_hex(0x19FA29), LV_PART_KNOB | LV_STATE_DEFAULT );
lv_obj_set_style_bg_opa(ui_ArcPowerLevel, 255, LV_PART_KNOB| LV_STATE_DEFAULT);

ui_ImgLightning = lv_img_create(ui_GlobalContainer);
lv_img_set_src(ui_ImgLightning, &ui_img_s8_png);
lv_obj_set_width( ui_ImgLightning, LV_SIZE_CONTENT);  /// 20
lv_obj_set_height( ui_ImgLightning, LV_SIZE_CONTENT);   /// 20
lv_obj_set_x( ui_ImgLightning, -23 );
lv_obj_set_y( ui_ImgLightning, 121 );
lv_obj_set_align( ui_ImgLightning, LV_ALIGN_CENTER );
lv_obj_add_flag( ui_ImgLightning, LV_OBJ_FLAG_ADV_HITTEST );   /// Flags
lv_obj_clear_flag( ui_ImgLightning, LV_OBJ_FLAG_SCROLLABLE );    /// Flags

ui_LabelPowerLevel = lv_label_create(ui_GlobalContainer);
lv_obj_set_width( ui_LabelPowerLevel, LV_SIZE_CONTENT);  /// 1
lv_obj_set_height( ui_LabelPowerLevel, LV_SIZE_CONTENT);   /// 1
lv_obj_set_x( ui_LabelPowerLevel, 26 );
lv_obj_set_y( ui_LabelPowerLevel, 121 );
lv_obj_set_align( ui_LabelPowerLevel, LV_ALIGN_CENTER );
lv_label_set_text(ui_LabelPowerLevel,"70%");
lv_obj_set_style_text_color(ui_LabelPowerLevel, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT );
lv_obj_set_style_text_opa(ui_LabelPowerLevel, 255, LV_PART_MAIN| LV_STATE_DEFAULT);
lv_obj_set_style_text_font(ui_LabelPowerLevel, &lv_font_montserrat_20, LV_PART_MAIN| LV_STATE_DEFAULT);

lv_obj_add_event_cb(ui_ImgLowPower, ui_event_ImgLowPower, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ImgFlashlight, ui_event_ImgFlashlight, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ImgDelete, ui_event_ImgDelete, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_SliderBrightness, ui_event_SliderBrightness, LV_EVENT_ALL, NULL);
lv_obj_add_event_cb(ui_ScreenSet, ui_event_ScreenSet, LV_EVENT_ALL, NULL);

}

void ui_ScreenSet_screen_destroy(void)
{
   if (ui_ScreenSet) lv_obj_del(ui_ScreenSet);

// NULL screen variables
ui_ScreenSet= NULL;
ui_GlobalContainer= NULL;
ui_ContainerTop= NULL;
ui_ImgLowPower= NULL;
ui_ImgFlashlight= NULL;
ui_ImgDelete= NULL;
ui_ContainerCentral= NULL;
ui_SliderBrightness= NULL;
ui_ImgSun= NULL;
ui_LabelBrightness= NULL;
ui_ArcPowerLevel= NULL;
ui_ImgLightning= NULL;
ui_LabelPowerLevel= NULL;

}
