andlabs / libui

Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Other
10.73k stars 615 forks source link

C-compliant React-like syntax proposal for libui #293

Open zheksoon opened 6 years ago

zheksoon commented 6 years ago

Hi,

This is a proof-of-concept syntax for making UI programming with libui more declarative. I don't really have any experience with this library, but looking at some example apps I imagined a React-like syntax for the library that is still C-complaint.

Here's a gist of control gallery example implemented with this hypothetical syntax: https://gist.github.com/zheksoon/5ed91f694397a73f10aa882affa637d3

Does it make sense to develop it more? Will it help someone?

Thanks!

PS Actually, there is a real React bindings to libui using libui-node, you can see how the real React syntax looks like: https://github.com/parro-it/react-libui

andlabs commented 6 years ago

This kind of thing I've seen typically called "declarative", and my stance on the subject is: it's possible to build these declarative APIs on top of non-declarative ones, but NOT the other way around. (There's a reason I can't use the Windows Ribbon Framework in libui.)

That being said, I'm not sure if I want to prescribe a specific style of doing this. But I also don't want to make doing so impossible, so I guess try something and see what works?

zheksoon commented 6 years ago

For sure I'm not forcing this to be included in libui by any means, just asking if community finds it interesting.

it's possible to build these declarative APIs on top of non-declarative ones, but NOT the other way around.

Yes, exactly - this is what the React binding does (but from some unclosed issues it looks like there might be some problems with dynamic checkboxes, maybe more).

Josemboa commented 6 years ago

I think it could be great to have something like that, including for Go (https://github.com/andlabs/ui). There is now something we can test: Photon-native (https://github.com/kusti8/proton-native), but it uses Node.js.

mardukbp commented 6 years ago

Great idea! It seems that Nim is the way to go. See Cross-platform GUIs and Nim macros.

mardukbp commented 6 years ago

Also, you could get some inspiration from Red and Rebol. See Red GUI system.

wasamasa commented 6 years ago

I implemented a SXML interface with Scheme that desugars into creating and linking the widgets. It's kind of like JSX, but the Lisp way of doing it.

https://github.com/wasamasa/libui/blob/master/examples/hello-world/hello-world.scm https://github.com/wasamasa/libui/commit/3dc40348d35fb9649e010b4e9207efc5da8a021d