Esempio n. 1
0
 public virtual cave.Color getBackgroundColorForElement(cave.ui.FormDeclaration.Element element)
 {
     if (element.isType("GroupContainer"))
     {
         return(cave.Color.black());
     }
     return(cave.Color.white());
 }
Esempio n. 2
0
        public virtual Windows.UI.Xaml.UIElement createWidgetForElement(cave.ui.FormDeclaration.Element element)
        {
            if (!(element != null))
            {
                return(null);
            }
            if (element.isType("TextInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_DEFAULT, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("TextButton"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextButtonWidget.forText(context, element.getPropertyString("text"), getActionHandler(element.getPropertyString("action"))));
            }
            if (element.isType("RawTextInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_NONASSISTED, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("PasswordInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_PASSWORD, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("NameInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_NAME, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("EmailAddressInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_EMAIL_ADDRESS, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("PhoneNumberInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_PHONE_NUMBER, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("StreetAddressInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextInputWidget.forType(context, cave.ui.TextInputWidget.TYPE_STREET_ADDRESS, asPlaceHolder(element.getLabel())));
            }
            if (element.isType("TextAreaInput"))
            {
                return((Windows.UI.Xaml.UIElement)cave.ui.TextAreaWidget.forPlaceholder(context, asPlaceHolder(element.getLabel()), element.getPropertyInteger("rows")));
            }
            if (element.isType("CodeInput"))
            {
                var v = cave.ui.TextAreaWidget.forPlaceholder(context, asPlaceHolder(element.getLabel()), element.getPropertyInteger("rows"));
                v.configureMonospaceFont();
                return((Windows.UI.Xaml.UIElement)v);
            }
            if (element.isType("StaticTextElement"))
            {
                var st  = cave.ui.FormWidget.StaticTextWidget.forText(context, element.getLabel());
                var bgc = getBackgroundColorForElement(element);
                var fgc = getAdjustedForegroundColor(element, bgc);
                st.setBackgroundColor(bgc);
                st.setTextColor(fgc);
                return((Windows.UI.Xaml.UIElement)st);
            }
            if (element.isType("RadioGroupInput"))
            {
                var items = element.getPropertyDynamicVector("items");
                if (!(items != null))
                {
                    items = new cape.DynamicVector();
                }
                return((Windows.UI.Xaml.UIElement)cave.ui.RadioButtonGroupWidget.forGroup(context, element.getPropertyString("groupName"), items.toVectorOfStrings()));
            }
            if (element.isType("MultipleChoiceInput"))
            {
                var kvl    = new cape.KeyValueList <string, string>();
                var values = element.getPropertyVector("values");
                if (values != null)
                {
                    var n = 0;
                    var m = values.Count;
                    for (n = 0; n < m; n++)
                    {
                        var value = values[n] as cape.DynamicMap;
                        if (value != null)
                        {
                            var key = value.getString("key");
                            var val = value.getString("value");
                            if (key != null)
                            {
                                kvl.add((string)key, (string)val);
                            }
                        }
                    }
                }
                return((Windows.UI.Xaml.UIElement)cave.ui.SelectWidget.forKeyValueList(context, kvl));
            }
            if (element.isType("CheckBoxInput"))
            {
                var cbx = cave.ui.CheckBoxWidget.forText(context, element.getPropertyString("text"));
                cbx.setWidgetChecked(element.getPropertyBoolean("isChecked"));
                return((Windows.UI.Xaml.UIElement)cbx);
            }
            if (element.isType("DateInput"))
            {
                var v1 = cave.ui.DateSelectorWidget.forContext(context);
                v1.setSkipYears(element.getPropertyInteger("skipYears"));
                return((Windows.UI.Xaml.UIElement)v1);
            }
            if (element.isType("StringListInput"))
            {
                var v2 = new cave.ui.FormWidget.MyStringListInputWidget(context);
                v2.setWidgetPlaceholder(element.getLabel());
                return((Windows.UI.Xaml.UIElement)v2);
            }
            cave.ui.CustomContainerWidget container = null;
            if (element.isType("VerticalContainer"))
            {
                var vb = cave.ui.VerticalBoxWidget.forContext(context);
                if (formWidth > 0)
                {
                    vb.setWidgetWidthRequest(formWidth);
                }
                vb.setWidgetSpacing(elementSpacing);
                container = (cave.ui.CustomContainerWidget)vb;
            }
            else if (element.isType("HorizontalContainer"))
            {
                var hb = cave.ui.HorizontalBoxWidget.forContext(context);
                hb.setWidgetSpacing(elementSpacing);
                container = (cave.ui.CustomContainerWidget)hb;
            }
            else if (element.isType("GroupContainer"))
            {
                var vb1 = cave.ui.VerticalBoxWidget.forContext(context);
                if (formWidth > 0)
                {
                    vb1.setWidgetWidthRequest(formWidth);
                }
                vb1.setWidgetSpacing(elementSpacing);
                var wlayer = cave.ui.LayerWidget.forContext(context);
                var bgc1   = getBackgroundColorForElement(element);
                wlayer.addWidget((Windows.UI.Xaml.UIElement)cave.ui.CanvasWidget.forColor(context, bgc1));
                var groupLabel = cave.ui.LabelWidget.forText(context, element.getPropertyString("title"));
                groupLabel.setWidgetTextColor(getAdjustedForegroundColor(element, bgc1));
                wlayer.addWidget((Windows.UI.Xaml.UIElement)cave.ui.LayerWidget.forWidget(context, (Windows.UI.Xaml.UIElement)groupLabel, context.getHeightValue("2mm")));
                vb1.addWidget((Windows.UI.Xaml.UIElement)wlayer);
                container = (cave.ui.CustomContainerWidget)vb1;
            }
            if (!(container != null))
            {
                System.Diagnostics.Debug.WriteLine("Unsupported form declaration container encountered: `" + element.getType() + "'");
                return(null);
            }
            var array = element.getChildren();

            if (array != null)
            {
                var n2 = 0;
                var m2 = array.Count;
                for (n2 = 0; n2 < m2; n2++)
                {
                    var child = array[n2];
                    if (child != null)
                    {
                        var ww = createAndRegisterWidget(child);
                        if (!(ww != null))
                        {
                            continue;
                        }
                        var label = child.getLabel();
                        if (enableFieldLabels && !cape.String.isEmpty(label))
                        {
                            var wlayer1 = cave.ui.LayerWidget.forContext(context);
                            var bgc2    = getBackgroundColorForElement(child);
                            wlayer1.addWidget((Windows.UI.Xaml.UIElement)cave.ui.CanvasWidget.forColor(context, bgc2));
                            var wbox = cave.ui.VerticalBoxWidget.forContext(context);
                            var lw   = cave.ui.LabelWidget.forText(context, label);
                            lw.setWidgetTextColor(getAdjustedForegroundColor(child, bgc2));
                            lw.setWidgetFontSize((double)fieldLabelFontSize);
                            if (fieldLabelFontResource != null)
                            {
                                lw.setWidgetFontResource(fieldLabelFontResource);
                            }
                            else
                            {
                                lw.setWidgetFontFamily(fieldLabelFontFamily);
                            }
                            var ss = context.getHeightValue("1mm");
                            wbox.addWidget((Windows.UI.Xaml.UIElement)cave.ui.LayerWidget.forWidget(context, (Windows.UI.Xaml.UIElement)lw).setWidgetMarginLeft(ss).setWidgetMarginRight(ss).setWidgetMarginTop(ss));
                            wbox.addWidget(ww, child.getPropertyDouble("weight"));
                            wlayer1.addWidget((Windows.UI.Xaml.UIElement)wbox);
                            addToContainerWithWeight(container, (Windows.UI.Xaml.UIElement)wlayer1, child.getPropertyDouble("weight"));
                        }
                        else
                        {
                            addToContainerWithWeight(container, ww, child.getPropertyDouble("weight"));
                        }
                    }
                }
            }
            return((Windows.UI.Xaml.UIElement)container);
        }