
Cross platform GUIs and Nim macros - dom96
http://serv.peterme.net/devlog/cross-platform-guis-and-nim-macros.html
======
dom0
In 2012 I could pack a whole Python interpreter, Qt and various image-
processing libraries into an InnoSetup installer that just-so scratched the 12
MB mark; I doubt this has changed significantly.

Contrary to what the linked (more interesting) survey article suggests, Qt
_is_ usually the answer to most issues when it comes to cross-platform UI.

Gtk is not bad, but Gtk is what it is: it was created because Qt couldn't be
used for licensing concerns (at the time) by people unexperienced with the
matter (compared to the Trolltech staff), and is maintained by people who, for
the most part, care about Linux. Qt on the other hand is supported
commercially, and puts far more effort into supporting more platforms better.
[Also the tooling and docs are really nice].

~~~
vog
Side note:

Back when I did Win32 packaging of cross-platform applications, I never liked
InnoSetup much, mostly because of the many levels of unpacking into temporary
directories, but also because it was relatively slow and not as compact as it
could be. Instead, I always preferred NSIS using the makensis command.

Among others, NSIS can be compiled on *nix systems, but still produces a
Windows executable file (like a cross compiler), so you can put it in your
cross compiling toolchain. That way, you can create your full Windows port
including installer without ever having to touch a Windows.

~~~
dom0
InnoSetup was very easy to get started with and get the expected results,
while NSIS looked more complex. I'm not particularly opinionated about
installers as long as they install and uninstall things :)

------
analognoise
A better solution: FreePascal + Lazarus. Cross Platform. Native. Compiled. A
RAD tool that is tough to match.

~~~
bsder
Recommending Delphi (or something compatible like FreePascal) is not going to
win you my support.

Every Delphi-based app I have used has been a horrible bodge of bugs.

~~~
clouddrover
I think that would have more to do with the applications themselves as opposed
to anything intrinsic to Delphi. I've used plenty of applications written in
Delphi and they've worked fine. Skype for Windows was written with Delphi (and
maybe still is).

Delphi's pretty good. You should try it out:
[https://www.embarcadero.com/products/delphi](https://www.embarcadero.com/products/delphi)

------
norswap
Why does the fact that GTK "looks non-native on Windows" disqualify it? If
it's pretty enough for Linux, isn't also good enough for Windows? (Also my
personal opinion is that it doesn't look too bad.)

~~~
casion
With GUIs, consistency is the primary concern followed by 'pretty'.

Non-native breaks consistency, rendering 'pretty' fairly meaningless.

~~~
thomastjeffery
That's an absurd notion. Is chrome inconsistent because it doesn't look like a
GUI toolkit?

~~~
laumars
Yes, and it annoys the hell out of me. Even Chromium's "GTK+" theme doesn't
look right next to other GTK applications, where as Firefox does.

------
Lammy
The state of the Web in 2017: This page is nothing but text but just renders
as a blank page until you allow JavaScript

~~~
pwg
Or, until you turn off CSS (firefox: View->Page Style->No Style).

Then all the text appears, even without any JS running.

~~~
progman
Nice! Is there also a way to print the text? I just get almost empty pages.

~~~
pwg
There is a way, but it involves a bit of work (again because the author used
styles that hide everything unless the JS runs).

Save the page to disk (Firefox: File->Save Page As).

Then open the saved html file in a text editor and delete all of the <link>
tags in the <head> section that reference style sheets and save the changes.

Then open the edited html page from disk, and the result will be printable.

------
AsyncAwait
I am looking for a cross-platform GUI library that feels native across
Mac/Win/Linux and has well maintained bindings in a language that is not C++ -
an impossible task it seems.

~~~
progman
GtkAda is a binding for Ada. Ada is like Pascal but much more powerful. GTK is
available for Linux, Windows and OSX. However, you could also use Qt and
import from C++ to Ada.

[http://www.ada2012.org/](http://www.ada2012.org/)

[http://www.adacore.com/gtkada/](http://www.adacore.com/gtkada/)

[http://compgroups.net/comp.lang.ada/gtkada-for-
macos-x/14082...](http://compgroups.net/comp.lang.ada/gtkada-for-
macos-x/1408220)

[https://www.gtk.org/download/windows.php](https://www.gtk.org/download/windows.php)

~~~
AsyncAwait
That's a _very_ interesting solution. I've been curious about Ada for a long
time, but never found a reason to use it for anything - this might be it!

Thanks for bringing it to my attention.

~~~
david-given
A few years ago I did a writeup on the language.
[http://cowlark.com/2014-04-27-ada](http://cowlark.com/2014-04-27-ada)

tl;dr: there's a great deal to like about it, but its quirks are very quirky.

~~~
progman
Thanks for pointing this out. It is really good and important to know Ada's
weak points. OTOH I agree that there is a great deal to like.

------
thomastjeffery
It seems like the only real complaint this article addresses is that gtk (or
other non-native toolkits) add a ~20mb dependency, and Windows didn't have a
good package manager (since static compilation is preferred).

Frankly, this is a non issue. Windows users are used to this. It comes with
the territory. Toolkits like GTK and Qt are full featured, densely documented,
fast, look good, and work well in any OS.

------
awinter-py
took me a second to realize how important this is; my brain dismissed the
final solution as 'so what, that's just like HTML'.

then I got it -- the ability to use code generation to be declarative is
incredible.

having the ability to mix declarative (HTML / data structures) and imperative
(javascript) is what makes react so powerful. The ability to do that almost-
natively inside the language is amazing.

~~~
nikki93
Yeah I think one of the main things that React offers is a DSL for trees (JSX)
that can lexically close over and also splice in JavaScript. Languages that
allow creating your own DSLs offer this for other realms such as shader
coding, logic programming etc. within the metalanguage.

~~~
draegtun
_> Languages that allow creating your own DSLs offer this for other realms..._

Rebol & Red are examples of this, there's a GUI dialect called VID [1][2] and
in companion with this is a Draw dialect [3][4].

1\. [http://rebol.com/docs/easy-vid.html](http://rebol.com/docs/easy-vid.html)

2\. [https://doc.red-lang.org/en/vid.html](https://doc.red-
lang.org/en/vid.html)

3\. [http://www.rebol.com/docs/draw.html](http://www.rebol.com/docs/draw.html)

4\. [https://doc.red-lang.org/en/draw.html](https://doc.red-
lang.org/en/draw.html)

------
devwastaken
I've been struggling with finding a good cross-platform C#/.NET framework that
can tie into Visual Studio.

So far, you're making your entire UI in code (Like WxWidgets), having to use
an app like XamarinStudio to even get fully packaged OSX apps, along with
requiring an external framework such as
[https://github.com/picoe/Eto](https://github.com/picoe/Eto), (its official
package is broken in Xamarin though)

I understand that win forms may not be great when you start to build a bigger
application with a lot more presentation and data, but it makes building
simple apps easy and convenient. We need something like that cross-platform.

If anyone knows more about re-creating windows form apps cross-platform in a
nice manner, I'd appreciate the info.

~~~
kodablah
I don't spend much time w/ that stack, but Avalonia [1] seems to be a big
player. Even better, they recently merged .Net core support [2]. You of course
lose some native look and feel.

1 -
[https://github.com/AvaloniaUI/Avalonia](https://github.com/AvaloniaUI/Avalonia)
2 -
[https://github.com/AvaloniaUI/Avalonia/issues/314#issuecomme...](https://github.com/AvaloniaUI/Avalonia/issues/314#issuecomment-277459855)

~~~
devwastaken
What is the benefit of .net Core and how would that be used in comparison to
.net Framework 4.5?

~~~
kodablah
This may be too small of a place to explain it and I'm not completely familiar
w/ the ecosystem, but .Net core is the .Net runtime built for cross-platform
use. It doesn't have all of .Net framework, but they are adding a bit at a
time. See
[https://www.microsoft.com/net/core/platform](https://www.microsoft.com/net/core/platform)

------
MaxLeiter
Speaking of cross platform UIs, on iOS the page hijacks scrolling so you can't
scroll past the wx widget code segment.

~~~
cstrahan
I came here to comment on that as well.

I tried flicking the page right above the code fragment, but it turns out the
scroll hijacking disables iOS's native inertial scrolling, so there's no way
for me to read the rest of the article until I get back to my desktop.

I don't see the need for down-votes here: clearly many authors (in absolute
terms, if not relative terms) tease their viewers with 30 minutes of reading,
only to frustrate them by making the rest of the page inadvertently
unreachable. I would think of these kinds of comments as a courtesy to the
author.

~~~
tedmiston
I also hit this very frustrating point in the article on iOS where it became
impossible to scroll further.

------
corysama
There is a project to get IUP working on OSX.

[https://github.com/ewmailing/IupCocoa](https://github.com/ewmailing/IupCocoa)

~~~
ewmailing
And also iOS, Android, and a native web browser backend via Emscripten :)

This was a proposal/prototype/intro video for IUP for iOS & Android for the
IUP community.

[https://www.youtube.com/watch?v=UvrEfOg3Nyk](https://www.youtube.com/watch?v=UvrEfOg3Nyk)

Repos:

[https://github.com/ewmailing/IupCocoaTouch](https://github.com/ewmailing/IupCocoaTouch)

[https://github.com/ewmailing/IupAndroid](https://github.com/ewmailing/IupAndroid)

[https://github.com/ewmailing/IupEmscripten](https://github.com/ewmailing/IupEmscripten)

------
vfclists
Do most GUI toolkit whinges ever come to accept the fact that most of these
issues would go way if Trolltech/Qt/Digia/Nokia would actually bite the bullet
and create a simple C interface to the C++ that even other C++ compilers
cannot link cleanly to?

C++ and its co conspirator Javascript have done so much to hinder programming
development over the past 20 years.

Linux has been round for over and there isn't a decent opensource graphical
debugger for Linux that Visual Studio will have to step in some time in the
future. All this is soooo depressing.

------
progman
Brilliant idea! The code sample is the most clean GUI code I have ever seen.
However, I haven't coded GUI for a very long time, so it may be that there are
also other good GUI APIs which I don't know about.

Nevertheless, this DSL reveals how powerful Nim actually is. It seems many
developers have not realized it yet. With Nim they get C performance, seamless
C FFI, and a very expressive pythonic syntax. I am using Nim for years now,
and it's amazing how productive coding can be.

~~~
ndh2
> the most clean GUI code I have ever seen

That's because it doesn't actually do anything...

------
kodablah
I wish someone would pick back up wxc, the C interface for wxWidgets. IIRC the
latest updates are in the wxc folder of wxHaskell [1]. That any non-C++
language is able to somewhat "import C++" (i.e. Nim and D) is nice and all,
but doesn't really help the larger community and can be brittle in some C++
situations.

1 -
[https://github.com/wxHaskell/wxHaskell](https://github.com/wxHaskell/wxHaskell)

------
legulere
Even with cross platform toolkits you will never have apps that feel right.

The right(TM) way to do it is to write a GUI for each platform separately.

~~~
gribbly
Actually I would prefer a GUI emerging which is the same across all platforms
(except the lowest parts of the plumbing I suppose).

OpenGL would be a good candidate for rendering.

------
lappet
So I have used wxWidgets in the past with the help of python bindings and
enjoyed using it and my end product. I hear electron[1] is picking up these
days for cross-platform dev - anyone got experience with it?

[1] [https://electron.atom.io/](https://electron.atom.io/)

~~~
laumars
Only from an end user perspective and frankly I hate it. It has all the size
and performance problems complained about in that article but without the
benefit of native widgets. And frankly if I wanted to run a web app on my
desktop then I'd rather run it in my preferred browser.

I know I'm getting old (in IT terms) and grumpy but I'm unconvinced our
current frontend web stack are the right tools for modern web development;
albeit it's what we're stuck with. So I'm even less convinced that it's the
right stack for "native" desktop applications.

~~~
thomastjeffery
> It has all the size and performance problems complained about in that
> article

Complaining about electron being bloated now is just like complaining​ about
gtk being bloated back in the 90s.

~~~
laumars
To be honest I've never been a massive fan of GTK either. Then or now. Though
at least I can sympathise a little more with why GTK existed and at least GTK
is native so still had better comparable performance (ie performed better on
average hardware of that era than electron performs on average hardware of
this current era).

------
marvy
No one mentions fltk? I never used it, but is there some reason it's
unsuitable?

~~~
beagle3
FLTK is extremely lightweight and easy to use, and quite fast to boot. It
doesn't integrate very well with e.g. platform accessibility hooks and stuff
like that (but then, not many toolkits do). Highly recommended if you're using
C++.

FLTK's major problem is that it is too much of a C++ system; while wrappers
for some languages exist, a lot of the properties that make it desirable in
C++ are lost through those wrappers.

~~~
i336_
The language itself also has some serious race conditions that are impossible
to debug unless you're on really slow/embedded hardware. For example, I used
the Dillo web browser (which is FLTK-based) for a couple years when I was
stuck on an 800MHz PC, and when the system was swapping heavily, doing things
like opening the (FLTK-generated) file-save dialog or dragging a window
scrollbar (IIRC) would lock the mouse - FLTK uses X11 cursor locks to
constrain the cursor in some situations, and due to the system's heavy I/O
load, FLTK wasn't releasing the locks, and I had to kill the entire browser.

~~~
beagle3
Interesting. But why do you think this is a race condition?

~~~
i336_
Hmm. Good point; AFAIK Dillo doesn't use threading.

I'm honestly not sure what was causing it, but I know that it only happened
when the system was swapping a _lot_. So something that expected something
else to be done or take a short amount of time didn't.

For all I know it could be the way FLTK is using Xlib (I don't think it uses
XCB yet).

------
ekvintroj
This post is like a copy paste of this one:
[https://news.ycombinator.com/item?id=13952007](https://news.ycombinator.com/item?id=13952007)

------
Entangled
Why not using YAML for the UI definition? Easier, simpler and universal.

