/*
 * Copyright 2022 NXP
 * SPDX-License-Identifier: MIT
 * The auto-generated can only be used on NXP devices
 */

#include "lvgl.h"
#include <stdio.h>
#include "gui_guider.h"
#include "events_init.h"
#include "custom.h"
#include "usart.h"

static lv_obj_t * g_kb;
static void kb_event_cb(lv_event_t *e)
{
	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_t *kb = lv_event_get_target(e);
	if(code == LV_EVENT_READY || code == LV_EVENT_CANCEL){
		lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
	}
}
static void ta_event_cb(lv_event_t *e)
{

	lv_event_code_t code = lv_event_get_code(e);
	lv_obj_t *ta = lv_event_get_target(e);
	lv_obj_t *kb = lv_event_get_user_data(e);
	if (code == LV_EVENT_FOCUSED)
	{
		lv_keyboard_set_textarea(kb, ta);
		lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN);
	}
	if (code == LV_EVENT_DEFOCUSED)
	{
		lv_keyboard_set_textarea(kb, NULL);
		lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN);
		 //printf("%s\r\n",lv_textarea_get_text(ta));
	}
}

void setup_scr_screen3(lv_ui *ui){

	//Write codes screen3
	ui->screen3 = lv_obj_create(NULL);

	//Write style state: LV_STATE_DEFAULT for style_screen3_main_main_default
	static lv_style_t style_screen3_main_main_default;
	if (style_screen3_main_main_default.prop_cnt > 1)
		lv_style_reset(&style_screen3_main_main_default);
	else
		lv_style_init(&style_screen3_main_main_default);
	lv_style_set_bg_color(&style_screen3_main_main_default, lv_color_make(0xff, 0xff, 0xff));
	lv_style_set_bg_opa(&style_screen3_main_main_default, 0);
	lv_obj_add_style(ui->screen3, &style_screen3_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write codes screen3_imgbtn_1
	ui->screen3_imgbtn_1 = lv_imgbtn_create(ui->screen3);
	lv_obj_set_pos(ui->screen3_imgbtn_1, 5, 6);
	lv_obj_set_size(ui->screen3_imgbtn_1, 32, 27);

	//Write style state: LV_STATE_DEFAULT for style_screen3_imgbtn_1_main_main_default
	static lv_style_t style_screen3_imgbtn_1_main_main_default;
	if (style_screen3_imgbtn_1_main_main_default.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_1_main_main_default);
	else
		lv_style_init(&style_screen3_imgbtn_1_main_main_default);
	lv_style_set_text_color(&style_screen3_imgbtn_1_main_main_default, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor(&style_screen3_imgbtn_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_1_main_main_default, 0);
	lv_style_set_img_opa(&style_screen3_imgbtn_1_main_main_default, 255);
	lv_obj_add_style(ui->screen3_imgbtn_1, &style_screen3_imgbtn_1_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write style state: LV_STATE_PRESSED for style_screen3_imgbtn_1_main_main_pressed
	static lv_style_t style_screen3_imgbtn_1_main_main_pressed;
	if (style_screen3_imgbtn_1_main_main_pressed.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_1_main_main_pressed);
	else
		lv_style_init(&style_screen3_imgbtn_1_main_main_pressed);
	lv_style_set_text_color(&style_screen3_imgbtn_1_main_main_pressed, lv_color_make(0xFF, 0x33, 0xFF));
	lv_style_set_img_recolor(&style_screen3_imgbtn_1_main_main_pressed, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_1_main_main_pressed, 0);
	lv_obj_add_style(ui->screen3_imgbtn_1, &style_screen3_imgbtn_1_main_main_pressed, LV_PART_MAIN|LV_STATE_PRESSED);

	//Write style state: LV_STATE_CHECKED for style_screen3_imgbtn_1_main_main_checked
	static lv_style_t style_screen3_imgbtn_1_main_main_checked;
	if (style_screen3_imgbtn_1_main_main_checked.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_1_main_main_checked);
	else
		lv_style_init(&style_screen3_imgbtn_1_main_main_checked);
	lv_style_set_text_color(&style_screen3_imgbtn_1_main_main_checked, lv_color_make(0xFF, 0x33, 0xFF));
	lv_style_set_img_recolor(&style_screen3_imgbtn_1_main_main_checked, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_1_main_main_checked, 0);
	lv_obj_add_style(ui->screen3_imgbtn_1, &style_screen3_imgbtn_1_main_main_checked, LV_PART_MAIN|LV_STATE_CHECKED);
	lv_imgbtn_set_src(ui->screen3_imgbtn_1, LV_IMGBTN_STATE_RELEASED, NULL, &_return_alpha_32x27, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_1, LV_IMGBTN_STATE_PRESSED, NULL, &_set_blue_alpha_32x27, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_1, LV_IMGBTN_STATE_CHECKED_RELEASED, NULL, &_return_alpha_32x27, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_1, LV_IMGBTN_STATE_CHECKED_PRESSED, NULL, &_set_blue_alpha_32x27, NULL);
	lv_obj_add_flag(ui->screen3_imgbtn_1, LV_OBJ_FLAG_CHECKABLE);

	//Write codes screen3_imgbtn_2
	ui->screen3_imgbtn_2 = lv_imgbtn_create(ui->screen3);
	lv_obj_set_pos(ui->screen3_imgbtn_2, 102, 4);
	lv_obj_set_size(ui->screen3_imgbtn_2, 100, 50);

	//Write style state: LV_STATE_DEFAULT for style_screen3_imgbtn_2_main_main_default
	static lv_style_t style_screen3_imgbtn_2_main_main_default;
	if (style_screen3_imgbtn_2_main_main_default.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_2_main_main_default);
	else
		lv_style_init(&style_screen3_imgbtn_2_main_main_default);
	lv_style_set_text_color(&style_screen3_imgbtn_2_main_main_default, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor(&style_screen3_imgbtn_2_main_main_default, lv_color_make(0xff, 0xff, 0xff));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_2_main_main_default, 0);
	lv_style_set_img_opa(&style_screen3_imgbtn_2_main_main_default, 255);
	lv_obj_add_style(ui->screen3_imgbtn_2, &style_screen3_imgbtn_2_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write style state: LV_STATE_PRESSED for style_screen3_imgbtn_2_main_main_pressed
	static lv_style_t style_screen3_imgbtn_2_main_main_pressed;
	if (style_screen3_imgbtn_2_main_main_pressed.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_2_main_main_pressed);
	else
		lv_style_init(&style_screen3_imgbtn_2_main_main_pressed);
	lv_style_set_text_color(&style_screen3_imgbtn_2_main_main_pressed, lv_color_make(0xFF, 0x33, 0xFF));
	lv_style_set_img_recolor(&style_screen3_imgbtn_2_main_main_pressed, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_2_main_main_pressed, 0);
	lv_obj_add_style(ui->screen3_imgbtn_2, &style_screen3_imgbtn_2_main_main_pressed, LV_PART_MAIN|LV_STATE_PRESSED);

	//Write style state: LV_STATE_CHECKED for style_screen3_imgbtn_2_main_main_checked
	static lv_style_t style_screen3_imgbtn_2_main_main_checked;
	if (style_screen3_imgbtn_2_main_main_checked.prop_cnt > 1)
		lv_style_reset(&style_screen3_imgbtn_2_main_main_checked);
	else
		lv_style_init(&style_screen3_imgbtn_2_main_main_checked);
	lv_style_set_text_color(&style_screen3_imgbtn_2_main_main_checked, lv_color_make(0xFF, 0x33, 0xFF));
	lv_style_set_img_recolor(&style_screen3_imgbtn_2_main_main_checked, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_img_recolor_opa(&style_screen3_imgbtn_2_main_main_checked, 0);
	lv_obj_add_style(ui->screen3_imgbtn_2, &style_screen3_imgbtn_2_main_main_checked, LV_PART_MAIN|LV_STATE_CHECKED);
	lv_imgbtn_set_src(ui->screen3_imgbtn_2, LV_IMGBTN_STATE_RELEASED, NULL, &_hed_alpha_100x50, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_2, LV_IMGBTN_STATE_PRESSED, NULL, &_head_alpha_100x50, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_2, LV_IMGBTN_STATE_CHECKED_RELEASED, NULL, &_hed_alpha_100x50, NULL);
	lv_imgbtn_set_src(ui->screen3_imgbtn_2, LV_IMGBTN_STATE_CHECKED_PRESSED, NULL, &_head_alpha_100x50, NULL);
	lv_obj_add_flag(ui->screen3_imgbtn_2, LV_OBJ_FLAG_CHECKABLE);

	//Write codes screen3_ta_1
	ui->screen3_ta_1 = lv_textarea_create(ui->screen3);
	lv_obj_set_pos(ui->screen3_ta_1, 62, 62);
	lv_obj_set_size(ui->screen3_ta_1, 200, 22);

	//Write style state: LV_STATE_DEFAULT for style_screen3_ta_1_main_main_default
	static lv_style_t style_screen3_ta_1_main_main_default;
	if (style_screen3_ta_1_main_main_default.prop_cnt > 1)
		lv_style_reset(&style_screen3_ta_1_main_main_default);
	else
		lv_style_init(&style_screen3_ta_1_main_main_default);
	lv_style_set_radius(&style_screen3_ta_1_main_main_default, 4);
	lv_style_set_bg_color(&style_screen3_ta_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
	lv_style_set_bg_grad_color(&style_screen3_ta_1_main_main_default, lv_color_make(0xff, 0xff, 0xff));
	lv_style_set_bg_grad_dir(&style_screen3_ta_1_main_main_default, LV_GRAD_DIR_VER);
	lv_style_set_bg_opa(&style_screen3_ta_1_main_main_default, 255);
	lv_style_set_border_color(&style_screen3_ta_1_main_main_default, lv_color_make(0xe6, 0xe6, 0xe6));
	lv_style_set_border_width(&style_screen3_ta_1_main_main_default, 2);
	lv_style_set_text_color(&style_screen3_ta_1_main_main_default, lv_color_make(0x00, 0x00, 0x00));
	lv_style_set_text_font(&style_screen3_ta_1_main_main_default, &lv_font_arial_12);
	lv_style_set_text_letter_space(&style_screen3_ta_1_main_main_default, 2);
	lv_style_set_text_align(&style_screen3_ta_1_main_main_default, LV_TEXT_ALIGN_LEFT);
	lv_style_set_pad_left(&style_screen3_ta_1_main_main_default, 2);
	lv_style_set_pad_right(&style_screen3_ta_1_main_main_default, 2);
	lv_style_set_pad_top(&style_screen3_ta_1_main_main_default, 2);
	lv_style_set_pad_bottom(&style_screen3_ta_1_main_main_default, 2);
	lv_obj_add_style(ui->screen3_ta_1, &style_screen3_ta_1_main_main_default, LV_PART_MAIN|LV_STATE_DEFAULT);

	//Write style state: LV_STATE_DEFAULT for style_screen3_ta_1_main_scrollbar_default
	static lv_style_t style_screen3_ta_1_main_scrollbar_default;
	if (style_screen3_ta_1_main_scrollbar_default.prop_cnt > 1)
		lv_style_reset(&style_screen3_ta_1_main_scrollbar_default);
	else
		lv_style_init(&style_screen3_ta_1_main_scrollbar_default);
	lv_style_set_radius(&style_screen3_ta_1_main_scrollbar_default, 0);
	lv_style_set_bg_color(&style_screen3_ta_1_main_scrollbar_default, lv_color_make(0x21, 0x95, 0xf6));
	lv_style_set_bg_grad_color(&style_screen3_ta_1_main_scrollbar_default, lv_color_make(0x21, 0x95, 0xf6));
	lv_style_set_bg_grad_dir(&style_screen3_ta_1_main_scrollbar_default, LV_GRAD_DIR_VER);
	lv_style_set_bg_opa(&style_screen3_ta_1_main_scrollbar_default, 255);
	lv_obj_add_style(ui->screen3_ta_1, &style_screen3_ta_1_main_scrollbar_default, LV_PART_SCROLLBAR|LV_STATE_DEFAULT);
	//lv_textarea_set_text(ui->screen3_ta_1,"number：");
	if (g_kb == NULL)
	{
		g_kb = lv_keyboard_create(ui->screen3);
		lv_obj_add_event_cb(g_kb, kb_event_cb, LV_EVENT_ALL, NULL);
		lv_obj_add_flag(g_kb, LV_OBJ_FLAG_HIDDEN);
	}
	lv_keyboard_set_textarea(g_kb, ui->screen3_ta_1);
	lv_obj_add_event_cb(ui->screen3_ta_1, ta_event_cb, LV_EVENT_ALL, g_kb);

	//Init events for screen
	events_init_screen3(ui);
}