Nice to have:
Are there some existing API that could be a starting point ? What should be the next move, in your opinion?
It should be compiled to a DLL
Oh?
- Multi-threading ready with clear rules what can be done in a background thread and what not and how to communicate between threads.
I think the lib should just have a boolean inBackgroundThread: bool parameter for those backgroundable proc. For UI most thing should be main thread for responsiveness.
- This can imply that it works well on embedded devices, but also and more importantly that it can be used in security critical applications.
Are there even GUIs that are cleared for mission-critical applications?
Nice to have:
- If you only work with the very high level APIs and restrict yourself to certain widgets, make it so that it supports a textmode UI as well.
If I were to write a UI library, given how hard and time-consuming it is to wrote UI libs, I would instead start with text first, especially because most people using Nim in productions are using it for CLI-based tools.
Once those are made very appealing, upgrade to GUI.
There is a lot to do with text-based UI already, status-bar, progress-bars, see https://github.com/Textualize/rich which IMO is the based console UI, and certainly the one with best docs, I've seen.
Isn't Fidget quite close to this?
I've come to believe that the most challenging piece with a custom GUI is text input. Even more so than text rendering! Well at least since Treeform did much of the hard work on fonts. :)
For text input you need to handle shortcuts, different alphabets, left-to-right, repeating inputs, etc. I believe it'd be worth considering reusing OS native text input, and I believe it's what browsers do (did?).
Well speaking of browsers, supporting a (sane) subset of html rendering would be an interesting approach: https://sciter.com/ :P Actually I always did think sciter was pretty impressive demonstration of what one person could do if focused. The author said it took him about 9 months of full time work.
Both approaches are mutually exclusive and require a separated code. Even a general concept how a GUI library works is separated for both ways.
I don't agree. It's mostly the existing distinction between peekEvent vs waitForEvent.
It is usually done via canvas widget. So that widget is needed. And this mean just abilities to drawing in the library.
Yes, but there is a difference between "here is a canvas widget" and "every widget was built on top of this canvas and so should be yours".
zooming UIs
looks kind of like interactive((animated) svg + map server) + leaflet
Other backends (software renderer, NanoVG in Nim (no wrapper - like femtoVG in Rust), Nim native driver, ...) can follow when the FW has a good usability and some widgets are available. The developer can decide which backend to use for special hardware. I think there is a lot of other work to create a multitreaded Render-Tree, low-memory consumtion,
Building multi-threaded renderer honestly isn't too hard IMHO. Just convert your UI/widget tree into a set of more primitive non-ref objects to put them into a sequence to send to the render thread to avoid allocations. Especially when you build on others actual GPU renderer's!
The renderer runs super fast. The front end is another matter. Things like tables + re-draws can get expensive and slow.
The pattern of making simple render nodes to send to the renderer also makes it pretty easy to port the front-end to alternative rendering backends. I've been wanting to try porting Figuro to NanoVG or similar so I can try it an a raspberry pi or even esp32. Partly I'm curious what it'd take to run a nice UI on an ESP32 :-)
solid/responsive event-management, handling of dirty components, layout-system, composition and innovative extention API for creation of custom components and widgets in pure Nim, no DSL. I think Nims syntax offers a good declarative style.
Those are harder parts. Many of these UI systems have built these up over many years. New UI's like SiftUI's struggle with these for years despite having enormous companies like Apple behind them. Flutter UI apparently struggled for years with text input box refresh performance on many platforms, etc.
You can get pretty basic UI elements up pretty quickly, the fine polish is harder. Handling font styling, theming, etc are all tricky. I found aspects like default colors or sizes for widgets to be tricky. How do you override them efficiently from a user context, etc.
IMHO, many of these pieces can be handled by separate libraries. Layout systems can in theory work with most any widget system or event system.
I gave libagar a spin with futhark. Works great.
This is the hello world example from their docs.
import futhark, strutils
importc:
path "/usr/include/agar"
"agar/core.h"
"agar/gui.h"
{.passl: "-lag_core -lag_gui".}
assert 0 == AgInitCore(nil, 0)
assert 0 == AgInitGraphics("")
var window = AgWindowNew(0)
let label = AgLabelNew(window, 0, "Hello, World!")
AgWindowShow(window)
assert 0 == AgEventLoopProc()
# libagar install cmd for Arch Linux, adapt to your OS
$ pakku -S agar
# futhark runs into a compiler limit, work around with loop iterations
$ nim c --maxLoopIterationsVM:100000000 agar.nim
$ ./agar
Et voila, a window.
That was a lot easier than I thought.
Now I wonder if libagar is any good! Looks comprehensive for sure.
I dont care for subpixel polaristion
Please do!
If you mean subpixel rendering/aliasing/hinting (= aliasing using colors, not just gray tones), the absence of it lets fonts look blurry. Example in the below Image (part of a bug report).
Please do!
Nah, that's like GPU support. Once you have widgets and portability and it working on 80% of the platforms that Nim runs on, you can care about subpixels and GPUs.