My swift wrapper proof of concept

Just a quick link to my experimental swift wrapper around LVGL. It uses an SDL simulator. Concept is to wrap objects in swift. Make a very swift like API (blocks, properties, etc).

This has wrappers right now for Screen, Theme, Style, Button, Label, and Object… Also stores self on user_data that is used in event handling and getting the current screen.

Example code in demo:

import Foundation
import LVGLSwift
 
// We need to setup callback
lv_init()
simulation_hal_init()

let theme = DarkTheme()
lv_disp_set_theme(lv_disp_get_default(), &theme.lvTheme)

let screen:Screen = Screen()
let button = Button(parent: screen)
let label = Label(parent: button);

button.center();
button.onClick(handler: { _ in
    print("was clicked")
})

label.text = "Foo"
screen.load();


while true {
    lv_task_handler()
    usleep(5 * 1000)
}
1 Like

Amazing! Glad to see that you use v8. :slight_smile:

Can I try it on Linux?

You can try. I haven’t booted up my pi running Ubuntu yet to try. Was just trying a quick proof of concept. The only change (I think) may be to the SDL path. I was going to work on getting it working this weekend.

You should be able to build now. I have fixed things up and verified it builds on Ubuntu with swift 5.4. Its a bit heavy due to runtimes and build not being optimized.

Where the project it? :slight_smile:

Sorry… Been so heads down with day job and this forgot to post the link.

1 Like

Thanks!
I’m new to swift so is there a brief guide about how to get started with it on Linux?

And is there a way to run LVGL on iOS?

I haven’t tried iOS. There would need to be a GL wrapper written for it. It definitely wouldn’t feel like a mobile app. I am doing this for an embedded project using something with a bit of ram in it. Also see if I can share some basic business logic between device, mobile, web. I have also spent so much tie in swift that c++ felt a bit chaotic (I wrote a basic wrapper there too) after being away for 10 years.

As far as getting swift to run on linux. There is a lengthy article here:

If running ARM you may need to follow these directions:

Thanks! I’ll try it out. :wink: