Editing pages with custom codes in Gui Guider

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Editing pages with custom codes in Gui Guider

跳至解决方案
2,608 次查看
frozen
Contributor III

I use Gui Guider 1.5.1 and v8.3.2 Lvgl.

I have created 2 pages and I can switch from one to another. When I switch the page and then turn back to the same page, this button we created becomes unvisible. How can I make it visible forever on that page ?


In fact I want to know how to manipulate generated files with custom codes. For example there is a screen and there is a button on that screen built with Gui Guider, how can I change this button's spesifications with custom area files ?

frozen_0-1691068552075.pngfrozen_1-1691068573702.png

/**
*custom.c file
**/
#include <stdio.h>
#include "lvgl.h"
#include "custom.h"
//#include "src/examples/lv_examples.h"

lv_obj_t *btn2;
lv_obj_t *btn;

static void btn_event_cb2(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * btn2 = lv_event_get_target(e);
    if(code == LV_EVENT_CLICKED) {
        static uint8_t cnt = 0;
        cnt++;

        /*Get the first child of the button which is the label and change its text*/
        lv_obj_t * label = lv_obj_get_child(btn2, 0);
        lv_label_set_text_fmt(label, "Button: %d", cnt);
    }
}

static void btn_event_cb(lv_event_t *event)
{
	lv_event_code_t code = lv_event_get_code(event);
	
    if(code == LV_EVENT_CLICKED)
	{
        static uint8_t cnt = 0;
        cnt++;

        /*Get the first child of the button which is the label and change its text*/
        lv_obj_t * label = lv_obj_get_child(btn, NULL);
        lv_label_set_text_fmt(label, "Button: %d", cnt);
    }
}

void lv_example_get_started_2(void)
{
    btn2 = lv_btn_create(lv_scr_act());     /*Add a button the current screen*/
    lv_obj_set_pos(btn2, 10, 10);                            /*Set its position*/
    lv_obj_set_size(btn2, 120, 50);                          /*Set its size*/
    //lv_obj_add_event(btn2, btn_event_cb2, LV_EVENT_ALL, NULL);           /*Assign a callback to the button*/

    lv_obj_t * label = lv_label_create(btn2);          /*Add a label to the button*/
    lv_label_set_text(label, "Button");                     /*Set the labels text*/
    lv_obj_center(label);
}

void lv_ex_get_started_1(void)
{
	static int btn2_no = 2;
	btn = lv_btn_create(lv_scr_act());
    
    lv_obj_set_pos(btn, 100, 100);                            /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/

	lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL,&btn2_no);
    lv_obj_t * label = lv_label_create(btn);          /*Add a label to the button*/
    lv_label_set_text(label, "Button1");                     /*Set the labels text*/
}

void custom_init(lv_ui *ui)
{
    /* Add your codes here */
	lv_ex_get_started_1();
	lv_example_get_started_2();

lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x003a57), LV_PART_MAIN);
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Hello world");
lv_obj_set_style_text_color(lv_scr_act(), lv_color_hex(0xf92f3f), LV_PART_MAIN);
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

}

 

0 项奖励
回复
1 解答
2,572 次查看
Xu_Zhang
NXP Employee
NXP Employee

Hi, frozen
I made some modifications to the code in "custom.c/custom.h", and made the button always on the display by reloading the button object in the new interface. The specific method is as follows:

1. Modify the code in "custom.c/custom.h".

Xu_Zhang_0-1691129391435.png

Xu_Zhang_1-1691129402255.png

2. Add a button control named "btn_1". Add the second page named "screen_1".

Xu_Zhang_2-1691129433715.png

3. Add two events to btn_1, namely page switching event and custom event.
The time in the page switch event is set to 0.

Xu_Zhang_3-1691129487889.png

Add header files #include "custom.h" and" lv_ex_get_started_1()" to the custom event "Edit Code"

Xu_Zhang_4-1691129535622.png

4. Generate the code again, you can see the following program in "events_init.c", and then view the effect in the emulator.

Xu_Zhang_5-1691129575488.png

 

BR

Xu Zhang

 

 

 

在原帖中查看解决方案

0 项奖励
回复
1 回复
2,573 次查看
Xu_Zhang
NXP Employee
NXP Employee

Hi, frozen
I made some modifications to the code in "custom.c/custom.h", and made the button always on the display by reloading the button object in the new interface. The specific method is as follows:

1. Modify the code in "custom.c/custom.h".

Xu_Zhang_0-1691129391435.png

Xu_Zhang_1-1691129402255.png

2. Add a button control named "btn_1". Add the second page named "screen_1".

Xu_Zhang_2-1691129433715.png

3. Add two events to btn_1, namely page switching event and custom event.
The time in the page switch event is set to 0.

Xu_Zhang_3-1691129487889.png

Add header files #include "custom.h" and" lv_ex_get_started_1()" to the custom event "Edit Code"

Xu_Zhang_4-1691129535622.png

4. Generate the code again, you can see the following program in "events_init.c", and then view the effect in the emulator.

Xu_Zhang_5-1691129575488.png

 

BR

Xu Zhang

 

 

 

0 项奖励
回复