Boost logo

Boost :

Subject: [boost] [gui] Help with a little experiment.
From: Germán Diago (germandiago_at_[hidden])
Date: 2011-06-18 07:05:08


Hello. I'm trying to implement a little experiment of what I see should
be the future of c++ guis. For that I'm going to need a handful of
proto and fusion, and I have some questions. Besides that, there
have been many times that a GUI for boost has been discussed.
As I have some questions and something to expose, I thought it would
be a good idea to post this message in both boost users and boost developers.

I don't have an entire proposal for this, but for now I'm experimenting
how a GUI framework should look like in my opinion.

My opinion is that it should be AS declarative as possible, so, taking
as a backend the gtk framework, I came with a syntax like the following
one:

#define CONTROLLER_CLASS GuiController
#include <Gui/Layout.h>
#include <iostream>

class GuiController {
        void onEntryChanged(Entry & entry) {
                auto text = entry.getText();
                std::cout << text << std::endl;
        }

        void onButtonClick(Button & button) {
                std::cout << "Button was clicked" << std::endl;
        }
};

auto gui_definition =
Window(title="Hello, world!") <<
        VBox(expand=true) <<
                HBox(expand=true) <<
                        Label(text="Name:") && Entry[SLOT(onEntryChanged)])
                << End(HBox);
                << Button(text="hello")[SLOT(onButtonClick)];
        << End(VBox)
<< End(Window);

The properties are mapped to objects like title corresponding to the gtk
properties. The << operator means insert into and the << End(WidgetName)
means that no more widgets should be inserted inside that closed widget.
The && operator means put widgets at the same level. Regarding signals,
they're put inside operator[]. That gui definition would be used like this

template <class UI, class Controller>
?? createGUI(UIDefinition & ui_def, Controller & controller);

int main(int argc, char * argv[]) {
        GuiController controller;
        auto window = createGUI(gui_definition, controller);

        window.show_all();
        window.run();
}

The function createGUI would generate a GUI from the definition and
 it would bind SLOTS automagically. It's very little code making use of
a DSEL. The problem is that I must learn a lot of proto to code this,
but if it works, do you think it would be an improvement? It's all
compiler-checkable
and the code is very short. After this first step I could start
thinking beyond gtk
and separate the library in backend and frotend so that not just gtk+ is used.

My question is:

Can I make something like End(VBox) work with boost.proto? I mean if it's
possible to close the expression for a VBox with end and insert the next widget
to the same level that the HBox.

Thanks for your time and feedback is welcome.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk