News for hackers. Stuff that matters.
Re:CXX-Qt: Safe Rust bindings for Qt by lordofgibbons on Wednesday March 02, 2022 @06:38AM (#30526191)
Sorry if off-topic but I've seen many attempts at Qt bindings from Go and Rust. It seems all GUI libraries are more than 15 years old - except flutter, which is currently alpha quality on desktop.

As someone who has never implemented a native GUI library, what makes them so difficult to implement that we see so almost no language-native ones? Is it a matter of it not being monetizable, or something else?

Re:CXX-Qt: Safe Rust bindings for Qt by jonathanstrange on Wednesday March 02, 2022 @07:31AM (#30526605)
The hardest is to make multiline text input and rich text support. None of the smaller, home-brown GUIs gets this right. You basically have to write a complete editor that supports all languages, including Japanese, Chinese, Arabic, etc. Even native operating system text input widgets have been plagued with problems. Generally, there are tons of edge cases and special input considerations to consider in a GUI, e.g. DPI scaling, accessibility, right-to-left languages and unusual unicode glyph handling (composed glyphs), scrolling behavior & mouse handling, platform-dependent layout issues (HI guidelines), escape characters in file paths and unusual file systems, and so on and so forth.

It's quite possible to make a good GUI, just lots of mundane small issues to deal with, and it's overall a massive undertaking. It requires at least an extremely good knowledge of how different languages deal with text and input it.

Re:CXX-Qt: Safe Rust bindings for Qt by sharikous on Wednesday March 02, 2022 @08:12AM (#30526930)
Can't you just link HarfBuzz for that?
Re:CXX-Qt: Safe Rust bindings for Qt by jcelerier on Wednesday March 02, 2022 @08:24AM (#30527043)
Harfbuzz partly comes from Qt's codebase IIRC
Re:CXX-Qt: Safe Rust bindings for Qt by mwcampbell on Wednesday March 02, 2022 @01:35PM (#30530970)
harfbuzz is for text rendering, not editing. Of course, the former is a prerequisite for the latter, but text editing has plenty of its own complexity.
Re:CXX-Qt: Safe Rust bindings for Qt by jcelerier on Wednesday March 02, 2022 @07:10AM (#30526440)
Qt5's qtbase module is over 2 million LOC, and doesn't even cover QML, QtQuick, etc.

Just having proper abstractions over each platform[1]'s:

- windowing

- KB/mouse/tablet/touch input

- raster painting

- 3D APIs (Vk, D3D, GL, Metal...)

- text layout and rendering

- support for accessibility APIs

+ things such as generic data models for tables and trees, etc... is already an immense amount of work, and you haven't even started drawing a single button yet.

* https://github.com/qt/qtbase/tree/dev/src/plugins/platforms

Re:CXX-Qt: Safe Rust bindings for Qt by MaxBarraclough on Wednesday March 02, 2022 @07:49AM (#30526751)
A few more for the list:

* Internationalisation

* Concurrency, parallelism, and perhaps async (probably less of an issue with modern C++, but Qt still has plenty on offer here [0])

* Integration with various platform-specific build tools and IDEs

[0] https://doc.qt.io/qt-5/threads-technologies.html

Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @07:27AM (#30526573)
You do not need to replicate all features of Qt to make a GUI toolkit, especially since Qt tends to have a ton of stuff outside GUIs and actually has two "widgets" approaches (classic widgets and QML). For example the 3D API stuff are pointless beyond context creation, unless you use only that 3D API (instead of underlying window system functionality) to put stuff on screen.

Qt also recreates a ton of features found in C++ and if we're considering a new language, chances are the language itself has features that make Qt's unnecessary.

Re:CXX-Qt: Safe Rust bindings for Qt by jcelerier on Wednesday March 02, 2022 @07:32AM (#30526614)
Which features are you talking about ? Even in c++23 there isn't yet a way to replicate moc, rcc, uic with the same ergonomy for the end user and the same efficiency.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @07:38AM (#30526663)
I mean things like containers though in the context of a new language chances are the language itself may provide functionality that makes moc unnecessary.

Also you certainly do not need something like moc to make a GUI library, which comes back to what i originally wrote in that you do not need to replicate Qt to have a GUI library.

Re:CXX-Qt: Safe Rust bindings for Qt by ogoffart on Wednesday March 02, 2022 @08:15AM (#30526962)
"containers" was not in the list.

There sure is some overlap with what Qt offers that most language offers (Containers, Networking, Database, threading, ...). But purely in the context of making a UI library, there is still a huge amount of things that Qt offers that needs to be replicated.

Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @08:25AM (#30527052)
The post i replied to was about how big Qt is, which includes containers, etc. That the specific examples given did not contain "containers" isn't relevant since they are part of the "2 million LOC" mentioned.

Yes, you need to implement similar functionality, like abstracting the window system, input handling, text, etc but you do not need to replicate what Qt does to have a GUI toolkit.

Qt is very complex and Qt is (among others) a GUI library but Qt being complex doesn't mean that GUI libraries have to be complex.

Re:CXX-Qt: Safe Rust bindings for Qt by rob74 on Wednesday March 02, 2022 @08:47AM (#30527246)
...but, as others have noted, even if you want to only support the "core" features that most people would take for granted for a GUI (cross-platform, all the "usual" widgets including complicated ones such as RichEdit, ListView, TreeView, text with Unicode support and subpixel rendering etc. etc.) it's already a massive undertaking.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @12:05PM (#30529660)
That is another issue, yes, it is not trivial (though it isn't like making a browser or even a game engine - especially since game engines nowadays tend to have their own GUI toolkits :-P) but my point was that you do not need to replicate what Qt does to have a useful and usable library.
Re:CXX-Qt: Safe Rust bindings for Qt by jerf on Wednesday March 02, 2022 @09:07AM (#30527428)
Correct. You don't have to replicate anywhere near what Qt has to make a useful toolkit.

However, here is your experience with almost every other toolkit: Download it, compile it, build a couple test screens with it, maybe even build a couple of your production screens with it, then the inevitable disaster: You have some requirement, and you need a calendar that can highlight certain dates, or that gives you mouseevents on each individual date, or allows Jewish as well as Gregorian calendars, or that allows you to add things between the month name and the month days other than what the widget already puts there, or that... etc., for any of dozens of specialized requirements. And then you bounce off the toolkit and tell people in online discussions that you really enjoyed working with it, it was nice that it was so simple, and it has a lot of promise and you hope the developers keep working on it, but it wasn't suitable for your needs and Qt had exactly the widget you needed or at least the widget you needed had the plugin points you needed to do your job.

(In the meantime, the project stalls and dies because nobody else is using it either, but all for different reasons.)

And you hadn't even gotten a tenth of your dialogs started.

Another common one is, as people say, trying to add a rich text dialog and getting hit hard by bugs, counterintuitive behaviors, internationalization issues, etc.

Nobody uses all of what Qt offers. I can't even imagine what it would look like for a program to use literally everything it has. Even a full office suite would be pressed to do that. But everybody uses lots of different things. Put 10 Qt GUI users together and they'll use very different subsets beyond the bare basics like layouts and simple buttons.

Simply to write a binding to a GUI toolkit, ignoring all the other aspects of Qt, is itself a major project. There's been more than one Python project for it, and it is a project, generally more than one person could hope to do. To write a full toolkit that won't give people the experience above is enormous.

And that is why it is important to select your language carefully if you're writing a GUI-heavy project. You can't just pick up your favorite language and casually expect every widget you need to be available. Even if you nominally have "a binding to Qt" in your language, in my experience it's important to still double check that the binding to the widget(s) you need actually work, because anything beyond those bare basic layout, buttons, and bindings to simple widgets everybody uses is still quite possibly broken, or incompletely bound so it can't actually be used (which means nobody can have ever even tried this widget), or straight-up missing, or it's present but there's no way to correctly subclass something then make the bound widget use your subclass (in the foreign language) correctly, or something.

Nor can you just bide your time and hope a toolkit appears. They're enormous projects, even just to get one to the point that most developers don't generally hit a vital bit of missing functionality, let alone to get one full of all the features someone could reasonably want.

Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @11:57AM (#30529531)
Sorry but my experience with Qt has been neutral to negative. I can go and write a textwall about all the issues Qt has and personal experiences i had with it myself, but they're not really relevant here. Your message is basically "people stick with Qt because people stick with Qt so that is the safe bet" (aka "nobody was fired for buying IBM"). Which sure, it is true and a big reason why you do not see other toolkits much, but this doesn't really have to do with what i wrote.
Re:CXX-Qt: Safe Rust bindings for Qt by ahartmetz on Wednesday March 02, 2022 @10:11PM (#30536680)
Grandparent's point is that, in something with less functionality, you will hit missing feature X quickly, and it won't be the same missing feature as any ten random other developers. It is just your interpretation that it is, somehow, primarily about inertia or image. Joel on Software has an essay about (missing) features: https://www.joelonsoftware.com/2001/03/23/strategy-letter-iv...
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Thursday March 03, 2022 @05:51AM (#30539444)
I get that point and i disagree because it makes two assumptions:

1. That you need to replicate Qt to have the same or equivalent features for a GUI toolkit (remember that what i made explicitly that Qt is more than just a GUI toolkit) or you will not have the same features at all

2. That you will "hit" said missing feature

None of these have to do anything with making a GUI library though. #1 is especially questionable since even if you need the non-GUI functionality Qt provides, it might be something the language already has (remember that this is about other languages aside from C and C++) and/or you may even find a separate library that provides such functionality.

And yes, inertia and image does affect A LOT. People do choose projects only because of the perceived safety of those projects from being used by other people. This is why regardless of features, many people stick or flock to languages/libraries/frameworks/etc for their communities and "community" or "ecosystem" is a common concern about something new. This is something you can see often in Hacker News posts too.

Re:CXX-Qt: Safe Rust bindings for Qt by wuschelhase on Wednesday March 02, 2022 @06:54AM (#30526311)
It is an enormous effort (read investment) to get to a point of detail, where such a library becomes usable to a wide audience.

Consider a simple text input: In some languages (e.g. 'syllable based' korean Hangul) you have to compose multiple keystrokes to get to a complex letter. While you type, the last and as well as the second-to-last complex-characters might still 'trade' consonants and vowels among each other.

Now layer in more Dimensions, such as validating that input or line-wrapping, elision and many more.

To my mind, only few libraries got to this level of detail without breaking apart on complexity. It requires high maintainer stamina or massive investments.

Re:CXX-Qt: Safe Rust bindings for Qt by sho_hn on Wednesday March 02, 2022 @01:40PM (#30531033)
Most of your input example is nowadays typically handled by code outside the GUI toolkits themselves (such as the IME, the text shaping and the font stack), although the general "the GUI devil is in the details" thrust is right.
Re:CXX-Qt: Safe Rust bindings for Qt by ahartmetz on Wednesday March 02, 2022 @06:49AM (#30526271)
There is a lot of stuff there. When I think of Qt, and omitting things like QString and QIODevice / QNetwork: Text rendering, list / grid / tree views, painting primitives and not-so-primitives (e.g. dashed lines), input including multitouch, custom styling, accessibility, many miscellaneous widgets, timers and events, integration with native environment, printing - and a ton of customization points for everything.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @07:36AM (#30526648)
Beyond the "this is too hard" responses (which from personal experience working on GUIs and toolkits for decades i think are overblown), it is also that a GUI toolkit -or any other library really- written in a niche language will only be usable for that niche language's audience but a GUI toolkit -or any other library- written in a language that can be used by other languages with almost zero friction, is way more likely to be used.

And people tend to use what they see other people using, thus repeating the cycle.

So you see these 15 year old libraries being used because other people are using these 15 year old libraries because they are written in languages that can be (relatively) easily be wrapped (both C and C++ wrapping can be done automatically and there are many tools for that - largely because this is something a ton of people want to do, so again, it feeds back to the cycle of things being popular because they are popular).

But there are lots of new toolkits being made, you can even find a submission for a new one in Hacker News almost every month (though the responses are pretty much the same in all of them :-P).

Re:CXX-Qt: Safe Rust bindings for Qt by jacobr1 on Wednesday March 02, 2022 @10:47AM (#30528617)
Also note that Qt, while having a legacy of its prior versions, has seen significant investments keep it up to date. You aren't using an "old" library, you are using a modern library in its latest incarnation.
Re:CXX-Qt: Safe Rust bindings for Qt by nu11ptr on Wednesday March 02, 2022 @10:15AM (#30528263)
Assuming you are talking about Qt/wxWidgets, and I don't think they are easy to create bindings for due to being written in C++. I think they have been used because they represent the largest, most complete crossplatform codebases representing the traditional desktop GUI using either native widgets, or in Qt's case "simulated" native looking widgets.

In contrast, GTK is written in C AFAIK, and anytime a new language springs up the very first thing you generally see is a GTK wrapper. I have always suspected this is because C is far easier to wrap since most languages have a well defined C FFI, but typically lack a C++ one (due to lack of std ABI) thus Qt/wxWidgets bindings typically lag GTK.

Re:CXX-Qt: Safe Rust bindings for Qt by Macha on Wednesday March 02, 2022 @11:26AM (#30529091)
C is also a relatively simple procedural language which constrains the APIs that e.g. GTK can offer. This makes working with GTK in its native platform uglier than Qt, but does mean alternative bindings can build their own more ergonomic abstractions on top of it.

Qt on the other hand is very much a C++ OOP style, so if there's an impedance mismatch representing that in your language, as is the case for Rust, C or Go, then it gets much harder to do. The C++ bindings do present difficulty of course, but you can see from e.g. PyQT that if the pattern works in your language it's one that can be overcome.

Re:CXX-Qt: Safe Rust bindings for Qt by tialaramex on Wednesday March 02, 2022 @12:40PM (#30530148)
And there are other choices Qt makes that are unfriendly for, say, Rust too, QString is defined in terms of UTF-16 code units, which was probably a pragmatic choice when Qt was younger, but inconvenient today since of course Rust can't necessarily be confident this is actually Unicode (I tried but was unsuccessful in figuring out what CXX-Qt does about that) and on non-Windows systems Rust doesn't have a built-in representation for this "a bunch of UTF-16 code units" pseudo string, yet on Windows you probably do want that structure because it is what other Windows stuff expects such as the File APIs...
Re:CXX-Qt: Safe Rust bindings for Qt by Macha on Wednesday March 02, 2022 @01:09PM (#30530571)
Although Windows has gone backwards on that a little with the current recommendation being to use the *A APIs with a UTF-8 code page: https://docs.microsoft.com/en-us/windows/apps/design/globali...
Re:CXX-Qt: Safe Rust bindings for Qt by nu11ptr on Wednesday March 02, 2022 @12:36PM (#30530081)
This a good point, and I agree that C++ made sense at the time as it is much richer for creating a GUI. I've never tried to use GTK C GObject interface, but I've seen some snippets and it looked nasty to me. However, in hindsight, it at least makes it fairly easy to create bindings for and I suspect many (most?) don't use the GTK C API but some other language bindings, so it turned out to make a lot of sense I think.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @12:03PM (#30529622)
There are tools to create bindings for C and C++, like SWIG you can see some examples in [0], e.g. the wxWidgets bindings for Python. AFAIK for Gtk bindings can be generated using gobject introspection handling most (if not all) of the mundane bits.

[0] http://www.swig.org/projects.html

Re:CXX-Qt: Safe Rust bindings for Qt by nu11ptr on Wednesday March 02, 2022 @12:31PM (#30530011)
I'm aware and have used SWIG. It is amazing, but a) it doesn't support all languages b) it still takes a lot of work to create C++ bindings. This is primarily due to the complexity of C++ APIs vs. relative simplicity of a C-based API as another poster commented, not any shortcoming of SWIG.

So yes, there are tools, my point is it is still much easier to wrap a C based API because you can often just use your language FFI, not an external toolset.

Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Thursday March 03, 2022 @05:43AM (#30539408)
Sure, i do not disagree that wrapping C++ is harder than C, but my point was that the language is widespread and popular enough to actually have tools that assist such wrappings, unlike other languages, so even if all else were equal you are more likely to see a C or C++ library be wrapped than -say- a Free Pascal library (which can create DLL/so/etc that are 100% compatible with C and thus wrappable).
Re:CXX-Qt: Safe Rust bindings for Qt by mwcampbell on Wednesday March 02, 2022 @07:47AM (#30526730)
> from personal experience working on GUIs and toolkits for decades i think are overblown)

Accessibility and internationalization are really hard though, right?

I'm finally doing something about the accessibility issue: https://github.com/AccessKit/accesskit Still have a long way to go though.

Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @08:18AM (#30526987)
They can be among the harder parts of a toolkit (though it also depends on the toolkit's scope - can't really compare something like Qt that has a very large scope going even outside GUIs with something like imgui, which only provides the most barebones GUI functionality) yes, but i think the "hardness" exists not in how hard they are to have that functionality but in most people not even thinking about these things.
Re:CXX-Qt: Safe Rust bindings for Qt by bluGill on Wednesday March 02, 2022 @10:59AM (#30528764)
Legacy code. I've been doing QT for 10 years, I only heard of rust about 3 years ago, but the hype (particularly memory safety) has got me very interested. If I can take some existing C++ that is due for major surgery for other reasons and write it in rust I'm interested.

We know from experience that rewriting our entire system from scratch will take 5 years and cost $150million: I won't even attempt to convince management of that. Our current C++ should be good for 25 years as just C++. if we maintain it well (the major surgery mentioned above) it can last indefinitely. However replacing the current QT GUI is not on the table, it already has our themes. Maybe someday in the future it will be on the table if there is better one and it can work well (look at feel) with out current QT GUI, but for today we don't complain about QT.

Re:CXX-Qt: Safe Rust bindings for Qt by IshKebab on Wednesday March 02, 2022 @07:12AM (#30526451)
They're just really enormous libraries with a ton of tiny details you have to get right. Same reason there are so few good FOSS CAD programs or word processors. Tons of work.
Re:CXX-Qt: Safe Rust bindings for Qt by fulafel on Wednesday March 02, 2022 @07:45AM (#30526717)
There's a lot of requirements creep, the bar is high, since the estabilished stacks have had decades to build up their feature sets. Complexity multipliers include accessibility, cross-platform, gpu acceleration, complexities of text in the modern world (unicode, fancy rendering like subpixel aa, fonts, bidi...), programming language bindings, memory/lifetime management in presence of different mutually incompatible PL memory management models, native code hostile mobile platforms, etc. Leave any of those out and you start halving your potential users for each feature.

(For more specialised, niche gui toolkits the answer is that they're out there, but you've never heard of them because they don't enjoy the network effects that a wider user base gets the big toolkits)

Re:CXX-Qt: Safe Rust bindings for Qt by api on Wednesday March 02, 2022 @08:02AM (#30526847)
A high quality desktop GUI library is close to a game engine in terms of difficulty. You have to support a vast array of languages, accessibility, input paradigms, flexible layout, different screen resolutions and DPIs, styling, and so on. It's a massive undertaking.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Wednesday March 02, 2022 @12:09PM (#30529712)
Considering that some game engines tend to have their own GUI toolkits (e.g. UE4's Slate for example), you can say that it is more difficult to make a game engine than a GUI toolkit :-P.
Re:CXX-Qt: Safe Rust bindings for Qt by sho_hn on Wednesday March 02, 2022 @01:42PM (#30531056)
I'd say making a comprehensive 2D GUI toolkit is actually more complex and difficult than making a 3D game engine - even one that includes a rudimentary 2D GUI toolkit. There's an enormous long tail to 2D.

My current work is exactly at the place where those tech universes overlap and integrate.

Re:CXX-Qt: Safe Rust bindings for Qt by mwcampbell on Wednesday March 02, 2022 @01:47PM (#30531132)
Is the long tail you're talking about more in 2D rendering itself, or in accommodating the great diversity of the humans using the UI, e.g. accessibility and internationalization?
Re:CXX-Qt: Safe Rust bindings for Qt by sho_hn on Wednesday March 02, 2022 @02:01PM (#30531318)
Rendering does have a lot of interesting 2D-specific problems too that 3D engines don't optimize for (Raph Levien's blog has great stuff on this), but what the 3D engines lack is often more related to UI layout, input (e.g. sophisticated focus handling), advanced text (editing, layout, shaping).

Unity's probably been investing the most into a more complete 2D toolkit (which is their third or fourth generation of 2D UI toolkit bundled with the engine) lately. Among the FOSS game engine projects Bevy has made strong 2D suitable for UI an explicit goal. But that one true converged contender is still not even on the horizon yet, IMHO.

Re:CXX-Qt: Safe Rust bindings for Qt by api on Wednesday March 02, 2022 @05:57PM (#30534566)
Game engine toolkits usually don't have to support accessibility, right-to-left languages, full Unicode, and many other things that mature application UIs need.
Re:CXX-Qt: Safe Rust bindings for Qt by badsectoracula on Thursday March 03, 2022 @05:41AM (#30539388)
I'm not sure about RTL but AFAIK UE4's Slate does have unicode support and also seems to have accessibility support. If the tools built on Slate use that though, i don't know, but that is the same as any toolkit.
Re:CXX-Qt: Safe Rust bindings for Qt by beowulfey on Wednesday March 02, 2022 @07:35AM (#30526637)
Rust has a number of burgeoning GUI libraries. Some of them are further developed than others. I think the difficulty is just the complexity of the work. It takes a lot of effort to make a complete, functional library, and many of these are largely the work of one to a few people (probably in their spare time)!

https://www.areweguiyet.com/

The secret, I suspect, is probably "money".