XuNeo / luavgl

lua + lvgl = luavgl An optimized lvgl Lua binding
MIT License
57 stars 13 forks source link

Define the UI in a form similar to QML and use it to refine the official examples. #38

Closed yinntian closed 1 month ago

yinntian commented 1 month ago

Exposing the Widgets creation API directly to the global environment creates the UI in the following form.

Object{
    w = lvgl.SIZE_CONTENT, h = lvgl.SIZE_CONTENT
    Object{
        Button{
            text = "btn"
        }
    },

    Object{
        Label{
            text = "label"
        },

        Image{
            src = "img.png"
        }
    },
}

By encapsulating the creation function of each component of widgets, it intercepts the created property sheet, separates out the fields that belong to the decoration, and then provides the original property sheet to the constructor of the component. After the object has been created, it is loaded with the functions of the decorated fields. image

Only some of the popular widgets have been ported, and all of them come with sample programs. image-1

image-2

XuNeo commented 1 month ago

Thank you for such a great improvement.

It's a big PR. I have spent some time to go through the commits. Most of them are straight forward and I'd like to merge them firstly.

The most part I cannot understand for now is commit feat(ui): expose the 'widget_create_methods' API to the global enviro…, that I would like to discuss it with you further.

Would you like to separate this PR to several small ones.

For example,

These commits I think are ready to go.

yinntian commented 1 month ago

It's just a wrapper around the 'widget_create_methods' array, I just didn't want to go deep enough to break the original code in the first place.

This caused me to separate the incoming tables, one for the decorator and one for luavgl_obj_create, which is actually quite cumbersome, and the correct way to do it would be to modify the luavgl_obj_create function.

But I don't have any extra time to deal with these submissions yet

yinntian commented 1 month ago

Thanks for the fix, I changed too much code and the quality is worrying.

I was wondering if you want to split the luavgl.c file, all built in via #include "xx.c", I think it's more difficult for coding and maintenance.

I think there should be two options

  1. put everything in "luavgl.h", don't allow #include for other luavgl parts, make a header-only library.
  2. take a multi-file form, the traditional way, I can provide the corresponding xmake build script. If you need cmake and makefile, xmake can generate them directly.
XuNeo commented 1 month ago

Thanks for the fix, I changed too much code and the quality is worrying.

This single PR is too large to be safely merged. If you are busy, I can help to prepare several PRs.

I was wondering if you want to split the luavgl.c file, all built in via #include "xx.c", I think it's more difficult for coding and maintenance.

I know that looks different. That's the style luv uses and thus followed when I learn lua tricks.

I can provide the corresponding xmake build script. If you need cmake and makefile, xmake can generate them directly.

Let's do it!