Beispiel #1
0
        public Button(WidgetManager manager) : base(manager)
        {
            Add(label = new Label(manager)
            {
                AnchorFrom = BoxAlignment.Centre,
                AnchorTo   = BoxAlignment.Centre,
                Hoverable  = false,
            });

            clickBehavior = new ClickBehavior(this);
            clickBehavior.OnStateChanged += (sender, e) => RefreshStyle();
            clickBehavior.OnClick        += (sender, e) => Click(e.Button);
        }
Beispiel #2
0
 public Slider(WidgetManager manager) : base(manager)
 {
     OnHovered += (sender, e) =>
     {
         hovered = e.Hovered;
         if (!disabled)
         {
             RefreshStyle();
         }
     };
     OnClickDown += (sender, e) =>
     {
         if (disabled || dragged)
         {
             return(false);
         }
         dragButton = e.Button;
         dragged    = true;
         Value      = GetValueForPosition(new Vector2(e.X, e.Y));
         DragStart(dragButton);
         return(true);
     };
     OnClickUp += (sender, e) =>
     {
         if (disabled || !dragged)
         {
             return;
         }
         if (e.Button != dragButton)
         {
             return;
         }
         dragged = false;
         RefreshStyle();
         DragEnd(dragButton);
         OnValueCommited?.Invoke(this, e);
     };
     OnDrag += (sender, e) =>
     {
         if (disabled || !dragged)
         {
             return;
         }
         Value = GetValueForPosition(new Vector2(e.X, e.Y));
         DragUpdate(dragButton);
     };
 }
Beispiel #3
0
 public Image(WidgetManager manager) : base(manager)
 {
 }
 public StackLayout(WidgetManager manager) : base(manager)
 {
 }
Beispiel #5
0
 public FlowLayout(WidgetManager manager) : base(manager)
 {
 }
Beispiel #6
0
 public Widget(WidgetManager manager)
 {
     this.manager = manager;
 }
 public ProgressBar(WidgetManager manager) : base(manager)
 {
 }
Beispiel #8
0
        public Textbox(WidgetManager manager) : base(manager)
        {
            DefaultSize = new Vector2(200, 0);

            cursorLine = new Sprite()
            {
                Texture   = DrawState.WhitePixel,
                ScaleMode = ScaleMode.Fill,
                Color     = Color4.White,
            };

            Add(content = new Label(manager)
            {
                AnchorFrom = BoxAlignment.BottomLeft,
                AnchorTo   = BoxAlignment.BottomLeft,
            });
            Add(label = new Label(manager)
            {
                AnchorFrom = BoxAlignment.TopLeft,
                AnchorTo   = BoxAlignment.TopLeft,
            });

            OnFocusChange += (sender, e) =>
            {
                if (hasFocus == e.HasFocus)
                {
                    return;
                }
                if (hasFocus && hasCommitPending)
                {
                    OnValueCommited?.Invoke(this, EventArgs.Empty);
                    hasCommitPending = false;
                }

                hasFocus = e.HasFocus;
                RefreshStyle();
            };
            OnHovered += (sender, e) =>
            {
                hovered = e.Hovered;
                RefreshStyle();
            };
            OnKeyDown += (sender, e) =>
            {
                if (!hasFocus)
                {
                    return(false);
                }

                var inputManager = manager.InputManager;
                switch (e.Key)
                {
                case Key.Escape:
                    if (hasFocus)
                    {
                        manager.KeyboardFocus = null;
                    }
                    break;

                case Key.BackSpace:
                    if (selectionStart > 0 && selectionStart == cursorPosition)
                    {
                        selectionStart--;
                    }
                    ReplaceSelection("");
                    break;

                case Key.Delete:
                    if (selectionStart < Value.Length && selectionStart == cursorPosition)
                    {
                        cursorPosition++;
                    }
                    ReplaceSelection("");
                    break;

                case Key.A:
                    if (inputManager.ControlOnly)
                    {
                        SelectAll();
                    }
                    break;

                case Key.C:
                    if (inputManager.ControlOnly)
                    {
                        if (selectionStart != cursorPosition)
                        {
                            ClipboardHelper.SetText(Value.Substring(SelectionLeft, SelectionLength), System.Windows.Forms.TextDataFormat.UnicodeText);
                        }
                        else
                        {
                            ClipboardHelper.SetText(Value, System.Windows.Forms.TextDataFormat.UnicodeText);
                        }
                    }
                    break;

                case Key.V:
                    if (inputManager.ControlOnly)
                    {
                        var clipboardText = ClipboardHelper.GetText(System.Windows.Forms.TextDataFormat.UnicodeText);
                        if (clipboardText != null)
                        {
                            if (!AcceptMultiline)
                            {
                                clipboardText = clipboardText.Replace("\n", "");
                            }
                            ReplaceSelection(clipboardText);
                        }
                    }
                    break;

                case Key.X:
                    if (inputManager.ControlOnly)
                    {
                        if (selectionStart == cursorPosition)
                        {
                            SelectAll();
                        }

                        ClipboardHelper.SetText(Value.Substring(SelectionLeft, SelectionLength), System.Windows.Forms.TextDataFormat.UnicodeText);
                        ReplaceSelection("");
                    }
                    break;

                case Key.Left:
                    if (inputManager.Shift)
                    {
                        if (cursorPosition > 0)
                        {
                            cursorPosition--;
                        }
                    }
                    else if (selectionStart != cursorPosition)
                    {
                        SelectionRight = SelectionLeft;
                    }
                    else if (cursorPosition > 0)
                    {
                        cursorPosition = --selectionStart;
                    }
                    break;

                case Key.Right:
                    if (inputManager.Shift)
                    {
                        if (cursorPosition < Value.Length)
                        {
                            cursorPosition++;
                        }
                    }
                    else if (selectionStart != cursorPosition)
                    {
                        SelectionLeft = SelectionRight;
                    }
                    else if (cursorPosition < Value.Length)
                    {
                        selectionStart = ++cursorPosition;
                    }
                    break;

                case Key.Up:
                    cursorPosition = content.GetCharacterIndexAbove(cursorPosition);
                    if (!inputManager.Shift)
                    {
                        selectionStart = cursorPosition;
                    }
                    break;

                case Key.Down:
                    cursorPosition = content.GetCharacterIndexBelow(cursorPosition);
                    if (!inputManager.Shift)
                    {
                        selectionStart = cursorPosition;
                    }
                    break;

                case Key.Home:
                    cursorPosition = 0;
                    if (!inputManager.Shift)
                    {
                        selectionStart = cursorPosition;
                    }
                    break;

                case Key.End:
                    cursorPosition = Value.Length;
                    if (!inputManager.Shift)
                    {
                        selectionStart = cursorPosition;
                    }
                    break;

                case Key.Enter:
                case Key.KeypadEnter:
                    if (AcceptMultiline && (!EnterCommits || inputManager.Shift))
                    {
                        ReplaceSelection("\n");
                    }
                    else if (EnterCommits && hasCommitPending)
                    {
                        OnValueCommited?.Invoke(this, EventArgs.Empty);
                        hasCommitPending = false;
                    }
                    break;
                }
                return(true);
            };
            OnKeyUp += (sender, e) =>
            {
                return(hasFocus);
            };
            OnKeyPress += (sender, e) =>
            {
                if (!hasFocus)
                {
                    return(false);
                }
                ReplaceSelection(e.KeyChar.ToString());
                return(true);
            };
            OnClickDown += (sender, e) =>
            {
                manager.KeyboardFocus = this;
                selectionStart        = cursorPosition = content.GetCharacterIndexAt(Manager.Camera.FromScreen(new Vector2(e.X, e.Y)).Xy);
                return(true);
            };
            OnDrag += (sender, e) =>
            {
                cursorPosition = content.GetCharacterIndexAt(Manager.Camera.FromScreen(new Vector2(e.X, e.Y)).Xy);
            };
        }
Beispiel #9
0
        public ScrollArea(WidgetManager manager, Widget scrollable) : base(manager)
        {
            ClipChildren        = true;
            Add(scrollContainer = new StackLayout(manager)
            {
                FitChildren = true,
                Children    = new Widget[]
                {
                    scrollable
                },
            });
            Add(scrollIndicatorTop = new Label(manager)
            {
                StyleName  = "icon",
                Icon       = IconFont.ArrowCircleUp,
                AnchorFrom = BoxAlignment.TopRight,
                AnchorTo   = BoxAlignment.TopRight,
                Hoverable  = false,
                Opacity    = 0.6f,
            });
            Add(scrollIndicatorBottom = new Label(manager)
            {
                StyleName  = "icon",
                Icon       = IconFont.ArrowCircleDown,
                AnchorFrom = BoxAlignment.BottomRight,
                AnchorTo   = BoxAlignment.BottomRight,
                Hoverable  = false,
                Opacity    = 0.6f,
            });
            Add(scrollIndicatorLeft = new Label(manager)
            {
                StyleName  = "icon",
                Icon       = IconFont.ArrowCircleLeft,
                AnchorFrom = BoxAlignment.BottomLeft,
                AnchorTo   = BoxAlignment.BottomLeft,
                Hoverable  = false,
                Opacity    = 0.6f,
            });
            Add(scrollIndicatorRight = new Label(manager)
            {
                StyleName  = "icon",
                Icon       = IconFont.ArrowCircleRight,
                AnchorFrom = BoxAlignment.BottomRight,
                AnchorTo   = BoxAlignment.BottomRight,
                Hoverable  = false,
                Opacity    = 0.6f,
            });
            OnHovered += (sender, e) =>
            {
                hovered = e.Hovered;
                updateScrollIndicators();
            };
            OnClickDown += (sender, e) =>
            {
                if (e.Button != MouseButton.Left)
                {
                    return(false);
                }
                dragged = true;
                return(true);
            };
            OnClickUp += (sender, e) =>
            {
                if (e.Button != MouseButton.Left)
                {
                    return;
                }
                dragged = false;
            };
            OnDrag += (sender, e) =>
            {
                if (!dragged)
                {
                    return;
                }
                scroll(e.XDelta, e.YDelta);
            };
            OnMouseWheel += (sender, e) =>
            {
                if (scrollsVertically)
                {
                    scroll(0, e.DeltaPrecise * 64);
                }
                else if (scrollsHorizontally)
                {
                    scroll(e.DeltaPrecise * 64, 0);
                }
                return(true);
            };

            scrollIndicatorTop.Pack();
            scrollIndicatorBottom.Pack();
            scrollIndicatorLeft.Pack();
            scrollIndicatorRight.Pack();
            updateScrollIndicators();
        }
Beispiel #10
0
 public Label(WidgetManager manager) : base(manager)
 {
 }
 public DrawableContainer(WidgetManager manager) : base(manager)
 {
 }
Beispiel #12
0
 public LinearLayout(WidgetManager manager) : base(manager)
 {
 }