1 /**
2 Copyright: Copyright (c) 2013-2014 Andrey Penechko.
3 License: a$(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0).
4 Authors: Andrey Penechko.
5 */
6 
7 module anchovy.gui.templates.widgettemplate;
8 
9 import anchovy.gui;
10 import std.algorithm;
11 
12 class SubwidgetTemplate
13 {
14 	Variant[string] properties;
15 	SubwidgetTemplate[] subwidgets;
16 	ForwardedProperty[] forwardedProperties;
17 
18 	override string toString()
19 	{
20 		return toStringImpl("");
21 	}
22 
23 	string toStringImpl(string padding)
24 	{
25 		string result;
26 		result ~= padding ~ to!string(properties["type"]);
27 
28 		foreach(key; properties.byKey)
29 		{
30 			result ~= " " ~ key ~ ":" ~ to!string(properties[key]);
31 		}
32 		foreach(fprop; forwardedProperties)
33 		{
34 			result ~= " alias " ~ fprop.propertyName ~" = " ~ fprop.targetPropertyName;
35 		}
36 		result ~= "\n";
37 
38 		foreach(sub; subwidgets)
39 		{
40 			result ~= sub.toStringImpl(padding ~ "   ");
41 		}
42 
43 		return result;
44 	}
45 }
46 
47 struct ForwardedProperty
48 {
49 	string propertyName; // property that will be created in root.
50 	string targetPropertyName; // property to bind to.
51 }
52 
53 class WidgetTemplate
54 {
55 	SubwidgetTemplate tree; // the widget itself.
56 	SubwidgetTemplate[string] subwidgetsmap;
57 	string baseType;
58 	string name;
59 	string container;
60 
61 	SubwidgetTemplate findSubwidgetByName(string name)
62 	{
63 		SubwidgetTemplate* subwidget;
64 
65 		subwidget = name in subwidgetsmap;
66 
67 		return *subwidget;
68 	}
69 
70 	override string toString()
71 	{
72 		return tree.toString() ~
73 				"base: " ~ baseType ~ " cont: " ~ container~"\n";
74 	}
75 }