コード例 #1
0
        // bool registerCallbackToParent = false;

        public VisualWindow()
        {
            this.StyleBorderRadius(4, 4, 4, 4);
            this.StyleBorderWidth(1, 1, 2, 2);
            Color borderColor = new Color32(58, 121, 187, 255);

            this.StyleBorderColor(Color.grey, Color.grey, borderColor, borderColor);
            Color backgroundColor = EditorGUIUtility.isProSkin
                ? new Color32(64, 64, 64, 255)
                : new Color32(184, 184, 184, 255);

            this.StyleBackgroundColor(backgroundColor);
            this.StyleMinSize(128, 32);
            this.StyleMaxSize(9999, 9999);
            this.StylePosition(Position.Absolute);
            this.AddManipulator(new UIDragger(this, true));

            this.RegisterCallback <MouseOverEvent>(RegisterParentGeometryChanged);


            headerElement      = new HorizontalLayout();
            headerElement.name = nameof(headerElement).ToUpper();
            headerElement.StyleMaxHeight(24);
            headerElement.StyleMinHeight(24);
            headerElement.StylePadding(18, 18, 4, 4);
            headerElement.StyleJustifyContent(Justify.Center);
            headerElement.RegisterCallback <MouseUpEvent>((callback) =>
            {
                if (callback.button == 2)
                {
                    this.style.width = this.style.height = StyleKeyword.Auto;
                    Repaint();
                }
            });
            base.Add(headerElement);

            labelElement      = new Label();
            labelElement.name = nameof(labelElement).ToUpper();
            name = labelElement.text = "Untitled";
            labelElement.StyleMargin(0, 0, 0, 2);
            labelElement.StyleAlignSelf(Align.Center);
            labelElement.StyleFont(FontStyle.Bold);
            headerElement.Add(labelElement);

            Image closeButton = new Image();

            closeButton.name  = nameof(closeButton).ToUpper();
            closeButton.image = EditorGUIUtility.IconContent("winbtn_win_close").image;
            closeButton.StyleSize(16, 16);
            closeButton.StyleBorderWidth(1, 0, 0, 1);
            closeButton.StyleBorderRadius(0, 0, 4, 0);
            closeButton.StyleBorderColor(borderColor);
            closeButton.StylePosition(Position.Absolute);
            closeButton.StyleAlignSelf(Align.FlexEnd);
            base.Add(closeButton);

            closeButton.RegisterCallback <MouseDownEvent>((e) => { this.StyleDisplay(DisplayStyle.None); });

            contentElement      = new VisualElement();
            contentElement.name = nameof(contentElement).ToUpper();
            contentElement.StyleMargin(0, 0, 0, 9);
            base.Add(contentElement);

            Image resizeButton = new Image();

            resizeButton.name = nameof(resizeButton).ToUpper();
            resizeButton.StyleAlignSelf(Align.FlexEnd);
            resizeButton.StylePosition(Position.Absolute);
            resizeButton.StyleSize(8, 8);
            resizeButton.StyleBorderRadius(0, 0, 0, 4);
            resizeButton.StyleBorderWidth(0, 2, 0, 2);
            resizeButton.StyleBorderColor(Color.grey);
            resizeButton.StyleRight(1);
            resizeButton.StyleBottom(1);
            base.Add(resizeButton);
            var uIResizer = new UIResizer(this);

            resizeButton.AddManipulator(uIResizer);
            uIResizer.mouseMoveAction += () =>
            {
                resizeButton.StyleRight(1);
                resizeButton.StyleBottom(1);
            };
        }
コード例 #2
0
        private void Init(string title)
        {
            this.StyleFont(FontStyle.Bold);
            this.StyleMinHeight(20);
            this.StyleBorderWidth(0, 0, 1, 0);
            Color borderColor = EditorGUIUtility.isProSkin
                ? new Color32(35, 35, 35, 255)
                : new Color32(153, 153, 153, 255);

            this.StyleBorderColor(borderColor);

            headerElement = new HorizontalLayout();
            headerElement.StyleHeight(21);
            headerElement.StyleMaxHeight(21);
            headerElement.StyleMinHeight(21);
            headerElement.StylePadding(4, 0, 0, 0);
            headerElement.StyleAlignItem(Align.Center);
            Color backgroundColor = EditorGUIUtility.isProSkin
                ? new Color32(80, 80, 80, 255)
                : new Color32(222, 222, 222, 255);

            headerElement.StyleBackgroundColor(backgroundColor);
            Color hoverBorderColor = new Color32(58, 121, 187, 255);

            headerElement.RegisterCallback <MouseEnterEvent>((evt) =>
            {
                headerElement.StyleBorderWidth(1);
                headerElement.StyleBorderColor(hoverBorderColor);
            });
            headerElement.RegisterCallback <MouseLeaveEvent>((evt) =>
            {
                headerElement.StyleBorderWidth(0);
                headerElement.StyleBorderColor(Color.clear);
            });
            base.Add(headerElement);

            contentElement = new VerticalLayout();
            contentElement.StyleDisplay(value);
            base.Add(contentElement);

            labelElement      = new Label();
            labelElement.text = title;
            headerElement.Add(labelElement);

            imageElement      = new Image();
            imageElement.name = nameof(imageElement);
            imageElement.StyleMargin(0, 4, 0, 0);
            imageElement.StyleSize(16, 16);
            headerElement.Add(imageElement);
            imageElement.SendToBack();
            imageElement.RegisterCallback <GeometryChangedEvent>((evt) =>
            {
                imageElement.StyleDisplay(imageElement.image == null ? DisplayStyle.None : DisplayStyle.Flex);
            });

            foloutImage = new Image();
            foloutImage.StyleWidth(13);
            foloutImage.StyleMargin(0, 2, 0, 0);
            foloutImage.scaleMode = ScaleMode.ScaleToFit;
            foloutImage.image     = value ? onIcon : offIcon;
            if (!EditorGUIUtility.isProSkin)
            {
                foloutImage.tintColor = Color.grey;
            }
            headerElement.Add(foloutImage);
            foloutImage.SendToBack();


            headerElement.RegisterCallback <MouseUpEvent>((evt) =>
            {
                if (evt.button == 0)
                {
                    Value = !Value;
                    evt.StopPropagation();
                }
            });
        }