
2011/6/18 Germán Diago <germandiago@gmail.com>:
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.
Ok. I would prefer a XAML mapping.It has been used with success in the .NET world and it is standard. It seems that you are reiventing gtkmm:).