0

When talking about RAD (Rapid Application Development) Tool under Linux/Unix, I used to use Tk, which is a fairly easy library for building graphical applications, to build simple GUI based applications, because to me, GTK, Qt, or Java are way too complicated to be use to build simple GUI based applications. Maybe they are designed to build complicated ones.

The core concept of Tk is that GUIs are built out of widgets -- objects like buttons, windows, scrollbars, and menus, which have associated attributes (size, colour, captions, and so on). Widgets are grouped together hierarchically within a toplevel window...

The general structure of a Tcl/Tk program is to define the user interface as a hierarchy of widgets with subroutines executed by callbacks. Widgets show up on the screen when you ask a geometry manager to manage them, or when you invoke the pack command (to resize the widget's parent to hold them).

-- Rapid Application Development Tools

The reason I quote above is to show how easy is to code such GUI based applications by hand in Tk.

The key idea is that you "declare" the GUI, instead of drawing it by hand (like in Visual Basic). There are so many drawing-based GUI tools (like glade, etc), but very very few declarative ones. I'm wondering what they are.

While looking for answers myself, I found the following is the kind of declarative GUI building tools I'm looking for (although I don't know what Oz stands for). you can see how simple declaration can be used for creating windows, adding children to them, and making them react to user input, etc.

functor import Application(exit) System(show) GTK define %% Define Toplevel window class class MyToplevel from GTK.window meth new() GTK.window, new(GTK.'WINDOW_TOPLEVEL') GTK.window, setBorderWidth(10) GTK.window, setTitle("Hello, World!") {self signalConnect('delete-event' deleteEvent _)} end meth deleteEvent(Args) %% Do cleanup stuff here {System.show 'deleteEvent occured'} {Application.exit 0} end end %% Define HelloButton class class HelloButton from GTK.button meth new() GTK.button, newWithLabel("Hello, World!") GTK.button, signalConnect('clicked' clickedEvent _) end meth clickedEvent(Args) {System.show 'ClickedEvent occured'} end end %% Create Class Instances Toplevel = {New MyToplevel new()} Button = {New HelloButton new()} %% Make Butten child of Toplevel Container {Toplevel add(Button)} %% Make it all visible {Toplevel showAll()} end

So, again, what are the popular declarative GUI building tools out there? (I'm actually more interested with those that work with Go, but that's not the restrain to this question)

Thanks

1

There is a library called libui.

libui is a simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.

When you use this library, you write a GUI program instead of "drag-drop" GUI components. I don't know what "declare" exactly means. But, I assume that "declare" is the code keywords is easily to understand. This library is not only available for C but also Go. Here is a simple GUI program I taken from libui tutorial:

package main

import (
    "github.com/andlabs/ui"
)

func main() {
    err := ui.Main(func() {
        name := ui.NewEntry()
        button := ui.NewButton("Greet")
        greeting := ui.NewLabel("")
        box := ui.NewVerticalBox()
        box.Append(ui.NewLabel("Enter your name:"), false)
        box.Append(name, false)
        box.Append(button, false)
        box.Append(greeting, false)
        window := ui.NewWindow("Hello", 200, 100, false)
        window.SetChild(box)
        button.OnClicked(func(*ui.Button) {
            greeting.SetText("Hello, " + name.Text() + "!")
        })
        window.OnClosing(func(*ui.Window) bool {
            ui.Quit()
            return true
        })
        window.Show()
    })
    if err != nil {
        panic(err)
    }
}

It will produce a GUI program like this:

example-libgui-go-program

  • This is the best answer so far. – xpt Nov 21 '16 at 17:07
1

Vaadin

For building the GUI of a web app in pure Java, consider the Vaadin open-source framework.

Vaadin works exactly as you describe, specifying in code the layout of a form, adding each widget (labels, fields, buttons, etc.). You then add chunks of code to be executed as the user manipulates the widgets at runtime.

Vaadin is similar in idea to Java Swing, but much simpler, better engineered, better thought-out, and much more practical and reliable.

Search for similar Questions here where I have posted more detailed discussions on Vaadin.

  • Thanks Basil, I found it "works on any HTML5 based stack" as well. That's a plus. Oh, and Vaadin Charts as well (Commercial license). I'd surely pick this one had there not been a Go solution. Still, +1. – xpt Nov 21 '16 at 16:49
  • How is this declarative? – reinierpost Nov 21 '16 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.