I would love to see something like the Flutter Engine[1] written in Rust, which is a layer tree that runs in an OpenGL context and includes text rendering, shape drawing, gesture recognition, scroll layers, a layout engine, etc. – all components necessary for modern mobile app development.
Rust has dynamic dispatch, by using trait objects (https://doc.rust-lang.org/book/trait-objects.html). It also has something similar to interface inheritance ("trait Foo: Bar" means that everything that implements the trait Foo must also implement the trait Bar), and one can always do "C-style inheritance" (have the parent be the first field of the child) for structs.
Given that, I'd say building a large, complex GUI framework in Rust is possible. I also wonder how a GUI framework written for Rust (instead of Rust bindings to a framework for another language) would look like.
WebRender and Servo together contain all of these.
It's certainly no coincidence that the top contributors to the Flutter engine are all Chromium contributors.
also, the fact that it is one letter away from my name was confusing at first :P
After the initial bumps and scratches getting used to rust, I've found the experience to be better overall than I remember it being back in the day with C++ and Qt. I actually ended up implementing my own tiny version of signals and slots as I remembered them from Qt to handle interactions between the user and the stuff on the back end (mostly sqlite at this point). That in combination with a certain relaxed attitude about using Rc<RefCell<_>> for GUI stuff has put me in a place where I'm pretty confident that any normal GUI operation is pretty straightforward with rust.
The amount of boilerplate code seems pretty similar between the two. I think that a GUI framework specifically designed for rust might actually be a big win over other options here, but so far there isn't one that I know of that meets my needs. As it is, using the GTK components from rust is easier than using them from C (in my opinion), and comparable with my memory of using Qt in C++.
I've also found that the type system and the error handling are great compared to what I used before. They help not only in catching problems, but also in ensuring that the design is complete before I get too far into it. The code I'm writing now is much more reliable in terms of handling errors and covering corner cases than what I did back then in c++/qt. There is a price for this upfront in terms of aligning your mental model with what rust wants, especially if you're coming from the same background I was. Once that is done I don't think it's any more difficult to get stuff done here than it was there, and the results seem to be quite a bit more robust.
It wasn't all good times though - the initial unlearning/relearning curve was pretty rough for me. I've been programming professionally in various languages for about 15 years, and rust has taken longer for me to get comfortable with than any other language. That's including a wide variety of languages from various paradigms including constraint/logic programming (prolog and ciao), functional (lisp, ocaml, haskell, etc.), imperative (python,ruby,c/c++,javascript) and other more obscure ones. Something about the familiar features of algebraic data types, pattern matching, and type inference combined with the strict memory model caused a lot of mental interference that took me a long time to sort out.
The build system is actually one of the biggest reasons I stuck with rust through the pain of getting started. I really love cargo, to the point now that I can't stand the thought of going back to makefiles, cmake, or any other C++ build system I've tried. Cargo seems to just work, which means I spend less time fighting with obscure linker and compiler flags and more time getting things done. I'd put up with a lot from the language just to keep the build system, to be honest.
Overall developing a GUI app in rust has been a decent experience. If you're already comfortable with the language, I'd recommend spending the time to learn the GTK bindings. Once you internalize their basic operating scheme, the time required to get GUI stuff done with rust is comparable to other languages and toolkits, but you get the peculiar combination of benefits that come from using rust itself.
We're still trying to get this to work with Windows. I've been reporting on this issue here: https://github.com/White-Oak/qml-rust/issues/31.
Any suggestions to get this going would be appreciated! Developing with Rust/QML on Windows definitely seems possible at this point...that said, most of what's left to be defined is what setup is required to actually get things to work.
after `brew install qt5`, I had to `brew linkapps qt5` & `brew link --force qt5`. Then `ln -s /usr/local/opt/qt5/mkspecs /usr/local/mkspecs && ln -s /usr/local/opt/qt5/plugins /usr/local/plugins` which is super not ideal.
I had some error and ran `brew install doxygen --with-qt5` which may not be necessary, but after these steps it built.
Edit: scratch that. As soon as I try the example in main.rs, it fails to build again. 'ld: framework not found QtCore'
After adding the clang_64/bin dir on the $PATH I too am getting 'ld: framework not found QtCore'.
Anyone able to suggest where I'm going wrong?
At least the frontend stack with the largest deployment—HTML, CSS, and JS—has a garbage collector and is memory safe. With C#/VB.NET on Windows, Swift on Mac/iOS, and Java on Android ascendant, this is now obviously the way to go. Imagine if we had permanently made the mistake of saddling the Web with manual, error-prone memory management.
But also the point is that the Qt runtime would be part of the browser, which is usually all C++ or Rust or whatever anyway - not the web programmer's responsibility.
What makes me sad is that Qt for a very long time has had a very well thought out ways of handling the complexities of UIs, including separating view from layout from business logic, doing layouts properly, they even have a pretty and lightweight DSL for defining UIs, which you can then style with a CSS-ish language. And a non-terrible UI builder on top of that. It even does responsive UIs these days! Granted, how well this would handle something as complex as current webapps is an interesting question, but they've always kept up with the changes, no problem.
Also they did proper threads and event loops, data storage and query APIs, serialization, networking and sockets, highly performant 2D and 3D graphics (GPU-accelerated stuff!), an embedded browser, and all this was (and is) all cross-platform! It really was miraculous magic that we had this circa 2005-2007, and it's frustrating to see bits and pieces of this just recently getting web standards. If in this day and age I see one more proposal for how to do javascript promises or Commonjs / AMD / ES6 modules or something I'm going to die of frustration and exhaustion. :-(
I see the main proposition of QT/QML in providing a framework that is not tied to a particular platform. The main thing that comes close are browser engines, but many people will find their huge footprints too large for using them for embedded applications (or partly even standalone desktop apps).
The browser is an atrocious, non-sensical platform that was invented to display Hypertext, not to run apps. Now look what we got? 5 new JS frameworks per month, because of some minuscule, often fabricated productivity gain. Various competing improvements to make CSS somehow manageable and an untyped, arcane and hard to optimize language on top of it. And we still struggle to make decent looking and performing apps. It's stupid.
Sounds like WebAssembly :)
HTML + CSS + JS are just barely not shitty, but have such widespread adoption and libraries. Web apps are just so easy to package and maintain.
extern crate sciter;
fn main() {
let mut frame = sciter::Window::new();
frame.load_file("minimal.htm");
frame.run_app();
}
Result: https://camo.githubusercontent.com/b7d9438384930801ba15d027d...Rust/Sciter integration: https://github.com/sciter-sdk/rust-sciter
HTML UI at the end is just a set of few simple concepts (at least with Sciter):
1. UI is a composition of just two universal components: Element and Node (text, comment, etc).
2. UI is a single rooted tree of such blocks - DOM tree.
3. The tree can be styled by well known CSS means.
4. Events are delivered to particular UI elements using bubbling/sinking event propagation schema.
5. Any DOM Element may have so called behavior assigned to it. The behavior is either native (C/C++/Rust/Go/etc) or script function. All <input> elements are normal DOM elements with corresponding behaviors attached.
I do not see how this simple setup can be an antithesis to anything.
or PyQt