dennwc / inkview

Go SDK for Pocketbook
MIT License
34 stars 5 forks source link

What's required to write a GUI App? #2

Open Skeeve opened 3 years ago

Skeeve commented 3 years ago

Hi. I do not understand how to write a GUI app for Pocketbook. Did you already do it? Do you have an example?

I think I need to include some GUI library (which one) to be able to paint windows and buttons and to react to button presses.

But as I never ever did that in any language (besides Javascript in a browser), I'm clueless here.

Do you have some guidance, please?

dennwc commented 3 years ago

Hi @Skeeve,

This library is relatively low level, as it exposes the API provided by the InkView SDK. You can check device info, get events, draw on screen, force it to refresh. But there is no complete GUI framework to use.

So you either need to try building a GUI app using those primitives (e.g. drawing lines, boxes and pixels) or we need to think which existing Golang framework can be used with this SDK.

If you want to try the first way, you will need to implement the App interface, and call Run. This will start the event loop handle by the SDK.

Events will automatically call the related callback on the interface:

    // Key is called on each key-related event.
    Key(e KeyEvent) bool
    // Pointer is called on each pointer-related event.
    Pointer(e PointerEvent) bool
    // Touch is called on each touch-related event.
    Touch(e TouchEvent) bool
    // Orientation is called each time an orientation of device changes.
    Orientation(o Orientation) bool

In the Draw callback you can use functions like DrawLine or DrawString followed by one of the screen update functions (e.g. FullUpdate). When the state of your app/UI changes, you need to call Repaint to ask SDK to call your Draw callback again.

If this is too much trouble for the app you want to build, we definitely need to explore ways to integrate with existing GUI frameworks for Go.

Skeeve commented 3 years ago

I really would prefer to "explore ways to integrate with existing GUI frameworks for Go."

I think that would be most beneficial for everyone.

dennwc commented 3 years ago

Although the most popular GUI toolkits for Go are Fyne and Gio, they both require OpenGL and shaders support in one form or another. There's also Shiny, which is partially deprecated, but allows to use simpler backends like the one we have for PocketBook.

Skeeve commented 3 years ago

Currently you see me completely clueless in regards what this is about and what's required to get it to work.

dennwc commented 3 years ago

After a chat with guys at Fyne, it seems like there is a way to make it work with this kind of renderer as well. This might take a while, though.

dennwc commented 3 years ago

I looked into it and the first step that is required is to get a direct access to PB framebuffer.

The short path is to just render to a bitmap and then draw it using Inkview API. Unfortunately I hit some issues when trying to render RGB images (it should be supported according to docs). Grayscale works, but it would require too many copy operations which may affect performance significantly (get RGB framebuffer, copy it to grayscale, copy to PB).

So I started to look into a different direction: reverse engineer the inkview.so and reimplement the parts we are care about in Go. For now it doesn't look too complicated and should give direct access to the framebuffer. But again, it might take some time.

Skeeve commented 3 years ago

Hi Denys… While looking around PB's filesystem, i notices the directory ebrmain/qml. Could it be that QT Quick is available on the device?

Skeeve commented 3 years ago

Might be interesting: "Building cross-platform Go GUIs fast using Fyne"

With the growing popularity of Go many people are asking how to build a solid GUI. The language design to target concurrency and portability makes it a great match for cross-platform development. This talk shows how the Fyne toolkit is designed to help make beautiful and idiomatic native apps with Go.

This talk explores the Fyne toolkit and what is new with the recently released version 2.0. We will explore the main features including canvas, widgets, data binding, test support and app store packaging.

We will step through how to build an application using standard widgets, data binding and storage, and then see how it can be distributed for practically all graphical operating systems and app stores.