How to design a platform-independent UI framework?
https://news.ycombinator.com/item?id=41388995I've been working on a hobby project, a UI framework, much like QT, SwiftUI, UIKit, WPF and alike, in my spare time. I haven't planned to do it professionally and it is not meant to become one, it is just for my personal experimentation.
Currently it is on a very early stage and I'm developing it under Windows, but it is meant to be multiplatform. So the backend for rendering could be skia, vulkan, directx etc. The language I'm developing it, C++, is not much relevant for my questions.
The responsibility of handling all UI controls or widgets is mine and it abstracts from the host-native Window. Once the hierarchy of UI widgets are built and rendered, what is left, is the interaction with the user.
The problem I'm facing now is how to handle the mouse, keyboard, touch, hover, capture, focus events, how to bubble them up, and how to design the UI widgets hierarchy to handle all of them in a clean way. The solution I came up with is not clean and that rings a bell in my mind that something is not right.
Beside the host (or platform dependent) window, at the top I have a Window class that handle all the widgets in a parent-child way relationship (a three) and then I have widget class for the default cases. Every other UI controls derive from the widget class.
Furthermore, there will be widgets that have visual appearance, as well as widgets that helps laying out other widgets but not necessarily do they have a visual representation. So subdividing classes, in my case in C++, is fundamental to avoid repeating code and to have a clean scalable architecture.
I gave a look at other open source projects but I couldn't find any simplified one. Chromium, for example that is used in web apps, is huge one and it would take a while before I could even find what is responsible for what. Firefox I feel is at the same level.
Are there any documentation or open source projects to have look at?
Thanks