D GUI Toolkit Comparison

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 29 12:50:02 PDT 2016


On Friday, 29 April 2016 at 13:52:59 UTC, Nordlöw wrote:
> Could somebody briefly outline the different GUI toolkits 
> available in D and how they differ especially in terms of 
> cleverly the make use of all idioms available in the language 
> aswell as in Phobos.
>
> For instance: DlangUI and Adams D Ruppe's `simpledisplay`

https://wiki.dlang.org/GUI_Libraries

I'm the author of Tkd[1] and wrote it to learn D in more depth 
and really enjoyed the flexibility of generic 
classes/functions/interfaces and mixins. Because Tkd is based on 
Tcl/Tk it was really hard to map the Tcl language and Tk toolkit 
to a sensible type hierarchy using inheritance. Using D gave me 
the opportunity to think a bit differently and compose types more 
simply while modeling the problem in a more intelligent way. I'm 
bias, but I love the simplicity of the finished code.

A pattern I used throughout was this:

     class Foo : Bar
     {
         public auto baz(this T)(...)
         {
             ...
             return cast(T) this;
         }
     }

Which allows chaining of methods with those of parent and child 
types, i.e:


import tkd.tkdapplication;

     class Application : TkdApplication
     {
         private void exitCommand(CommandArgs args)
         {
             this.exit();
         }

         override protected void initInterface()
         {
             auto frame = new Frame(2, ReliefStyle.groove)
                 .pack(10);

             auto label = new Label(frame, "Hello World!")
                 .pack(10);

             auto exitButton = new Button(frame, "Exit")
                 .setCommand(&this.exitCommand)
                 .pack(10);
         }
     }

     void main(string[] args)
     {
         auto app = new Application();
         app.run();
     }


[1]: https://github.com/nomad-software/tkd


More information about the Digitalmars-d-learn mailing list