Esempio n. 1
0
 public UIFont GetFont()
 {
     if (m_viewX is UIButton)
     {
         return(((UIButton)m_viewX).TitleLabel.Font);
     }
     else if (m_viewX is UILabel)
     {
         return(((UILabel)m_viewX).Font);
     }
     else if (m_viewX is UITextField)
     {
         return(((UITextField)m_viewX).Font);
     }
     else if (m_viewX is UITextView)
     {
         return(((UITextView)m_viewX).Font);
     }
     else if (m_viewX is UIPickerView)
     {
         UIPickerView        picker = m_viewX as UIPickerView;
         TypePickerViewModel model  = picker.Model as TypePickerViewModel;
         return(model.GetFont());
     }
     return(null);
 }
Esempio n. 2
0
 public void SetFont(UIFont newFont)
 {
     if (m_viewX is UIButton)
     {
         ((UIButton)m_viewX).TitleLabel.Font = newFont;;
     }
     else if (m_viewX is UILabel)
     {
         ((UILabel)m_viewX).Font = newFont;
     }
     else if (m_viewX is UITextField)
     {
         ((UITextField)m_viewX).Font = newFont;
     }
     else if (m_viewX is UITextView)
     {
         ((UITextView)m_viewX).Font = newFont;
     }
     else if (m_viewX is UIPickerView)
     {
         UIPickerView        picker = m_viewX as UIPickerView;
         TypePickerViewModel model  = picker.Model as TypePickerViewModel;
         model?.SetFont(newFont);
     }
 }
Esempio n. 3
0
        public virtual string GetText()
        {
            if (m_viewX is UIButton)
            {
                return(m_originalText != null ? m_originalText :
                       ((UIButton)m_viewX).Title(UIControlState.Normal));
            }
            string result = "";

            if (m_viewX is UIButton)
            {
                result = ((UIButton)m_viewX).Title(UIControlState.Normal);
            }
            else if (m_viewX is UILabel)
            {
                result = ((UILabel)m_viewX).Text;
            }
            else if (m_viewX is UITextField)
            {
                result = ((UITextField)m_viewX).Text;
            }
            else if (m_viewX is UITextView)
            {
                result = ((UITextView)m_viewX).Text;
            }
            else if (m_viewX is UIPickerView)
            {
                UIPickerView        pickerView = m_viewX as UIPickerView;
                TypePickerViewModel model      = pickerView.Model as TypePickerViewModel;
                int row = (int)GetValueFunction.GetValue(this);
                result = model.RowToString(row);
            }
            return(result);
        }
Esempio n. 4
0
        public virtual void AddImages(List <UIImage> images, string varName, string title)
        {
            if (ViewX is UIPickerView)
            {
                UIPickerView pickerView = ViewX as UIPickerView;

                TypePickerViewModel model = pickerView.Model as TypePickerViewModel;
                if (model == null)
                {
                    model = new TypePickerViewModel(AppDelegate.GetCurrentController());
                }
                model.Images = images;

                if (!string.IsNullOrWhiteSpace(title))
                {
                    AddAction(varName, title);
                }
                model.SetSize((int)pickerView.Bounds.Width, (int)pickerView.Bounds.Height / 4);
                pickerView.Model = model;
            }
            else if (ViewX is UITableView)
            {
                UITableView tableView = ViewX as UITableView;

                TableViewSource source = tableView.Source as TableViewSource;
                if (source == null)
                {
                    source = new TableViewSource();
                }
                source.Images    = images;
                tableView.Source = source;
            }
        }
Esempio n. 5
0
        public virtual double GetValue()
        {
            double result = 0;

            if (m_viewX is UISwitch)
            {
                result = ((UISwitch)m_viewX).On ? 1 : 0;
            }
            else if (m_viewX is UISlider)
            {
                result = ((UISlider)m_viewX).Value;
            }
            else if (m_viewX is UIStepper)
            {
                result = ((UIStepper)m_viewX).Value;
            }
            else if (m_viewX is UIPickerView)
            {
                result = ((TypePickerViewModel)(((UIPickerView)m_viewX).Model)).SelectedRow;
            }
            else if (m_viewX is UISegmentedControl)
            {
                result = ((UISegmentedControl)m_viewX).SelectedSegment;
            }
            else if (WidgetType == UIType.COMBOBOX)
            {
                TypePickerViewModel model = m_picker.Model as TypePickerViewModel;
                result = model.SelectedRow;
            }
            else
            {
                result = CurrVal;
            }
            return(result);
        }
Esempio n. 6
0
        public virtual void AddData(List <string> data, string varName, string title, string extra)
        {
            if (ViewX is UIPickerView)
            {
                UIPickerView pickerView = ViewX as UIPickerView;

                TypePickerViewModel model = pickerView.Model as TypePickerViewModel;
                if (model == null)
                {
                    model = new TypePickerViewModel(AppDelegate.GetCurrentController());
                }
                model.Data = data;

                if (!string.IsNullOrWhiteSpace(title))
                {
                    model.RowSelected += (row) => {
                        UIVariable.GetAction(title, varName, row.ToString());
                    };
                }
                if (!string.IsNullOrWhiteSpace(extra))
                {
                    var al = UtilsiOS.GetAlignment(extra);
                    model.Alignment = al.Item2;
                }

                model.SetSize((int)pickerView.Bounds.Width, (int)pickerView.Bounds.Height / 4);
                pickerView.Model = model;
            }
            else if (ViewX is UITableView)
            {
                UITableView tableView = ViewX as UITableView;

                TableViewSource source = tableView.Source as TableViewSource;
                if (source == null)
                {
                    source = new TableViewSource();
                }
                source.Data      = data;
                tableView.Source = source;
                tableView.ReloadData();
            }
            else if (m_picker != null)
            {
                TypePickerViewModel model = m_picker.Model as TypePickerViewModel;
                model.Data = data;

                if (!string.IsNullOrEmpty(extra))
                {
                    Tuple <UIControlContentHorizontalAlignment, UITextAlignment> al =
                        UtilsiOS.GetAlignment(extra);
                    model.Alignment = al.Item2;
                }
                m_picker.Model = model;

                SetText(data[0], extra, true /* triggered */);
            }
        }
Esempio n. 7
0
        public void SetComboboxAlignment(UITextAlignment al)
        {
            if (m_picker == null || m_picker.Model == null)
            {
                return;
            }
            TypePickerViewModel model = m_picker.Model as TypePickerViewModel;

            model.Alignment = al;
        }
Esempio n. 8
0
        public virtual bool SetText(string text, string alignment = null, bool tiggered = false)
        {
            m_originalText = text;

            m_alignment = string.IsNullOrEmpty(alignment) ? m_alignment : alignment;
            // Add extra space for buttons, otherwise they don't look good.
            if (m_viewX is UIButton)
            {
                if (m_alignment == "left")
                {
                    text = " " + text;
                }
                else if (m_alignment == "right")
                {
                    text = text + " ";
                }
            }
            AlignText(alignment);

            if (WidgetType == UIType.COMBOBOX && !tiggered)
            {
                SetComboboxText(text);
            }
            else if (ViewX is UIButton)
            {
                ((UIButton)ViewX).SetTitle(text, UIControlState.Normal);
            }
            else if (ViewX is UILabel)
            {
                ((UILabel)ViewX).Text = text;
            }
            else if (ViewX is UITextField)
            {
                ((UITextField)ViewX).Text = text;
            }
            else if (ViewX is UITextView)
            {
                ((UITextView)ViewX).Text = text;
            }
            else if (ViewX is UIPickerView && !tiggered)
            {
                UIPickerView        picker = ViewX as UIPickerView;
                TypePickerViewModel model  = picker.Model as TypePickerViewModel;
                int row = model.StringToRow(text);
                picker.Select((int)row, 0, true);
                model.Selected(picker, (int)row, 0);
            }
            else
            {
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        public virtual bool AlignText(string alignment)
        {
            if (string.IsNullOrEmpty(alignment))
            {
                return(false);
            }
            alignment = alignment.ToLower();

            Tuple <UIControlContentHorizontalAlignment, UITextAlignment> al = UtilsiOS.GetAlignment(alignment);

            if (WidgetType == UIType.COMBOBOX)
            {
                SetComboboxAlignment(al.Item2);
            }
            else if (ViewX is UIButton)
            {
                ((UIButton)ViewX).HorizontalAlignment = al.Item1;
            }
            else if (ViewX is UILabel)
            {
                ((UILabel)ViewX).TextAlignment = al.Item2;
            }
            else if (ViewX is UITextField)
            {
                ((UITextField)ViewX).TextAlignment = al.Item2;
            }
            else if (ViewX is UITextView)
            {
                ((UITextView)ViewX).TextAlignment = al.Item2;
            }
            else if (ViewX is UIPickerView)
            {
                UIPickerView        picker = ViewX as UIPickerView;
                TypePickerViewModel model  = picker.Model as TypePickerViewModel;
                if (model != null)
                {
                    model.Alignment = al.Item2;
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Esempio n. 10
0
        public void SetComboboxText(string text, int row = -1)
        {
            if (m_picker == null || m_picker.Model == null)
            {
                return;
            }
            TypePickerViewModel model = m_picker.Model as TypePickerViewModel;

            if (row < 0)
            {
                row = model.StringToRow(text);
            }
            m_picker.Select((int)row, 0, true);
            //model?.Selected(m_picker, (int)row, 0);
            ActionDelegate?.Invoke(WidgetName, text);

            m_button?.SetTitle(text, UIControlState.Normal);
        }
Esempio n. 11
0
 public virtual void AddAction(string varName,
                               string strAction, string argument = "")
 {
     if (!string.IsNullOrWhiteSpace(argument))
     {
         if (argument.Equals("FINISHED"))
         {
             if (ViewX is UITextField)
             {
                 UITextField textField = ViewX as UITextField;
                 textField.EditingDidEnd += (sender, e) => {
                     UIVariable.GetAction(strAction, varName, "\"" + textField.Text + "\"");
                 };
             }
             return;
         }
     }
     if (WidgetType == UIVariable.UIType.COMBOBOX)
     {
         ActionDelegate += (arg1, arg2) => {
             UIVariable.GetAction(strAction, arg1, "\"" + arg2 + "\"");
         };
     }
     else if (ViewX is UIButton)
     {
         UIButton button = ViewX as UIButton;
         button.TouchUpInside += (sender, e) => {
             UIVariable.GetAction(strAction, varName, "\"" + argument + "\"");
         };
     }
     else if (ViewX is UISwitch)
     {
         UISwitch sw = ViewX as UISwitch;
         sw.ValueChanged += (sender, e) => {
             UIVariable.GetAction(strAction, varName, "\"" + sw.On + "\"");
         };
     }
     else if (ViewX is UITextField)
     {
         UITextField textField = ViewX as UITextField;
         textField.EditingChanged += (sender, e) => {
             UIVariable.GetAction(strAction, varName, "\"" + textField.Text + "\"");
         };
     }
     else if (ViewX is UISlider)
     {
         UISlider slider = ViewX as UISlider;
         slider.ValueChanged += (sender, e) => {
             UIVariable.GetAction(strAction, varName, "\"" + slider.Value + "\"");
         };
     }
     else if (ViewX is UISegmentedControl)
     {
         UISegmentedControl seg = ViewX as UISegmentedControl;
         seg.ValueChanged += (sender, e) => {
             UIVariable.GetAction(strAction, varName, "\"" + seg.SelectedSegment + "\"");
         };
     }
     else if (ViewX is UIPickerView)
     {
         UIPickerView        pickerView = ViewX as UIPickerView;
         TypePickerViewModel model      = pickerView.Model as TypePickerViewModel;
         if (model == null)
         {
             model = new TypePickerViewModel(AppDelegate.GetCurrentController());
         }
         model.RowSelected += (row) => {
             UIVariable.GetAction(strAction, varName, row.ToString());
         };
         pickerView.Model = model;
     }
     else if (ViewX is UITableView)
     {
         UITableView     tableView = ViewX as UITableView;
         TableViewSource source    = tableView.Source as TableViewSource;
         if (source == null)
         {
             source = new TableViewSource();
         }
         source.RowSelectedDel += (row) => {
             UIVariable.GetAction(strAction, varName, "\"" + row + "\"");
         };
         tableView.Source = source;
     }
     else
     {
         ActionDelegate += (arg1, arg2) => {
             UIVariable.GetAction(strAction, varName, "\"" + arg2 + "\"");
         };
     }
 }
Esempio n. 12
0
        public void CreateCombobox(CGRect rect, string argument)
        {
            UIView parent = GetParentView();

            WidgetType = UIVariable.UIType.COMBOBOX;

            UIView mainView   = AppDelegate.GetCurrentView();
            int    mainHeight = (int)mainView.Frame.Size.Height;
            int    mainWidth  = (int)mainView.Frame.Size.Width;

            int pickerHeight = Math.Min(mainHeight / 3, 320);
            int pickerWidth  = Math.Min(mainWidth, 640);
            int pickerY      = mainHeight - pickerHeight + 20;

            m_picker  = new UIPickerView();
            m_button  = new UIButton();
            m_button2 = new UIButton();

            m_button.Frame = rect;

            m_picker.Frame  = new CGRect(0, pickerY, pickerWidth, pickerHeight);
            m_button2.Frame = new CGRect(0, pickerY - 20, pickerWidth, 40);

            string alignment = "", color1 = "", color2 = "", closeLabel = "";

            Utils.Extract(argument, ref alignment, ref color1, ref color2, ref closeLabel);
            m_alignment = alignment;
            Tuple <UIControlContentHorizontalAlignment, UITextAlignment> al =
                UtilsiOS.GetAlignment(alignment);

            m_viewY       = new UIView();
            m_viewY.Frame = new CGRect(0, 0, mainWidth, mainHeight);

            TypePickerViewModel model = new TypePickerViewModel(AppDelegate.GetCurrentController());

            /*model.RowSelected += (row) => {
             * string text = model.SelectedText;
             * SetText(text, alignment, true);
             * ActionDelegate?.Invoke(WidgetName, text);
             *
             * m_viewY.RemoveFromSuperview();
             * };*/
            m_picker.ShowSelectionIndicator = true;
            m_picker.Hidden = true;
            m_picker.Model  = model;

            if (!string.IsNullOrEmpty(color1))
            {
                m_viewY.BackgroundColor = UtilsiOS.String2Color(color1);
                if (string.IsNullOrEmpty(color2))
                {
                    color2 = color1;
                }
                m_picker.BackgroundColor = UtilsiOS.String2Color(color2);
            }

            //m_button.SetTitle(extraLabel, UIControlState.Normal);
            m_button.BackgroundColor = UIColor.Clear;
            m_button.SetTitleColor(UIColor.Black, UIControlState.Normal);
            m_button.Hidden             = false;
            m_button.Layer.BorderWidth  = 1;
            m_button.Layer.CornerRadius = 4;
            m_button.Layer.BorderColor  = UIColor.LightGray.CGColor;
            UIImage img = UtilsiOS.CreateComboboxImage(rect);

            m_button.SetBackgroundImage(img, UIControlState.Normal);
            m_button.ImageView.ClipsToBounds = true;
            m_button.ContentMode             = UIViewContentMode.Right;
            m_button.HorizontalAlignment     = al.Item1;
            m_button.TouchUpInside          += (sender, e) => {
                ResetCombos();
                m_button2.Hidden = false;
                m_picker.Hidden  = false;

                model = m_picker.Model as TypePickerViewModel;

                string text = GetText();
                int    row  = model.StringToRow(text);
                model.Selected(m_picker, (int)row, 0);
                mainView.BecomeFirstResponder();
                mainView.AddSubview(m_viewY);
            };

            if (string.IsNullOrEmpty(closeLabel))
            {
                closeLabel = "X";
            }
            m_button2.SetTitle(closeLabel + "\t", UIControlState.Normal);
            m_button2.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
            m_button2.BackgroundColor     = UIColor.FromRGB(100, 100, 100);
            m_button2.SetTitleColor(UIColor.White, UIControlState.Normal);
            m_button2.Hidden         = true;
            m_button2.TouchUpInside += (sender, e) => {
                m_button2.Hidden = true;
                m_picker.Hidden  = true;
                string text = model.SelectedText;
                SetText(text, alignment, true /* triggered */);
                ActionDelegate?.Invoke(WidgetName, text);

                m_viewY.RemoveFromSuperview();
                mainView.BecomeFirstResponder();
            };

            mainView.AddSubview(m_button);

            m_viewY.AddSubview(m_picker);
            m_viewY.AddSubview(m_button2);

            m_viewX     = m_button;
            m_viewX.Tag = ++m_currentTag;
        }
Esempio n. 13
0
        public virtual bool SetValue(string arg1, string arg2 = "")
        {
            double val = Utils.ConvertToDouble(arg1);

            CurrVal = val;
            if (m_viewY is UIStepper)
            {
                UIStepper stepper = m_viewY as UIStepper;
                stepper.Value = val;
                UIView[] subviews = m_viewX.Subviews;
                foreach (UIView view in subviews)
                {
                    if (view is UILabel)
                    {
                        UILabel label = view as UILabel;
                        label.Text = CurrVal.ToString();
                    }
                }
            }
            else if (WidgetType == UIType.COMBOBOX)
            {
                switch (arg1)
                {
                case "alignment":
                    Tuple <UIControlContentHorizontalAlignment, UITextAlignment> al =
                        UtilsiOS.GetAlignment(arg2);
                    m_button.HorizontalAlignment = al.Item1;
                    break;

                case "backgroundcolorpicker":
                    m_picker.BackgroundColor = UtilsiOS.String2Color(arg2);
                    break;

                case "backgroundcolorbutton2":
                    m_button2.BackgroundColor = UtilsiOS.String2Color(arg2);
                    break;

                case "fontcolor2":
                    m_button2.SetTitleColor(UtilsiOS.String2Color(arg2), UIControlState.Normal);
                    break;

                case "text2":
                    m_button2.SetTitle(arg2 + "\t", UIControlState.Normal);
                    break;
                }
                if (string.IsNullOrEmpty(arg1) || arg1 == "value")
                {
                    SetComboboxText("", (int)val);
                }
            }
            else if (m_viewX is UISwitch)
            {
                ((UISwitch)m_viewX).On = (int)val == 1;
            }
            else if (m_viewX is UISlider)
            {
                ((UISlider)m_viewX).Value = (float)val;
            }
            else if (m_viewX is UIStepper)
            {
                ((UIStepper)m_viewX).Value = (float)val;
            }
            else if (m_viewX is UIPickerView)
            {
                UIPickerView picker = m_viewX as UIPickerView;
                picker.Select((int)val, 0, true);
                TypePickerViewModel model = picker.Model as TypePickerViewModel;
                model?.Selected(picker, (int)val, 0);
            }
            else if (m_viewX is UISegmentedControl)
            {
                ((UISegmentedControl)m_viewX).SelectedSegment = (nint)val;
            }
            else
            {
                return(false);
            }
            return(true);
        }