373 points · by avitex · 10y ago · 182 comments
As far as I understand from the source code, libui is a thin C wrapper that makes calls to each platform native ui framework. For instance, to create a window on OSX it calls the corresponding Cocoa function, for Linux the corresponding GTK function, etc. So, unlike Qt and GTK which are heavy cross-platform libraries because they can "draw" their own widgets themselves, this library seems to just call other functions. In that sense, the resulting widgets are as native as they can be!
Qt, Gtk and others are from those old days when everyone wanted alternatives to native frameworks that could "draw" their own widgets. That is why Qt and GTK are/were useful to build the native desktop frameworks of Linuxes.. In these modern times that everyone has moved to Web, things on the desktop-land are far more stable and it is common agreement that Cocoa is perfectly fine for Mac, Win32 is perfectly fine for Windows and GTK is perfectly fine for Linux. This is great news, so now it is the best time to make thin wrappers around these stable things so that we can all go make useful software..
As for the why C and not anything else, is just that all these UI native frameworks can be easily called from C, and C is the common denominator of other higher level languages. So, in theory, each programming language that can interface with C (99.9% of them can) can call the functions of this libui. This means that, in theory, we can all start building 100% native desktop applications in our favorite languages with a lightweight library.. Now I'm off to start pylibui.. ;)
Hoping not to start any kind of framework quarrel, but my understanding was that quite many applications (such as Wireshark, Subsurface, and OpenShot) are moving from GTK to Qt very much due to Qt being more stable. Or is the main reason cross-platform compatibility?
My standards for quality on the desktop are way higher than what the "web" is supposed to give you today. It must be fast, consistent, and don't have any glitch.
The looks are a secondary point (and GTK 2 engines, or Qt4 for the matter) already give you great customization possibilities, which are way beyond what most other systems can do already.
GTK 3 and QML (Qt5) would like to target the same space as web applications. It doesn't make sense. Applications which are written with a web UI in mind will translate very poorly on the desktop, and the opposite is also true. My experience with QML was abysmal, and definitely not worth the extra dependency. Maybe you think that you button must be big and fat and have extra space to be tapped on-to, but on a desktop this is all wasted space on the screen that I want to use for data.
GTK 3 is trying to innovate a bit on the UI front, but many of the changes come with usability regressions on the desktop which I don't find acceptable anymore. Overlay scrollbars are a good example. In principle, they're a great idea. However the implementation is riddled of bugs which makes using scrollbars with a mouse a pain.
The CSS theming is nice, but they keep breaking the styles at each minor release. It's also incredibly slow. Whereas GTK+ and QML aim for rendering in a GL context, the reality is that if you want predictable performance they're going to be useless anyway.
QML is not targeting the same space as web applications. Its a more flexible and dynamic way of creating user interfaces. Its designed so you can create UIs for kiosks, infotainment systems, mobile applications, games, and desktops all with one toolkit. QML has components specifically for desktop development that have the same look as your traditional forms based widgets.
This is simply not true.
We are closer to hitting 60 fps (or whatever your EDID actually presents) than ever before, and staying locked to that. The more complex of an interface you create, the harder that is, but that is no different today than ever before. Work is underway doing something similar to the webrender concepts which will improve render times even further.
I'm not sure what you mean by visual consistency, other than we create new widgets as designers ask for them. Just because applications choose to use something other than say a GtkComboBox for everything is hardly our fault. I welcome a future where application developers can decide what UI concepts work for them.
That doesn't mean you can't use deprecated widgets. This is no different than any other platform. We experiment with new ideas, keep what works well, and deprecate what doesn't based on feedback and user testing. GTK+ is one of the few libraries that generally stays ABI stable for a decade, so deprecated is more of an indicator than "this will be removed next month" like developers are used to with web APIs.
> GTK 3 and QML (Qt5) would like to target the same space as web applications. It doesn't make sense. Applications which are written with a web UI in mind will translate very poorly on the desktop, and the opposite is also true. My experience with QML was abysmal, and definitely not worth the extra dependency. Maybe you think that you button must be big and fat and have extra space to be tapped on-to, but on a desktop this is all wasted space on the screen that I want to use for data.
Where do you get your information? Because they seem to be fairly miss-informed.
GTK+ is most definitely not trying to be a web application toolkit. The "big buttons" are that size because people have all sorts of accessibility needs different from your own. Or you're on HiDPI and we don't have 1.5x scaling (yet) as it requires more plumbing in the compositor to do 3x scaling in the toolkit and 2x downscaling (and input transformations) in the compositor. I hope to see this before long.
Personally, I'd like to see a "condensed" theme variant of sorts. Finally, thanks to all the CSS node work in 3.20, you can pretty much get that with a couple CSS lines.
> The CSS theming is nice, but they keep breaking the styles at each minor release. It's also incredibly slow. Whereas GTK+ and QML aim for rendering in a GL context, the reality is that if you want predictable performance they're going to be useless anyway.
It's no secret to GTK+ developers that the theming API was always sort of a gray area. As of 3.20 the theming API, for the first time in nearly 18 years, is considered stable.
GTK+ does not render with GL today. (There is integration to embed GL into the scene, though). That might land for 3.22, but it's a lot of work and I would not be surprised if it doesn't make it until 3.24 as it's part of the drain-the-swap redesign of the drawing model. Presumably vulkan will be supported too.
As someone who would like to create a commercial application for desktop, I really appreciate that at least the UI frameworks for Windows and OSX are quite stable.
Was surprised to hear that even Linus got sick of dealing with GTK and ported Subsurface to Qt, but that's how it is.
Yes, GTK+ has lots of quirks and I curse it on a regular basis, but so do Qt and all other toolkits I know of. And yes using Qt for Subsurface instead of GTK+ was a good idea, since Windows and OS X ports benefit a lot from that, but if Dirk and Linus were responsible for the Qt interface, it probably would have been just as bad as the GTK+ one.
I have, however, seen compositors that hit buggy mesa llvmpipe paths corrupt the visual output on the way to the GPU. But that would have happened to Qt as well unless you ran the Qt app on a non-composited desktop (which wouldn't really be an apples-to-apples comparison).
That said, I haven't programmed a UI in about 5 years, so this might be completely outdated.
This library seems to be implemented in C so that higher level languages can make use of it. C is much simpler to interface than C++. For instance, you mention WxWidgets, but that thing is so god-damn complex that there's still no stable WxPython for pyhton 3..
I really hope that this libui stays as just a simple simple thin wrapper so that we can build complex things no top of it in each language. For instance, python guys may create a declarative framework on top of this while lisp/haskell guys may create a Functional Reactive "thing" on top of it. As long as libui stays simple enough, everyone can extended it in ways that make sense for their own languages..
I did a project last year where I wanted to use SWT, but I wanted to write the program in Python, and use CPython rather than Jython so I could have access to C extension modules like lxml. So I hacked up a solution using the Avian lightweight JVM and the pyjnius JNI-based Python/JVM bridge from the Kivy project. I should release that sometime.
But if you want a complex and powerful UI toolkit (let's say you want to create an editor), you need a toolkit like Qt. You can't do that with just wrappers to native toolkits. You will only get the greatest common divisor.
I'm definitely going to try to implement a python wrapper around this as it seems usable enough as it is now.. :)
Electron is seen as a great thing because it allows web developers to finally come back to desktop. But what about we guys that learned how to build products directly for the desktop? We do not need Electron. We may need a web view to render something on it, but not Electron specifically.
Finally, as someone trying to build something to sell, I do not want the same GUI on all platforms, I just want something that looks native in each platform (not giant web buttons, for instance) and that allows me to share many components of a codebase.
I'm hoping that a native UI toolkit that can be used via FFI from nearly any language might take a chunk out of the Web-as-application-delivery-platform mindset.
I don't blame anyone for making non-native apps with Electron and HTML5, because it's so difficult to make them work on every platform. But here's to hoping someone finally got it right, and that native applications can take back some ground.
Death to the battery-eaters and memory-fillers. Let the OS do the heavy lifting.
Still, let's hope that libui does great --- it's already quite a feat to have the basic window controls working the same on three different platforms.
That 90% constitutes a lingua franca.
Not knocking the nice UI/UX folks - they work their corner, I work mine, and it's nice to have a technology to bridge schedules. My observation is that that 10% consumes as much as 1000% of the schedule at times :)
In my experience, the story of using a layered UI like this is that for a short while you use it, then customers start asking for features it cannot deliver and you start writing platform-specific code, then after a while the portable code is a minority. At some point there's a meeting in which someone points out that a particular platform is 90% of the value and wouldn't it be better to make do with just that 90%? Are these other platforms really worth the effort?
What's old is eventually new again.
If it should be faster with CSS, why isn't it? In fact, I develop a web app. What am I doing wrong?
In addition to all the standard controls, it's also got OpenGL and browser embedding since before Electron was cool.
Using it on the JVM is very easy, but there was a short-lived attempt to maintain a C++ API.
- How it looks: https://www.eclipse.org/swt/
- From Jython: https://github.com/danathughes/jythonSWT
- From JRuby: https://github.com/neelance/swt4ruby
- From C++ (defunct): http://www.pure-native.com/
It's built out of small chunks of C code: https://github.com/eclipse/eclipse.platform.swt/search?p=1&q... that are wrapped in a Java API with a straightforward coding style that seems amenable to automatic source translation. And it doesn't need GC - it actually requires the Java programmer to manually dispose resources, which is easy because it always requires objects to have a parent, so everything goes away when the pane / window / whatever gets disposed.
Reminds me of a quote by Joe Armstrong, creator of Erlang, on OO programming:
"You wanted a banana but what you got was a gorilla holding the banana and the entire jungle."
However, as others have pointed out, this will be very useful for many other languages as well. I would love to see a Renaissance of native cross platform apps.
I only use web applications when there isn't a native alternative that I can make use of.
Actually I moved back to the world of native applications and there is plenty of work.
Along similar lines, I have been using the MOAI environment, with the Hanappe GUI framework, to deliver apps across every platform you can port MOAI too, sort of .. fulfilling .. the once-jaunted "write once, run anywhere" dream, while also giving me a usable UI environment for the modern world.. ship bytecode/Lua files, run the same code everywhere (the MOAI client lives).
Seriously, worth an hour or so of lab-bench time, if one is considering the prospect of having an app/run-time equilibrium, albeit with a modicum of effort:
http://github.com/moai/ http://github.com/makotok/Hanappe http://github.com/makotok/Flower
(Flower is another branch, similar concept: build your entire UI as a mini-lib, bring it with you everywhere you need it...)
Things like atom inherit js etc. which gains a little bit of speed up and familiarity, but also performance overheads and complexity.
Not actually good, js-devs are the worst for a kind of NIH and low cross-pollination. Sometimes, a string custom and/or C-API is the nest for bringing in multiple communities.
Works with Windows, Mac OS, Linux, iOS and Android.
Strangely, juce seems to have a revamped website that has no pictures or screenshots of the juce user interface and its widgets. Weird. Not sure how effective that marketing is...
I hate this website. I feel like I'm looking at a Medium post, stuff is popping around as I scroll, hero carousel, unclear Metro-style tiles that turn black and disappear the text on mouse-over, the works. Spent way too much time trying to figure out where the API docs and examples were hidden.
Gimme a screenshot of something built with it, a snippet of a Hello World, tell me where it runs, point me to the docs, and point me to a download.
I can't use scrolling pictures of people looking at code(!), I'm not about to watch a keynote, I don't want a "developer story", I don't want links to "companies using"! I shouldn't need to click twice to get to "features," that ought to be the first thing I see!
The remainder might well be useful for some audiences, and as jumping-off point to get a sense of the ecosystem and community around the software, but put it at least a little bit below the fold.
Here's what Sensei Jeff has to say about that: https://blog.codinghorror.com/if-it-looks-corporate-change-i...
That said I do not know of any cross platform library in C, so this does seem to fill a niche.
Why? Release early and get feedback. Backward compatibility isn't holy. And it's just an alpha. No one expects the api to be stable.
The best hope so far is probably what's described in this email: http://lua-users.org/lists/lua-l/2016-03/msg00019.html
In past I've used Java/SWT and C#/WinForms. Both of those come with a concept of the UI thread, which is the thread which you should use to read from and write to the UI.
What I don't understand about these multiplatform libraries is: do they also provide this mechanism, or are they actually only responsible for drawing the widgets and forms, leaving to the developer (and the guest language they are using to leverage the library) to implement that part through threads or some different pattern (i.e. reactor pattern)?
What's the difference between libui and libsdl? The latter is also in C and supports many platforms. For large applications I may just use QT and for some embedded GUI I can use libsdl, what's the goal for libui?
SDL really shines in simple cross-platform abstractions - window creation, basic rendering, input handling, threading, timers, basic audio, platform-agnostic file handling, etc. The older version (1.2) also had extensions for fonts, networking, and some other things, but I'm not sure if that applies for 2.0. Beats the snot out of messing with Win32 for getting started with game programming.
The way I understood it, libui is a widget toolkit (e.g. GTK, wxWidgets, Qt, etc) -- while SDL is low-level library to handle drawing, input (i.e. you'd need to implement your own widgets using the low-level primitives that are available to you).
So you get a box you can draw in, and that's it. Then you're allowed to poke pixels until you get what you want. It's not that you're poking a lower level (which would be akin to directly blitting to the screen buffer like an old-timey OS), it's that you're poking a different level (creating a new context and performing operations on it, via GDI+ or OpenGL or whatever). You trade one set of primitives for another.
GUI Widgets are a higher level of abstraction on top of pixels. SDL gives you pixels or an OpenGL context which gives you a slightly abstracted way of rendering pixels.
Overall it was an easier and more productive development experience for me.
It didn't went through for the simple reason: set of common widgets in GUI OSes is quite small: buttons, editboxes, selects and that is it. What about menus, toolbars, treeviews/virtual lists, etc. etc. ?
So yes, you can do with that common set something extremely simple like alert() or prompt() in browsers. But nothing close to full scale applications.
Yet graphic primitives... GDI on Windows does not know anything about alpha channel or anti-aliasing... But CoreGraphics does. What would be the common set in this case?
Again, idea of reusing OS widgets and native platform's look and feel in multiplatform GUI toolkits is a perpetual dream of programmers since initial version of Bible was written. wxWidgets or SWT are such examples.
But event they failed to achieve one of their primary goal - native platform's look and feel. Does anyone know any wxWidget or SWT application that look native on, say, OSX ?
So if you are designing application of "one red button 'Start'" then this approach will work of course. But even in that case ... how to create really red button in OSX? Or on Windows? You will want something custom drawn... but you haven't common graphic primitives and so on.
Atom is slow and chromium a resource hog, but these are limitations of the current implementations, not inherent to the technologies themselves. A Servo-based UI toolkit with well thought out DOM bindings could solve both of these problems spectacularly.
But I'm glad this exists and I'm excited to see a light cross platform UI library that works across multiple OSes and languages. I'll probably use this for my future native UI needs.
> We have no intention to cover full CSS1/CSS2 attibute map.
Yeah that's not gonna work out for many projects.
WPF is native on Windows, Win32/WinForms is also native on Windows. I'm assuming it uses Win32, although a third party FFI to WPF would be very, very nice.
WinForms/Win32 is the first UI platform that Windows supported. It's getting less used because of the new UI platforms.
I don't really understand how do they define WPF, UWP, XAML and DirectUI now or how do they compare. XAML was the language used behind WPF but it seems they have changed the terms.
The start menu in Windows 10 was created in XAML: https://news.ycombinator.com/item?id=9968679
Edit: Found this: https://news.ycombinator.com/item?id=11498366
If you only have a button and a text field and want to make stuff happen when the button is clicked, then I doubt there is any difference in whether it uses Win32 or WPF.
Documentation
Needs to be written. Consult ui.h and the examples for details for now.
:(Another reason is that the underlying tools used by this library are likely in C as well, so it's probably the easiest language to use for the task.
- huge binaries (or dependencies)
- slow compiles
- slow runtime
- garbage collection
- non-portability
- C++ (I just don't like it)
...pretty much every popular language other than C falls into one or more of the above.
Yeah, I know I'm fussy.
Anyhow, I used to be the same way (perhaps surprisingly given what I work on now), but I stopped once I realized that it just takes so long to do basic things in C compared to other languages. The downside of slow compilation, for example, pales in comparison to the downside of it taking a lot more code to do basic things like string manipulation.
I'd also mention that, on Windows, C has big dependencies as well (msvcrt), unless you cheat like MinGW does and use the unsupported system msvcrt.
I'm really quite conflicted here. I've written in the past that it can even be seen as irresponsible to write new security-sensitive programs in C/C++ when there are reasonable alternatives available, which is most of the time - and "security-sensitive" can include almost anything, given the right scenario. On the other hand, while I'm a big fan of Rust and use it for some personal projects, some things about it drive me crazy, while C's low-level nature appeals to me, so I also like to use C. I can justify this contradiction to myself easily enough, because I don't write all that much code that other people actually use, but that's something I'd like to change... :( In any case, I'm looking forward to quality-of-life improvements in Rust such as incremental compilation, which should tilt the balance more onto its side.
libui is mainly intended for FFI use with Go.
Writing GUI apps in C is a pain in the ass, yes.
And they actually consider using this library.
There has been a lot of negativity/arguments against C here lately, which in my opinion has been very exaggerated.
Seriously, how often do you guys write GUI apps that _also need to be secure_? An application isn't secure just because you write it in another language, there's a lot more work to it. If there is even such a thing as secure.
If you communicate over a Network with not fully trusted remote endpoints, and handle text you have a fair chance of remote code execution in C. A git front end. A text editor. Anything written in C has a fair chance to making a mistake.
Your very basic attitude is an example to the problem the industry is having!
We will always make mistakes, no matter how hard we try, but not caring for such an important topic from upstart is a not simply a mistake, but an outright sin!
Security, robustness are some examples which are way too hard to add to a software when not taken into account upfront at design time!
C is not the right tool for these tasks.
I stand by my point. Simply "not using C" isn't magically going to make your application so much more secure.
2) Some things very much need to never be on a wider network with untrusted nodes. This is easier than it sounds...
Microsoft tried this idea out and it didn't work a few years back but it still seems to me that a browser based OS UI would be far more effective than things like Gnome and KDE and all that stuff.
Edit: well I guess Google had the same idea long ago and called it ChromeOS - browser as OS interface.
Here's the really funny thing though, if you just think about it for a second:
Whether browsers become as powerful as operating systems, or operating systems become as convenient (for users and developers) as browsers,
The end result will be exactly the same.
Yep. Consider how we use browsers vs. native apps right now:
- I can open a browser and say type twitter.com and get the exact same experience on ANY device, right away, along with all my data. This is good.
or
- IF a native app is available, I have to download it first, and then, I just have to launch that app directly every time I want to use it. I get a far more responsive UI, better integration into the rest of the operating system, and the native app can support more offline capability than it could if it was running in a browser. This is good too.
Now obviously what browsers are missing is the UI responsiveness, efficient hardware performance, and OS integration.
What native apps are missing is the convenience of typing in a web address, and they're more difficult for developers to provide the same experience on every OS.
Where we stand right now, it will take WAY more work to get web apps on the same level as native apps. Lots of wheels to reinvent.
It will take far less work to make the discoverability and acquisition of native apps as convenient as typing in a web address. So why not work towards that instead?
> It will take far less work to make the discoverability and acquisition of native apps as convenient as typing in a web address.
I don't see that as the case at all. The UI libraries are just the tip of the iceberg.
In fact, I think CSS is better suited to hardware acceleration with modern GPUs than these native libraries, which date back to the '90s, are. That's because they're declarative instead of based on imperative systems like GDI that were designed for rendering on old CPUs.
Other than the initial discovery/download delay for native apps, the web apps currently have no advantage over the native versions.
If people could instantly start using a native app just by typing say "Facebook" what reason would they have to go into their browser? Does anyone currently even do that? Go back to the website after they've installed the app?
In a browser menus are not like that. Normally they're imitated with CSS: a JavaScript or even a CSS selector swaps CSS classes from visible to invisible. There's no support for real menu behavior; you either have to do this all by yourself (probably pre-build the menu offscreen to measure it and then decide where to place it) or give up and use sub-par menus-like imitations And this is the only glitch here; there's lots of them (submenu behavior, shortcuts, behavior of text fields, etc.) In the standard GUI these things are implemented for you and polished long time ago; in browsers they simply do not exist.
And CSS is not that good even as a high-level layout engine.
They shine especially on collaboration and sharing functionalities.
You can do 3D editing on the web, at least in a fairly basic way.
Why?
> it still seems to me that a browser based OS UI would be far more effective than things like Gnome and KDE and all that stuff.
How so? My needs haven't changed. I still need a UI that provides a searchable launch menu, some quick-launch buttons, window management, etc. Rendering a bunch of things through a browser doesn't do that for me any better than rendering those things through some C libraries.
Still, taken as a given: Linux desktop design could use some work. Or at least the themes and icon sets.
Because somehow websites end up (can end up) looking great, but all those Linux desktops look shit. Things don't line up, the margins and spacing are wrong. It looks like it's made from a set of ill fitting phony knockoff lego bits that don't fit together.
If web browsers make it possible to design slick interfaces then the Linux desktop folks should get onto that quick smart.
Having said that, I guess that's what ChromeOS is eh?
To me, the web is for goofing off. It's where I'll read an article, post some comments somewhere, and leave. The desktop's where I get things done. I like Mate's interface (ditched Gnome at 3.x because I didn't like the new direction). KDE isn't terrible, but I feel like it gets in my way a little bit more.
> It looks like it's made from a set of ill fitting phony knockoff lego bits that don't fit together.
I remember when I would've described Linux desktops like that (about 15 years ago). You can still replicate that if you get too creative with your choice of themes and such, but I haven't found it distracting to what I use my computers for in....well, close to the last decade. Then again, I'm not a designer, so I tend not to notice or be bothered by some things that'd throw others into fits.
> Having said that, I guess that's what ChromeOS is eh?
It's neutered Linux. It's pretty enough, I suppose.