コード例 #1
0
        private UIControl GetMenuEntry(UIControl parent, string label)
        {
            var control = new UIButton();

            control.InputReleased += control_InputPressed;
            //var uiImg = new UIImage( "graphics/arrow_down" );
            //uiImg.AddConstraint( Edge.CenterXY, control, Edge.CenterXY );
            //control.AddDecoration( uiImg );

            var uiLabel = new UILabel(label);

            uiLabel.AddConstraint(Edge.CenterXY, control, Edge.CenterXY);
            control.AddDecoration(uiLabel);

            control.AddConstraint(Edge.CenterX, parent, Edge.CenterX);

            if (previousEntry == null)
            {
                control.AddConstraint(Edge.CenterY, parent, Edge.CenterY, 0, ConstraintCategory.Initialization);
            }
            else
            {
                control.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.Initialization);
            }

            previousEntry = control;
            return(control);
        }
コード例 #2
0
ファイル: Menu.cs プロジェクト: adamxi/SharpDXFramework
        private UIControl GetMenuEntry( UIControl parent, string label )
        {
            var control = new UIButton();
            control.InputReleased += control_InputPressed;
            //var uiImg = new UIImage( "graphics/arrow_down" );
            //uiImg.AddConstraint( Edge.CenterXY, control, Edge.CenterXY );
            //control.AddDecoration( uiImg );

            var uiLabel = new UILabel( label );
            uiLabel.AddConstraint( Edge.CenterXY, control, Edge.CenterXY );
            control.AddDecoration( uiLabel );

            control.AddConstraint( Edge.CenterX, parent, Edge.CenterX );

            if( previousEntry == null )
            {
                control.AddConstraint( Edge.CenterY, parent, Edge.CenterY, 0, ConstraintCategory.Initialization );
            }
            else
            {
                control.AddConstraint( Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.Initialization );
            }

            previousEntry = control;
            return control;
        }
コード例 #3
0
        public override void LoadContent()
        {
            var menuBar = new UIPanel();

            menuBar.AddConstraint(Edge.Top, null, Edge.Top, 10);
            menuBar.AddConstraint(Edge.Left, null, Edge.Left, 50);
            menuBar.Alpha = 0f;

            var homeItem = new UIButton();

            homeItem.AddDecoration(new UILabel("Home Menu"));
            homeItem.AddConstraint(Edge.Left, menuBar, Edge.Left);
            homeItem.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            homeItem.InputReleased += HomeItem_InputReleased;
            menuBar.AddChild(homeItem);

            var debugCheckbox = new UILabelCheckBox("Draw UI Borders:");

            debugCheckbox.AddConstraint(Edge.Left, homeItem, Edge.Right, -20);
            debugCheckbox.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            debugCheckbox.CheckBox.InputReleased += DebugCheckbox_InputReleased;
            debugCheckbox.CheckBox.Checked        = UIManager.DrawDebug;
            menuBar.AddChild(debugCheckbox);

            testSceneUIManager = new UIManager();
            testSceneUIManager.Add(menuBar);
        }
コード例 #4
0
        private void InitButton()
        {
            UIButton btn = new UIButton();

            btn.AddDecoration(new UIImage("graphics/arrow_down"));
            btn.Tag = "Arrow";
            btn.AddConstraint(Edge.Right, null, Edge.Right, 100f, ConstraintCategory.Initialization);
            btn.AddConstraint(Edge.CenterY, null, Edge.CenterY, ConstraintCategory.Initialization);
            btn.InputMoved += btn_MouseMoved;

            uiManager.Add(btn);
        }
コード例 #5
0
        private UIControl GetMenuEntry(UIControl parent, string label)
        {
            var btn = new UIButton();
            btn.Tag = label;
            btn.AddDecoration(new UILabel(label));

            btn.AddConstraint(Edge.CenterX, parent, Edge.CenterX, ConstraintCategory.All);

            if (previousEntry != null)
            {
                btn.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.All);
            }

            previousEntry = btn;
            return btn;
        }
コード例 #6
0
        private void Initialize()
        {
            UserInteractionEnabled = true;

            SetupFiltersButton(
                _filtersButton = new UIButton(UIButtonType.Custom)
                                 .WithFrame(8, 8, (Frame.Width - 16 / 2) - 4, Frame.Height - 16)
                                 .WithTitleForAllStates(Mvx.Resolve <ILocalizationService>().GetLocalizableString(ProductsConstants.RESX_NAME, "Catalog_Filters"))
                );

            _filtersButton.TranslatesAutoresizingMaskIntoConstraints = false;
            _filtersButton.AddConstraint(NSLayoutConstraint.Create(_filtersButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, ((DeviceInfo.ScreenWidth - 16) / 2) - 4));

            SetupSortButton(
                _sortButton = new UIButton(UIButtonType.Custom)
                              .WithFrame((Frame.Width / 2) + 4, 8, (Frame.Width - 16 / 2) - 4, Frame.Height - 16)
                              .WithTitleForAllStates(Mvx.Resolve <ILocalizationService>().GetLocalizableString(ProductsConstants.RESX_NAME, "Catalog_Sort"))
                );

            _sortButton.TranslatesAutoresizingMaskIntoConstraints = false;
            _sortButton.AddConstraint(NSLayoutConstraint.Create(_sortButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, ((DeviceInfo.ScreenWidth - 16) / 2) - 4));

            AddSubviews(_filtersButton, _sortButton);

            this.AddConstraints(new[]
            {
                NSLayoutConstraint.Create(_filtersButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 4),
                NSLayoutConstraint.Create(_filtersButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -4),
                NSLayoutConstraint.Create(_filtersButton, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1, 8),

                NSLayoutConstraint.Create(_sortButton, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 4),
                NSLayoutConstraint.Create(_sortButton, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, -4),
                NSLayoutConstraint.Create(_sortButton, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, this, NSLayoutAttribute.Trailing, 1, -8),
            });
        }
コード例 #7
0
        public static UIBarButtonItem SetupImageBarButton(nfloat size, string imageName, EventHandler onTouchEvent)
        {
            var button = new UIButton(new CGRect(0, 0, size, size))
            {
                ContentMode = UIViewContentMode.ScaleAspectFit
            };

            button.AddConstraint(NSLayoutConstraint.Create(button, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, size));
            button.AddConstraint(NSLayoutConstraint.Create(button, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, size));
            button.SetImage(UIImage.FromBundle(imageName), UIControlState.Normal);
            button.SetTitle(string.Empty, UIControlState.Normal);

            button.TouchUpInside -= onTouchEvent;
            button.TouchUpInside += onTouchEvent;

            return(new UIBarButtonItem(button));
        }
コード例 #8
0
        private UIControl GetMenuEntry(UIControl parent, string label)
        {
            var btn = new UIButton();

            btn.Tag = label;
            btn.AddDecoration(new UILabel(label));

            btn.AddConstraint(Edge.CenterX, parent, Edge.CenterX, ConstraintCategory.All);

            if (previousEntry != null)
            {
                btn.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.All);
            }

            previousEntry = btn;
            return(btn);
        }
コード例 #9
0
        private UIControl GetMenuEntry(string label)
        {
            var btn = new UIButton();

            btn.Tag = label;
            btn.AddDecoration(new UILabel(label));
            //btn.NormalizedOrigin = Vector2.Zero;

            btn.AddConstraint(Edge.CenterX, menuPanel, Edge.CenterX, ConstraintCategory.All);

            if (previousEntry != null)
            {
                btn.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.All);
            }

            previousEntry = btn;
            return(btn);
        }
コード例 #10
0
        private UIControl GetMenuEntry(string label)
        {
            var btn = new UIButton();

            btn.Tag = label;
            btn.AddDecoration(new UILabel(label));

            if (previousEntry == null)
            {
                btn.AddConstraint(Edge.CenterXY, menuPanel, Edge.CenterXY, ConstraintCategory.Initialization);
            }
            else
            {
                btn.AddConstraint(Edge.CenterX, previousEntry, Edge.CenterX, ConstraintCategory.Initialization);
                btn.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.Initialization);
            }

            previousEntry = btn;
            return(btn);
        }
コード例 #11
0
ファイル: TestScene.cs プロジェクト: adamxi/SharpDXFramework
        public override void LoadContent()
        {
            var menuBar = new UIPanel();
            menuBar.AddConstraint(Edge.Top, null, Edge.Top, 10);
            menuBar.AddConstraint(Edge.Left, null, Edge.Left, 50);
            menuBar.Alpha = 0f;

            var homeItem = new UIButton();
            homeItem.AddDecoration(new UILabel("Home Menu"));
            homeItem.AddConstraint(Edge.Left, menuBar, Edge.Left);
            homeItem.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            homeItem.InputReleased += HomeItem_InputReleased;
            menuBar.AddChild(homeItem);

            var debugCheckbox = new UILabelCheckBox("Draw UI Borders:");
            debugCheckbox.AddConstraint(Edge.Left, homeItem, Edge.Right, -20);
            debugCheckbox.AddConstraint(Edge.CenterY, menuBar, Edge.CenterY);
            debugCheckbox.CheckBox.InputReleased += DebugCheckbox_InputReleased;
            debugCheckbox.CheckBox.Checked = UIManager.DrawDebug;
            menuBar.AddChild(debugCheckbox);

            testSceneUIManager = new UIManager();
            testSceneUIManager.Add(menuBar);
        }
コード例 #12
0
        private UIControl GetMenuEntry(string label)
        {
            var btn = new UIButton();
            btn.Tag = label;
            btn.AddDecoration(new UILabel(label));
            //btn.NormalizedOrigin = Vector2.Zero;

            btn.AddConstraint(Edge.CenterX, menuPanel, Edge.CenterX, ConstraintCategory.All);

            if (previousEntry != null)
            {
                btn.AddConstraint(Edge.Top, previousEntry, Edge.Bottom, -20, ConstraintCategory.All);
            }

            previousEntry = btn;
            return btn;
        }
コード例 #13
0
        private void UpdateImage(string imageName, int widthRequest, int heightRequest, UIButton targetButton)
        {
            var     assembly = typeof(App).GetTypeInfo().Assembly;
            UIImage image    = null;

            if (imageName != null)
            {
                try
                {
                    image = UIImage.FromResource(assembly, imageName);
                }
                catch (Exception)
                {
                    var path  = PCLStorage.FileSystem.Current.LocalStorage.Path;
                    var iPath = PCLStorage.PortablePath.Combine(path, imageName);
                    image = UIImage.FromFile(iPath);
                }
            }

            var imageView = new UIImageView();

            var widthCt  = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, widthRequest);
            var heightCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, heightRequest);

            imageView.AddConstraint(widthCt);
            imageView.AddConstraint(heightCt);
            imageView.TranslatesAutoresizingMaskIntoConstraints = false;
            imageView.Image       = image;
            imageView.ContentMode = UIViewContentMode.ScaleAspectFit;

            targetButton.AddSubview(imageView);

            switch (ImageButton.Orientation)
            {
            case TextAligment.Left:
            {
                targetButton.TitleEdgeInsets     = new UIEdgeInsets(0, 20, 0, 0);
                targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
            }
            break;

            case TextAligment.Top:
            {
                targetButton.TitleEdgeInsets   = new UIEdgeInsets(5, 0, 0, 0);
                targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Top;
            }
            break;

            case TextAligment.Right:
            {
                var yCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterY, 1, 0);
                var xLeftCt   = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Left, 1, 0);

                targetButton.AddConstraint(yCenterCt);
                targetButton.AddConstraint(xLeftCt);

                targetButton.TitleEdgeInsets     = new UIEdgeInsets(0, 0, 0, 20);
                targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
            }
            break;

            case TextAligment.Bottom:
            {
                var xCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterX, 1, 0);
                var yTopCt    = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Top, 1, 0);

                targetButton.AddConstraint(xCenterCt);
                targetButton.AddConstraint(yTopCt);

                targetButton.TitleEdgeInsets   = new UIEdgeInsets(0, 0, 5, 0);
                targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Bottom;
            }
            break;

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #14
0
        /// <summary>
        /// Configure this instance.
        /// </summary>
        private void configure()
        {
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.BackgroundColor     = UIColor.DarkGray;
            this.Layer.CornerRadius  = CornerRadius;
            this.Layer.MasksToBounds = true;

            IconImageView = new UIImageView();
            IconImageView.TranslatesAutoresizingMaskIntoConstraints = false;
            IconImageView.BackgroundColor = UIColor.Clear;
            IconImageView.ContentMode     = IconContentMode;

            this.AddSubview(IconImageView);

            MessageLabel = new UILabel();
            MessageLabel.TranslatesAutoresizingMaskIntoConstraints = false;
            MessageLabel.TextColor       = UIColor.White;
            MessageLabel.Font            = MessageTextFont;
            MessageLabel.BackgroundColor = UIColor.Clear;
            MessageLabel.LineBreakMode   = UILineBreakMode.CharacterWrap;
            MessageLabel.Lines           = 2;
            MessageLabel.TextAlignment   = UITextAlignment.Left;
            MessageLabel.Text            = Message;

            this.AddSubview(MessageLabel);

            ActionButton = new UIButton();
            ActionButton.TranslatesAutoresizingMaskIntoConstraints = false;
            ActionButton.Hidden          = string.IsNullOrEmpty(ActionText);
            ActionButton.BackgroundColor = UIColor.Clear;
            ActionButton.TitleLabel.Font = ActionTextFont;
            ActionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            ActionButton.SetTitle(ActionText, UIControlState.Normal);
            ActionButton.SetTitleColor(ActionTextColor, UIControlState.Normal);
            ActionButton.TouchUpInside += (s, e) =>
            {
                if (!ActionButton.Hidden && ActionButton.Title(UIControlState.Normal) != String.Empty && ActionButton != null)
                {
                    ActionBlock(this);
                    dismissAnimated(true);
                }
            };

            this.AddSubview(ActionButton);

            SecondActionButton = new UIButton();
            SecondActionButton.TranslatesAutoresizingMaskIntoConstraints = false;
            SecondActionButton.BackgroundColor = UIColor.Clear;
            SecondActionButton.TitleLabel.Font = SecondActionTextFont;
            SecondActionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            SecondActionButton.SetTitle(SecondActionText, UIControlState.Normal);
            SecondActionButton.SetTitleColor(SecondActionTextColor, UIControlState.Normal);
            SecondActionButton.TouchUpInside += (s, e) =>
            {
                if (!SecondActionButton.Hidden && SecondActionButton.Title(UIControlState.Normal) != String.Empty && SecondActionBlock != null)
                {
                    SecondActionBlock(this);
                    dismissAnimated(true);
                }
            };

            this.AddSubview(SecondActionButton);

            SeperateView = new UIView();
            SeperateView.TranslatesAutoresizingMaskIntoConstraints = false;
            SeperateView.BackgroundColor = UIColor.Gray;

            this.AddSubview(SeperateView);

            ActivityIndicatorView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White);
            ActivityIndicatorView.TranslatesAutoresizingMaskIntoConstraints = false;
            ActivityIndicatorView.StopAnimating();

            this.AddSubview(ActivityIndicatorView);

            // Add constraints
            invalidateHorizontalConstraints();

            var vConstraintsForIconImageView = NSLayoutConstraint.FromVisualFormat(
                "V:|-2-[iconImageView]-2-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { IconImageView }, new NSObject[] { new NSString("iconImageView") })
                );

            var vConstraintsForMessageLabel = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[messageLabel]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { MessageLabel }, new NSObject[] { new NSString("messageLabel") })
                );

            var vConstraintsForSeperateView = NSLayoutConstraint.FromVisualFormat(
                "V:|-4-[seperateView]-4-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { SeperateView }, new NSObject[] { new NSString("seperateView") })
                );

            var vConstraintsForActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[actionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { ActionButton }, new NSObject[] { new NSString("actionButton") })
                );

            var vConstraintsForSecondActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[secondActionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { SecondActionButton }, new NSObject[] { new NSString("secondActionButton") })
                );

            iconImageViewWidthConstraint = NSLayoutConstraint.Create(IconImageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarIconImageViewWidth);

            actionButtonWidthConstraint = NSLayoutConstraint.Create(ActionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            secondActionButtonWidthConstraint = NSLayoutConstraint.Create(SecondActionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            var vConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
                "V:|-2-[activityIndicatorView]-2-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { ActivityIndicatorView }, new NSObject[] { new NSString("activityIndicatorView") })
                );

            var hConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
                "H:[activityIndicatorView]-2-|",
                0,
                new NSDictionary(),
                NSDictionary.FromObjectsAndKeys(
                    new NSObject[] { ActivityIndicatorView },
                    new NSObject[] { new NSString("activityIndicatorView") })
                );

            IconImageView.AddConstraint(iconImageViewWidthConstraint);
            ActionButton.AddConstraint(actionButtonWidthConstraint);
            SecondActionButton.AddConstraint(secondActionButtonWidthConstraint);

            this.AddConstraints(hConstraints);
            this.AddConstraints(vConstraintsForIconImageView);
            this.AddConstraints(vConstraintsForMessageLabel);
            this.AddConstraints(vConstraintsForSeperateView);
            this.AddConstraints(vConstraintsForActionButton);
            this.AddConstraints(vConstraintsForSecondActionButton);
            this.AddConstraints(vConstraintsForActivityIndicatorView);
            this.AddConstraints(hConstraintsForActivityIndicatorView);
        }
コード例 #15
0
        public UIScrollBar(ScrollBarOrientation orientation = ScrollBarOrientation.Vertical)
        {
            Orientation = orientation;
            string arrowResource = string.Empty;
            Vector2 sliderSize = Vector2.Zero;

            switch (orientation)
            {
                case ScrollBarOrientation.Vertical:
                    sliderSize = new Vector2(0, 20);
                    arrowResource = "graphics/arrow_down";
                    break;

                case ScrollBarOrientation.Horizontal:
                    sliderSize = new Vector2(20, 0);
                    arrowResource = "graphics/arrow_left";
                    break;
            }

            AutoSize = false;
            scrollStep = 0.02f;
            Color = new Color(240, 240, 240);
            Alpha = 1f;
            DrawBounds = true;

            sliderBackground = new UIPanel();
            sliderBackground.Color = new Color(240, 240, 240);
            sliderBackground.Alpha = 1f;
            sliderBackground.InputMoved += sliderBackground_MouseMoved;
            sliderBackground.InputPressed += sliderBackground_MousePressed;

            slider = new UIPanel();
            slider.Color = new Color(205, 205, 205);
            slider.Alpha = 1f;
            slider.AutoSize = false;
            slider.AbsorbPointer = false;
            slider.Size = sliderSize;
            //slider.InputDown += sliderBackground_MousePressed;

            arrowA = new UIButton();
            var arrowAImg = new UIImage(arrowResource);
            arrowAImg.Color = new Color(96, 96, 96);
            arrowAImg.AddConstraint(Edge.Dock, arrowA, Edge.Dock);
            arrowA.Tag = "bla";
            arrowA.AddDecoration(arrowAImg);
            arrowA.PointedColor = new Color(190, 190, 190);
            arrowA.PressedColor = new Color(120, 120, 120);
            arrowA.HighlightZoom = false;
            arrowA.InputDown += arrowA_MouseHeld;

            arrowB = new UIButton();
            var arrowBImg = new UIImage(arrowResource);
            arrowBImg.Color = new Color(96, 96, 96);
            arrowBImg.AddConstraint(Edge.Dock, arrowB, Edge.Dock);
            arrowB.AddDecoration(arrowBImg);
            arrowB.PointedColor = new Color(190, 190, 190);
            arrowB.PressedColor = new Color(120, 120, 120);
            arrowB.HighlightZoom = false;
            arrowB.InputDown += arrowB_MouseHeld;

            switch (orientation)
            {
                case ScrollBarOrientation.Vertical:
                    arrowAImg.SpriteEffect = SpriteEffects.FlipVertically;
                    arrowA.AddConstraint(Edge.Horizontal | Edge.Top, this, Edge.Horizontal | Edge.Top);
                    arrowB.AddConstraint(Edge.Horizontal, this, Edge.Horizontal);
                    arrowB.AddConstraint(Edge.Bottom, this, Edge.Bottom);
                    sliderBackground.AddConstraint(Edge.Horizontal, this, Edge.Horizontal);
                    sliderBackground.AddConstraint(Edge.Top, arrowA, Edge.Bottom);
                    sliderBackground.AddConstraint(Edge.Bottom, arrowB, Edge.Top);
                    slider.AddConstraint(Edge.Top, sliderBackground, Edge.Top, ConstraintCategory.Initialization);
                    slider.AddConstraint(Edge.Horizontal, sliderBackground, Edge.Horizontal);
                    break;

                case ScrollBarOrientation.Horizontal:
                    arrowBImg.SpriteEffect = SpriteEffects.FlipHorizontally;
                    arrowA.AddConstraint(Edge.Vertical | Edge.Left, this, Edge.Vertical | Edge.Left);
                    arrowB.AddConstraint(Edge.Vertical, this, Edge.Vertical);
                    arrowB.AddConstraint(Edge.Right, this, Edge.Right);
                    sliderBackground.AddConstraint(Edge.Vertical, this, Edge.Vertical);
                    sliderBackground.AddConstraint(Edge.Left, arrowA, Edge.Right);
                    sliderBackground.AddConstraint(Edge.Right, arrowB, Edge.Left);
                    slider.AddConstraint(Edge.Left, sliderBackground, Edge.Left, ConstraintCategory.Initialization);
                    slider.AddConstraint(Edge.Vertical, sliderBackground, Edge.Vertical);
                    break;
            }

            AbsorbPointer = false;
            //base.AbsorbPointer = true;
            //slider.AbsorbPointer = true;
            //arrowDown.AbsorbPointer = true;
            //arrowUp.AbsorbPointer = true;
            sliderBackground.AbsorbPointer = true;

            AddChild(arrowA);
            AddChild(arrowB);
            AddChild(sliderBackground);
            AddChild(slider);
        }
コード例 #16
0
ファイル: ImageButtonRenderer.cs プロジェクト: NamXH/Orchard
        private void UpdateImage(string imageName, int widthRequest, int heightRequest, UIButton targetButton)
        {
            var assembly = typeof(App).GetTypeInfo().Assembly;
            UIImage image = null;
            if (imageName != null)
            {
                try
                {
                    image = UIImage.FromResource(assembly, imageName);
                }
                catch (Exception)
                {
                    var path = PCLStorage.FileSystem.Current.LocalStorage.Path;
                    var iPath = PCLStorage.PortablePath.Combine(path, imageName);
                    image = UIImage.FromFile(iPath);
                }
            }

            var imageView = new UIImageView();

            var widthCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, widthRequest);
            var heightCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, heightRequest);

            imageView.AddConstraint(widthCt);
            imageView.AddConstraint(heightCt);
            imageView.TranslatesAutoresizingMaskIntoConstraints = false;
            imageView.Image = image;
            imageView.ContentMode = UIViewContentMode.ScaleAspectFit;

            targetButton.AddSubview(imageView);

            switch (ImageButton.Orientation)
            {
                case TextAligment.Left:
                    {
                        targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 20, 0, 0);
                        targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
                    }
                    break;
                case TextAligment.Top:
                    {
                        targetButton.TitleEdgeInsets = new UIEdgeInsets(5, 0, 0, 0);
                        targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Top;
                    }
                    break;
                case TextAligment.Right:
                    {
                        var yCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterY, 1, 0);
                        var xLeftCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Left, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Left, 1, 0);

                        targetButton.AddConstraint(yCenterCt);
                        targetButton.AddConstraint(xLeftCt);

                        targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 0, 0, 20);
                        targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
                    }
                    break;
                case TextAligment.Bottom:
                    {
                        var xCenterCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.CenterX, 1, 0);
                        var yTopCt = NSLayoutConstraint.Create(imageView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, targetButton, NSLayoutAttribute.Top, 1, 0);

                        targetButton.AddConstraint(xCenterCt);
                        targetButton.AddConstraint(yTopCt);

                        targetButton.TitleEdgeInsets = new UIEdgeInsets(0, 0, 5, 0);
                        targetButton.VerticalAlignment = UIControlContentVerticalAlignment.Bottom;
                    }
                    break;
                default:
                    throw new InvalidOperationException();
            }
        }
コード例 #17
0
        /**
         * Init configuration.
         */
        private void configure()
        {
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.BackgroundColor     = UIColor.DarkGray;
            this.Layer.CornerRadius  = CornerRadius;
            this.Layer.MasksToBounds = true;

            messageLabel = new UILabel();
            messageLabel.TranslatesAutoresizingMaskIntoConstraints = false;
            messageLabel.TextColor       = UIColor.White;
            messageLabel.Font            = MessageTextFont;
            messageLabel.BackgroundColor = UIColor.Clear;
            messageLabel.LineBreakMode   = UILineBreakMode.CharacterWrap;
            messageLabel.Lines           = 2;
            messageLabel.TextAlignment   = UITextAlignment.Left;
            messageLabel.Text            = Message;

            this.AddSubview(messageLabel);

            actionButton = new UIButton();
            actionButton.TranslatesAutoresizingMaskIntoConstraints = false;
            actionButton.BackgroundColor = UIColor.Clear;
            actionButton.TitleLabel.Font = ActionTextFont;
            actionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            actionButton.SetTitle(ActionText, UIControlState.Normal);
            actionButton.SetTitleColor(ActionTextColor, UIControlState.Normal);
            actionButton.TouchUpInside += (s, e) => doAction(actionButton);

            this.AddSubview(actionButton);

            secondActionButton = new UIButton();
            secondActionButton.TranslatesAutoresizingMaskIntoConstraints = false;
            secondActionButton.BackgroundColor = UIColor.Clear;
            secondActionButton.TitleLabel.Font = SecondActionTextFont;
            secondActionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            secondActionButton.SetTitle(SecondActionText, UIControlState.Normal);
            secondActionButton.SetTitleColor(SecondActionTextColor, UIControlState.Normal);
            secondActionButton.TouchUpInside += (s, e) => doAction(secondActionButton);

            this.AddSubview(secondActionButton);

            seperateView = new UIView();
            seperateView.TranslatesAutoresizingMaskIntoConstraints = false;
            seperateView.BackgroundColor = UIColor.Gray;

            this.AddSubview(seperateView);

            activityIndicatorView = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.White);
            activityIndicatorView.TranslatesAutoresizingMaskIntoConstraints = false;
            activityIndicatorView.StopAnimating();

            this.AddSubview(activityIndicatorView);

            // Add constraints
            var hConstraints = NSLayoutConstraint.FromVisualFormat(
                "H:|-4-[messageLabel]-2-[seperateView(0.5)]-2-[actionButton]-0-[secondActionButton]-4-|",
                0, new NSDictionary(),
                NSDictionary.FromObjectsAndKeys(
                    new NSObject[] {
                messageLabel,
                seperateView,
                actionButton,
                secondActionButton
            }, new NSObject[] {
                new NSString("messageLabel"),
                new NSString("seperateView"),
                new NSString("actionButton"),
                new NSString("secondActionButton")
            })
                );

            var vConstraintsForMessageLabel = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[messageLabel]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { messageLabel }, new NSObject[] { new NSString("messageLabel") })
                );

            var vConstraintsForSeperateView = NSLayoutConstraint.FromVisualFormat(
                "V:|-4-[seperateView]-4-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { seperateView }, new NSObject[] { new NSString("seperateView") })
                );

            var vConstraintsForActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[actionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { actionButton }, new NSObject[] { new NSString("actionButton") })
                );

            var vConstraintsForSecondActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[secondActionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { secondActionButton }, new NSObject[] { new NSString("secondActionButton") })
                );

            actionButtonWidthConstraint = NSLayoutConstraint.Create(actionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            secondActionButtonWidthConstraint = NSLayoutConstraint.Create(secondActionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            var vConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
                "V:|-2-[activityIndicatorView]-2-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { activityIndicatorView }, new NSObject[] { new NSString("activityIndicatorView") })
                );

            //todo fix constraint
            var hConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
                //"H:[activityIndicatorView(activityIndicatorWidth)]-2-|",
                "H:[activityIndicatorView]-2-|",
                0,
                new NSDictionary(),
                NSDictionary.FromObjectsAndKeys(
                    new NSObject[] { activityIndicatorView },
                    new NSObject[] { new NSString("activityIndicatorView") })
                //NSDictionary.FromObjectsAndKeys(new NSObject[] { activityIndicatorView }, new NSObject[] {  })
                );

            actionButton.AddConstraint(actionButtonWidthConstraint);
            secondActionButton.AddConstraint(secondActionButtonWidthConstraint);

            this.AddConstraints(hConstraints);
            this.AddConstraints(vConstraintsForMessageLabel);
            this.AddConstraints(vConstraintsForSeperateView);
            this.AddConstraints(vConstraintsForActionButton);
            this.AddConstraints(vConstraintsForSecondActionButton);
            this.AddConstraints(vConstraintsForActivityIndicatorView);
            this.AddConstraints(hConstraintsForActivityIndicatorView);
        }
コード例 #18
0
        public TTGSnackbar() : base(CoreGraphics.CGRect.FromLTRB(0, 0, 320, 44))
        {
            this.TranslatesAutoresizingMaskIntoConstraints = false;
            this.BackgroundColor     = UIColor.DarkGray;
            this.Layer.CornerRadius  = 4;
            this.Layer.MasksToBounds = true;

            this.MessageLabel = new UILabel
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                TextColor       = UIColor.White,
                Font            = UIFont.SystemFontOfSize(14),
                BackgroundColor = UIColor.Clear,
                LineBreakMode   = UILineBreakMode.WordWrap,
                TextAlignment   = UITextAlignment.Left,
                Lines           = 0
            };

            this.AddSubview(this.MessageLabel);

            this.ActionButton = new UIButton
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.Clear
            };
            this.ActionButton.TitleLabel.Font = UIFont.SystemFontOfSize(14);
            this.ActionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            this.ActionButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            this.ActionButton.TouchUpInside += (s, e) =>
            {
                // there is a chance that user doesn't want to do anything here, he simply wants to dismiss
                ActionBlock?.Invoke(this);
                Dismiss();
            };

            this.AddSubview(this.ActionButton);

            this.SecondActionButton = new UIButton
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.Clear
            };
            this.SecondActionButton.TitleLabel.Font = UIFont.BoldSystemFontOfSize(14);
            this.SecondActionButton.TitleLabel.AdjustsFontSizeToFitWidth = true;
            this.SecondActionButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            this.SecondActionButton.TouchUpInside += (s, e) =>
            {
                SecondActionBlock?.Invoke(this);
                Dismiss();
            };

            this.AddSubview(this.SecondActionButton);

            this.seperateView = new UIView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                BackgroundColor = UIColor.Gray
            };

            this.AddSubview(this.seperateView);

            // Add constraints
            var hConstraints = NSLayoutConstraint.FromVisualFormat(
                "H:|-4-[messageLabel]-2-[seperateView(0.5)]-2-[actionButton]-0-[secondActionButton]-4-|",
                0,
                new NSDictionary(),
                NSDictionary.FromObjectsAndKeys(
                    new NSObject[] {
                MessageLabel,
                seperateView,
                ActionButton,
                SecondActionButton
            },
                    new NSObject[] {
                new NSString("messageLabel"),
                new NSString("seperateView"),
                new NSString("actionButton"),
                new NSString("secondActionButton")
            }
                    )
                );

            var vConstraintsForMessageLabel = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[messageLabel]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject [] { MessageLabel }, new NSObject [] { new NSString("messageLabel") })
                );

            var vConstraintsForSeperateView = NSLayoutConstraint.FromVisualFormat(
                "V:|-4-[seperateView]-4-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject [] { seperateView }, new NSObject [] { new NSString("seperateView") })
                );

            var vConstraintsForActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[actionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject [] { ActionButton }, new NSObject [] { new NSString("actionButton") })
                );

            var vConstraintsForSecondActionButton = NSLayoutConstraint.FromVisualFormat(
                "V:|-0-[secondActionButton]-0-|", 0, new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject [] { SecondActionButton }, new NSObject [] { new NSString("secondActionButton") })
                );

            actionButtonWidthConstraint = NSLayoutConstraint.Create(ActionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            secondActionButtonWidthConstraint = NSLayoutConstraint.Create(SecondActionButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, TTGSnackbar.snackbarActionButtonMinWidth);

            //var vConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
            //"V:|-2-[activityIndicatorView]-2-|", 0,new NSDictionary(), NSDictionary.FromObjectsAndKeys(new NSObject[] { activityIndicatorView }, new NSObject[] { new NSString("activityIndicatorView") })
            //);

            //todo fix constraint
            //var hConstraintsForActivityIndicatorView = NSLayoutConstraint.FromVisualFormat(
            //  //"H:[activityIndicatorView(activityIndicatorWidth)]-2-|",
            //  "H:[activityIndicatorView]-2-|",
            //  0,
            //  new NSDictionary(),
            //  NSDictionary.FromObjectsAndKeys(
            //      new NSObject[] {  activityIndicatorView },
            //                 new NSObject[] {  new NSString("activityIndicatorView") })
            //  //NSDictionary.FromObjectsAndKeys(new NSObject[] { activityIndicatorView }, new NSObject[] {  })
            //);

            ActionButton.AddConstraint(actionButtonWidthConstraint);
            SecondActionButton.AddConstraint(secondActionButtonWidthConstraint);

            this.AddConstraints(hConstraints);
            this.AddConstraints(vConstraintsForMessageLabel);
            this.AddConstraints(vConstraintsForSeperateView);
            this.AddConstraints(vConstraintsForActionButton);
            this.AddConstraints(vConstraintsForSecondActionButton);
            //this.AddConstraints(vConstraintsForActivityIndicatorView);
            //this.AddConstraints(hConstraintsForActivityIndicatorView);
        }
コード例 #19
0
ファイル: UIWindow.cs プロジェクト: adamxi/SharpDXFramework
        public UIWindow()
        {
            AutoSize = false;
            Alpha = 0f;
            MinimumSize = new Vector2(200);
            Size = new Vector2(350, 250);
            TopPanel = new UIPanel();
            BodyPanel = new UIPanel();
            BottomPanel = new UIPanel();

            // Top panel
            TopPanel.AddConstraint(Edge.Top, this, Edge.Top);
            TopPanel.AddConstraint(Edge.Horizontal, this, Edge.Horizontal);
            TopPanel.Color = Color.White;
            TopPanel.Alpha = 1f;
            TopPanel.Tag = nameof(TopPanel);
            TopPanel.InputMoved += TopPanel_InputMoved;
            TopPanel.InputReleasedAnywhere += TopPanel_InputReleasedAnywhere;

            titleLabel = new UILabel(nameof(UIWindow));
            titleLabel.AddConstraint(Edge.Top, TopPanel, Edge.Top);
            titleLabel.AddConstraint(Edge.Left, TopPanel, Edge.Left, 5);
            titleLabel.Tag = "Titel label";
            TopPanel.AddChild(titleLabel);

            btn_close = new UIButton();
            btn_close.InputEnter += btn_close_InputEnter;
            btn_close.InputLeave += btn_close_InputLeave;
            btn_close.AddDecoration(new UIImage("graphics/btn_close") { Color = Color.Black });
            btn_close.AddConstraint(Edge.TopRight, TopPanel, Edge.TopRight);
            btn_close.HighlightZoom = false;
            btn_close.InputReleased += Btn_close_InputReleased;
            TopPanel.AddChild(btn_close);

            btn_maximize = new UIButton();
            btn_maximize.Color = Color.Transparent;
            btn_maximize.PointedColor = new Color(190, 190, 190);
            btn_maximize.PressedColor = new Color(120, 120, 120);
            btn_maximize.PointedAlpha = 0.5f;
            btn_maximize.PressedAlpha = 0.5f;
            btn_maximize.AddDecoration(new UIImage(RESOURCE_MAXIMIZE) { Color = Color.Black });
            btn_maximize.AddConstraint(Edge.Top, btn_close, Edge.Top);
            btn_maximize.AddConstraint(Edge.Right, btn_close, Edge.Left, -1);
            btn_maximize.HighlightZoom = false;
            btn_maximize.InputReleased += Btn_maximize_InputReleased;
            TopPanel.AddChild(btn_maximize);

            btn_minimize = new UIButton();
            btn_minimize.Color = Color.Transparent;
            btn_minimize.PointedColor = new Color(190, 190, 190);
            btn_minimize.PressedColor = new Color(120, 120, 120);
            btn_minimize.PointedAlpha = 0.5f;
            btn_minimize.PressedAlpha = 0.5f;
            btn_minimize.AddDecoration(new UIImage("graphics/btn_minimize") { Color = Color.Black });
            btn_minimize.AddConstraint(Edge.Top, btn_maximize, Edge.Top);
            btn_minimize.AddConstraint(Edge.Right, btn_maximize, Edge.Left, -1);
            btn_minimize.HighlightZoom = false;
            btn_minimize.InputReleased += Btn_minimize_InputReleased;
            TopPanel.AddChild(btn_minimize);

            // Body panel
            BodyPanel.AddConstraint(Edge.Top, TopPanel, Edge.Bottom);
            BodyPanel.AddConstraint(Edge.Horizontal, this, Edge.Horizontal);
            BodyPanel.AddConstraint(Edge.Bottom, BottomPanel, Edge.Top);
            //BodyPanel.Color = Color.White;
            //BodyPanel.Alpha = 1f;
            BodyPanel.Tag = nameof(BodyPanel);

            // Bottom panel
            BottomPanel.AddConstraint(Edge.Bottom, this, Edge.Bottom);
            BottomPanel.AddConstraint(Edge.Horizontal, this, Edge.Horizontal);
            BottomPanel.Color = Color.White;
            BottomPanel.Alpha = 1f;
            BottomPanel.Tag = nameof(BottomPanel);
            BottomPanel.Size = new Vector2(0, 20);

            // Resize grip
            ResizeGrip = new UIImage("graphics/resizeGrip");
            ResizeGrip.Color = Color.Black;
            ResizeGrip.AddConstraint(Edge.BottomRight, BottomPanel, Edge.BottomRight);
            ResizeGrip.Tag = nameof(ResizeGrip);
            ResizeGrip.InputPressed += ResizeGrip_InputPressed;
            ResizeGrip.InputReleasedAnywhere += ResizeGrip_InputReleasedAnywhere;
            BottomPanel.AddChild(ResizeGrip);

            AddChild(TopPanel);
            AddChild(BodyPanel);
            AddChild(BottomPanel);

            Resizable = true;
        }