How to Modify Custom.c file ?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to Modify Custom.c file ?

Jump to solution
2,834 Views
frozen
Contributor III

Hello,

I use Gui Guider 1.5.1 and v8.3.2 Lvgl . I want to see something on the screen with my own coded files/objects but I don't know how.

For example, I want to add button with label example. Here this is link and the code piece is below. Could you tell me how to add this code to custom.c/custom.h file and see the result on my screen ?

#include "../../lv_examples.h"

static void btn_event_cb(lv_obj_t * btn, lv_event_t event)
{
    if(event == 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);
    }
}

/**
 * Create a button with a label and react on Click event.
 */
void lv_ex_get_started_1(void)
{
    lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL);     /*Add a button the current screen*/
    lv_obj_set_pos(btn, 10, 10);                            /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                          /*Set its size*/
    lv_obj_set_event_cb(btn, btn_event_cb);                 /*Assign a callback to the button*/

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

 

0 Kudos
Reply
1 Solution
2,771 Views
Xu_Zhang
NXP Employee
NXP Employee

You can try to unadd "lv_obj_t *btn" in the "gui_guider.h" file earlier, you can add "lv_obj_t *btn" in "custom.c", then save the project and see the effect in the emulator.

Xu_Zhang_0-1690943513743.pngXu_Zhang_1-1690943536083.png

Note that "guider_ui.btn" was replaced by "btn" in the previous program.

Xu Zhang

View solution in original post

4 Replies
2,807 Views
Xu_Zhang
NXP Employee
NXP Employee

Hi, frozen

I made some modifications to the code you provided, added it to custom.c, and displayed some contents on the display screen. On the display screen, the button label can be automatically added by clicking the created button. The specific method is as follows:

1、Add the modified code in custom.c

Xu_Zhang_0-1690872282349.png

2、Add lv_obj_t * btn to thelv_ui‘” structure of the gui_guider.hfile.

Xu_Zhang_1-1690872312283.png

3、compile and download the code, the effect is as follows.

BR

 

Xu Zhang

0 Kudos
Reply
2,792 Views
frozen
Contributor III

Hi Xu_Zhang 

Thanks for your directives. I stuck in 2nd step, I do not have a development kit yet, that's why I work on just gui guider with Simulator. When I add lv_obj_t * btn" and then compile it, the file is regenerated and I get compile time error about there is no object as btn. How can I pass this subject ?

0 Kudos
Reply
2,772 Views
Xu_Zhang
NXP Employee
NXP Employee

You can try to unadd "lv_obj_t *btn" in the "gui_guider.h" file earlier, you can add "lv_obj_t *btn" in "custom.c", then save the project and see the effect in the emulator.

Xu_Zhang_0-1690943513743.pngXu_Zhang_1-1690943536083.png

Note that "guider_ui.btn" was replaced by "btn" in the previous program.

Xu Zhang

2,740 Views
frozen
Contributor III

Thank you, it works !! I have one more question related to this topic, 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 ?

0 Kudos
Reply