Reflection tip
I know that System.Xaml is a key technology that is not working with Gtk#.
In my free time, I tried to make possible Gtk#/Xaml like feeling, and the final code looks like following:
Initialize xml/C# objects initial mapping is:
After this, Xml code is like following for a window:
and the C# code looks like this:
A trained eye will notice that Gtk# Widget has the property WidthRequest but not Width, also, the method that sets Width, has to be called with other method, none named Width.
So the idea behind is that the xml mapping will go with properties, excluding some cases when are virtual properties.
An UI made with it is this one:
How it looks: http://picpaste.com/ui_program-ZHMePJcI.png
You may ask: but why you show the picture, does the gradient over Cairo in the left side has anything to do with Xml? The short answer is: yes, almost all declarative items are defined with xml.
Is it this program free/opensource?
Yes, the entire software alpha quality (the XML library/Reflection is good enough, I can say releasable), and for curious, can be found here: https://bitbucket.org/ciplogic/sharpdrawer/ (Mercurial repository, I recommend TortoiseHg to work with it)
Which features bring this Xml library:
- Xaml like mapping
- ways to override the constructors, for example if there is no constructor (look inside code for SmartWidget) or constructors need to take a specific parameter sometimes. The entire node is exposed to constructor so it can add/remove properties
- way to override the children addition
- Gtk#/Cairo operations mapping is done on top of the library, so for someone wanting xml mapping over other logical domains, can do it by looking how Gtk did the mapping. Also the mappings can be set after the fact
- Property binding. The code written previously:
Will notify the miniframework that if you listen to Changed event and will update ActiveText.
- it is a superset of Xaml in some places, in the idea that it supports both Xaml mapping of namespaces, assemblies, but it has extra tags to set them to not write them over and over. The behavior is per context. Is great if you import an external library for a section of the Xaml
- it supports inline code binding (just Boo), I should use the C# REPL evaluator for future, but I did not had the time yet, so very simple events can be written inline and Boo will compile them on dialog startup, at the end the user will have native performance for this inline code (Xaml requires that the logic to be set into references to code behind, but no way to write right away the code)
For haters: screenshot is on Windows, but it works just fine on Ubuntu 64bit, Fedora and OpenSuse. (I did not made any packaging, I will ask maybe in future to directhex)
I wanted with this post to show something that is practically untouchable by a single person doing this in his/her free time in some low level languages (I talk here about C++).
I know that System.Xaml is a key technology that is not working with Gtk#.
In my free time, I tried to make possible Gtk#/Xaml like feeling, and the final code looks like following:
Initialize xml/C# objects initial mapping is:
Code:
static void Init() { GtkDynamic.Setup(); BindInstance.AddBindMapping<ComboTexts>("ActiveText", "Changed"); }
HTML Code:
<Window Title="Create New Image" WindowPosition = "Center" Modal="true" xmlns:Controls="clr-namespace:SmartDraw.Views.Controls"> <VBox> <HBox> <Label Text="Template" /> <ComboTexts Namespace="SmartDraw.Views.Controls" DefaultWidth="200" ActiveText="{BindTo=Text;At=Changed}"> <ComboItem Text="640x480" /> <ComboItem Text="800x600" /> <ComboItem Text="1024x768" /> </ComboTexts> </HBox> <Label Text="Image Size" /> <HBox> <Label Width="100" Text="Width" /> <SpinButton Min="1" Max="30000" Value="{BindTwoWays=dWidth}"/> </HBox> <HBox> <Label Width="100" Text="Height" /> <SpinButton Min="1" Max="30000" Value="{BindTwoWays=dHeight}"/> </HBox> <HBox Pack="End" > <Button Text="OK" Clicked="OnOk" /> <Button Text="Cancel" Clicked="OnCancel" /> </HBox> </VBox> </Window>
Code:
internal class NewFileDialog : Window { public NewFileDialog():base(string.Empty) { this.SetXml(); //here the widget is built based on XML definition } (...) private void OnOk(object sender, EventArgs e) { // (OK button logic) Destroy(); } private void OnCancel(object sender, EventArgs e) { Destroy(); }
So the idea behind is that the xml mapping will go with properties, excluding some cases when are virtual properties.
An UI made with it is this one:
How it looks: http://picpaste.com/ui_program-ZHMePJcI.png
You may ask: but why you show the picture, does the gradient over Cairo in the left side has anything to do with Xml? The short answer is: yes, almost all declarative items are defined with xml.
Is it this program free/opensource?
Yes, the entire software alpha quality (the XML library/Reflection is good enough, I can say releasable), and for curious, can be found here: https://bitbucket.org/ciplogic/sharpdrawer/ (Mercurial repository, I recommend TortoiseHg to work with it)
Which features bring this Xml library:
- Xaml like mapping
- ways to override the constructors, for example if there is no constructor (look inside code for SmartWidget) or constructors need to take a specific parameter sometimes. The entire node is exposed to constructor so it can add/remove properties
- way to override the children addition
- Gtk#/Cairo operations mapping is done on top of the library, so for someone wanting xml mapping over other logical domains, can do it by looking how Gtk did the mapping. Also the mappings can be set after the fact
- Property binding. The code written previously:
Code:
BindInstance.AddBindMapping<ComboTexts>("ActiveText", "Changed");
- it is a superset of Xaml in some places, in the idea that it supports both Xaml mapping of namespaces, assemblies, but it has extra tags to set them to not write them over and over. The behavior is per context. Is great if you import an external library for a section of the Xaml
- it supports inline code binding (just Boo), I should use the C# REPL evaluator for future, but I did not had the time yet, so very simple events can be written inline and Boo will compile them on dialog startup, at the end the user will have native performance for this inline code (Xaml requires that the logic to be set into references to code behind, but no way to write right away the code)
For haters: screenshot is on Windows, but it works just fine on Ubuntu 64bit, Fedora and OpenSuse. (I did not made any packaging, I will ask maybe in future to directhex)
I wanted with this post to show something that is practically untouchable by a single person doing this in his/her free time in some low level languages (I talk here about C++).
Comment