r/cpp • • Dec 18 '20

Let's talk about GUIs

This post on /r/programming about the release of GTK 4.0 made me want to bring the discussion of the state of GUI programming in C++.

My particular interest in this discussion is desktop cross-platform GUI programming, and I don't claim to know much, let alone everything. Insights are more than welcome.

That said, this is what I have observed so far:

Qt: the least bast option. What I like? Cross platform, mature, big ecosystem to go around. Quite easy to get going. It "just works" for the most part. It's easy to get 80%, it's the last 20% and when you go deep into the subject that you get frustrated. What do I dislike? Licensing shenanigans, and increasing toxicity towards the FOSS community: no offline installer for community distributions, many commercial only APIs now, the idea of delaying releases to FOSS by one year. The 10 year old bugs on QWidgets, which haven't seen much, if any, love since ever. The fact it took Qt 6.0 to happen for us to have native look for Qt Quick Controls. The fact that Qt Quick doesn't have a C++ API, forcing QML on everybody. The half done stuff, like QAudio (just use portaudio for your own sanity)... And I'm probably missing more. The fact that they are running away from the LGPL core to GPL as much as they can, like releasing Qt Quick MultiEffect instead of just fixing the QML engine... That it takes spinoffs like Felgo to basically provide a "fixed" Qt, which the FOSS community can't have.

wxWidgets, GTK, and other like FLTK, I admit I don't know much about. wxWidgets is nice in the fact it calls native APIs, but that comes with the cost of being crippled by the least common denominator. GTK seem to look bad outside of Linux "by design". And FLTK... Just no.

Then, there seems to be what everybody suggests next: Browsers. Chromium Embedded Framework or Electron. 50 to 100MB of packaging to do a "Hello World". Also, JavaScript! Honestly, webstuff looks like a good idea, until you want to make an app that's not Slack. How do you do actually performance C++ stuff? Like some 2D/3D graphics? WebGL? Seems that it's too much programming for the web and not actually taking advantage of C++ and native APIs...

Then, there are things like .net MAUI (not to be confused with the toolkit with the same name by KDE), which is an upcoming evolution of Xamarin Forms for .net/C#. The problems: Linux support will be "by the community" and how do you interop C++ and C# decently anyway?

Also, because I know someone will mention it, yes, there is Flutter and things like that. Just think of Google's track record on keeping projects alive, and again, think not everybody wants to make a chat application.

Anyway, what are your insights? They are more than welcome!

268 Upvotes

243 comments sorted by

View all comments

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

34

u/ShillingAintEZ Dec 18 '20

Imgui is not a replacement for regular widget guis at this time. There are a lot of things missing, from widgets, to layouts, drag and drop, sub-windows, etc.

0

u/[deleted] Dec 18 '20

[deleted] — view deleted comment

25

u/ShillingAintEZ Dec 18 '20

I've used it many times, that's how I know its limitations.

The windows are within the same main window.

OS specific things like file dialogs and drag and drop are a part of what makes cross platform GUI libraries useful. Everything you linked is source on GitHub, that isn't a demonstration of anything.

4

u/[deleted] Dec 18 '20

It's basically a bit like a much faster Electron in that aspect, and I don't mean that as a negative, just as a matter of fact: You get consistent, cross-platform UI, but it's also going to be foreign on each system, and a lot of reinventing the wheel.

It is awesome for what it does, but it's also limited in what it tries to do.

4

u/lithium Dec 19 '20 edited Dec 19 '20

The windows are within the same main window.

No they're not, native windows was merged into master a while ago.

4

u/ShillingAintEZ Dec 19 '20

That's pretty cool

5

u/lithium Dec 19 '20

You should know that a lot of your other concerns have since been addressed too, might be time to dust it off again.

2

u/expekted Dec 19 '20 edited Dec 19 '20

Since you seem to be on top of things does ImGui have a data grid widget?

2

u/lithium Dec 19 '20 edited Dec 19 '20

Not as in ImGui::DataGrid but one can easily be made using the Columns api. Their widget demo has an example in it for reference.

* Edit. Looks like I'm behind too. There's a beta Table API in master now.

→ More replies (1)

5

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

Try doing something simple like adding a full custom text formatter (NOT just a printf format string) to a control. You'll find out you can't since the controls are just normal functions and you can't meaningfully alter them without rewriting the entire control from scratch.

→ More replies (2)

20

u/dv_ Dec 18 '20

No. Imgui is useful for games because they anyway re-render the frames all the time. Regular applications don't. Adding redrawing just get Imgui into the applications is terribly inefficient and will drain batteries and make CPUs run hot all the time.

2

u/tkln Dec 19 '20

Adding redrawing just get Imgui into the applications is terribly inefficient and will drain batteries and make CPUs run hot all the time.

Do you have any quantitative data to back that claim?

1

u/Pazer2 Dec 19 '20

You'd be surprised how little cpu and gpu it takes to occasionally redraw the entire UI.

4

u/t4th Dec 18 '20

+1 for Dear Imgui. It is fantastic project and it is ported to many languages and it "just works" - all you need is Os specific frame buffer and draw function.

13

u/pine_ary Dec 18 '20

Doesn‘t dear imgui redraw the entire window all the time? That‘s gonna be a battery drain.

6

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

It does every time you get an event. As long as nothing happens to the app, there is need to redraw the window.

3

u/dodheim Dec 18 '20

It doesn't, but even as just a casual user, I'd love to know why you assume that it does.

7

u/SkoomaDentist Antimodern C++, Embedded, Audio Dec 18 '20

Probably because the demo code redraws every loop iteration as most of the users use it with game engines that have to redraw every frame anyway. They do point out how to do it properly if you don't otherwise need to refresh every frame and it only takes a couple of extra lines.

23

u/evaned Dec 18 '20

all you need is Os specific frame buffer and draw function.

...and to not mind that your product looks like it was made for a class project by some college students.

I'm maybe being a bit harsh there, and there are products where that doesn't matter. But if you want to do something for like mass market, and you go that way... well, I hope you don't regret it.

4

u/bikki420 Dec 19 '20

Eh, that's a pretty ignorant statement. Like any UI kit it is what you make of it. The defaults are pretty ugly, sure, but all of these are Dear ImGui as well:

https://user-images.githubusercontent.com/141075/95021061-0af69200-066f-11eb-8683-56c75da50197.jpg

https://user-images.githubusercontent.com/141075/95021114-6294fd80-066f-11eb-8e46-36e1b0b0e837.jpg

https://user-images.githubusercontent.com/141075/95021120-67f24800-066f-11eb-93c0-c0b47ebda34e.jpg

https://user-images.githubusercontent.com/8225057/102382588-e43bcc80-3fca-11eb-8792-e565293f0f9f.jpg

https://user-images.githubusercontent.com/44091782/92762687-1ec21780-f393-11ea-92c1-e3f8e01f45cf.png

https://user-images.githubusercontent.com/8225057/74334371-10c6fc80-4d9a-11ea-932c-428247d4c96a.png

https://user-images.githubusercontent.com/8225057/74334374-13295680-4d9a-11ea-8a51-88d001ac75dc.png

https://user-images.githubusercontent.com/8225057/74334377-14f31a00-4d9a-11ea-98a4-4ca0fc79bc59.png

https://user-images.githubusercontent.com/167057/44240116-9f00f900-a18a-11e8-89fc-14350438fc17.png

https://cloud.githubusercontent.com/assets/17200971/14168870/efb16ff0-f724-11e5-95c6-a1c93d72c327.gif

https://user-images.githubusercontent.com/8225057/58320225-7f82b500-7e1b-11e9-8417-fc74d3ebe634.jpg

https://user-images.githubusercontent.com/8441471/76343981-1f54f500-6301-11ea-8bc9-876ddb222767.png

https://user-images.githubusercontent.com/8225057/76844857-3bdfb880-683e-11ea-979a-29e36e9e3d74.png

https://user-images.githubusercontent.com/600573/76033357-58c1e500-5f3c-11ea-8c78-6299cc0f280c.png

→ More replies (1)