Пример #1
0
        void Init(Rect frame)
        {
            contentView = new View(frame);
            vertical    = new ScrollBarView(1, 0, isVertical: true)
            {
                X      = Pos.AnchorEnd(1),
                Y      = 0,
                Width  = 1,
                Height = Dim.Fill(showHorizontalScrollIndicator ? 1 : 0)
            };
            vertical.ChangedPosition += delegate {
                ContentOffset = new Point(ContentOffset.X, vertical.Position);
            };
            vertical.Host = this;
            horizontal    = new ScrollBarView(1, 0, isVertical: false)
            {
                X      = 0,
                Y      = Pos.AnchorEnd(1),
                Width  = Dim.Fill(showVerticalScrollIndicator ? 1 : 0),
                Height = 1
            };
            horizontal.ChangedPosition += delegate {
                ContentOffset = new Point(horizontal.Position, ContentOffset.Y);
            };
            horizontal.Host = this;
            base.Add(contentView);
            CanFocus = true;

            MouseEnter             += View_MouseEnter;
            MouseLeave             += View_MouseLeave;
            contentView.MouseEnter += View_MouseEnter;
            contentView.MouseLeave += View_MouseLeave;
        }
Пример #2
0
        public void Scrolling_With_Default_Constructor_Do_Not_Scroll()
        {
            var sbv = new ScrollBarView {
                Position = 1
            };

            Assert.NotEqual(1, sbv.Position);
            Assert.Equal(0, sbv.Position);
        }
Пример #3
0
        public void Hosting_Two_Horizontal_ScrollBarView_Throws_ArgumentException()
        {
            var top  = new Toplevel();
            var host = new View();

            top.Add(host);
            var v = new ScrollBarView(host, false);
            var h = new ScrollBarView(host, false);

            Assert.Throws <ArgumentException> (null, () => v.OtherScrollBarView = h);
            Assert.Throws <ArgumentException> (null, () => h.OtherScrollBarView = v);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gui.ScrollBarView"/> class using <see cref="LayoutStyle.Computed"/> layout.
 /// </summary>
 /// <param name="host">The view that will host this scrollbar.</param>
 /// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal.</param>
 /// <param name="showBothScrollIndicator">If set to <c>true (default)</c> will have the other scrollbar, otherwise will have only one.</param>
 public ScrollBarView(View host, bool isVertical, bool showBothScrollIndicator = true) : this(0, 0, isVertical)
 {
     if (host == null)
     {
         throw new ArgumentNullException("The host parameter can't be null.");
     }
     else if (host.SuperView == null)
     {
         throw new ArgumentNullException("The host SuperView parameter can't be null.");
     }
     hosted                = true;
     ColorScheme           = host.ColorScheme;
     X                     = isVertical ? Pos.Right(host) - 1 : Pos.Left(host);
     Y                     = isVertical ? Pos.Top(host) : Pos.Bottom(host) - 1;
     Host                  = host;
     CanFocus              = host.CanFocus;
     Enabled               = host.Enabled;
     Visible               = host.Visible;
     Host.CanFocusChanged += Host_CanFocusChanged;
     Host.EnabledChanged  += Host_EnabledChanged;
     Host.VisibleChanged  += Host_VisibleChanged;
     Host.SuperView.Add(this);
     AutoHideScrollBars = true;
     if (showBothScrollIndicator)
     {
         OtherScrollBarView = new ScrollBarView(0, 0, !isVertical)
         {
             ColorScheme        = host.ColorScheme,
             Host               = host,
             CanFocus           = host.CanFocus,
             Enabled            = host.Enabled,
             Visible            = host.Visible,
             OtherScrollBarView = this
         };
         OtherScrollBarView.hosted = true;
         OtherScrollBarView.X      = OtherScrollBarView.IsVertical ? Pos.Right(host) - 1 : Pos.Left(host);
         OtherScrollBarView.Y      = OtherScrollBarView.IsVertical ? Pos.Top(host) : Pos.Bottom(host) - 1;
         OtherScrollBarView.Host.SuperView.Add(OtherScrollBarView);
         OtherScrollBarView.showScrollIndicator = true;
     }
     ShowScrollIndicator      = true;
     contentBottomRightCorner = new View(" ")
     {
         Visible = host.Visible
     };
     Host.SuperView.Add(contentBottomRightCorner);
     contentBottomRightCorner.X           = Pos.Right(host) - 1;
     contentBottomRightCorner.Y           = Pos.Bottom(host) - 1;
     contentBottomRightCorner.Width       = 1;
     contentBottomRightCorner.Height      = 1;
     contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick;
 }
Пример #5
0
        public void Hosting_A_View_To_A_ScrollBarView()
        {
            RemoveHandlers();

            _scrollBar = new ScrollBarView(_hostView, true);

            Assert.True(_scrollBar.IsVertical);
            Assert.False(_scrollBar.OtherScrollBarView.IsVertical);

            Assert.Equal(_scrollBar.Position, _hostView.Top);
            Assert.NotEqual(_scrollBar.Size, _hostView.Lines);
            Assert.Equal(_scrollBar.OtherScrollBarView.Position, _hostView.Left);
            Assert.NotEqual(_scrollBar.OtherScrollBarView.Size, _hostView.Cols);

            AddHandlers();
            _hostView.SuperView.LayoutSubviews();
            _hostView.Redraw(_hostView.Bounds);

            Assert.Equal(_scrollBar.Position, _hostView.Top);
            Assert.Equal(_scrollBar.Size, _hostView.Lines + 1);
            Assert.Equal(_scrollBar.OtherScrollBarView.Position, _hostView.Left);
            Assert.Equal(_scrollBar.OtherScrollBarView.Size, _hostView.Cols + 1);
        }
Пример #6
0
        void Initialize(Rect frame)
        {
            contentView = new View(frame);
            vertical    = new ScrollBarView(1, 0, isVertical: true)
            {
                X      = Pos.AnchorEnd(1),
                Y      = 0,
                Width  = 1,
                Height = Dim.Fill(showHorizontalScrollIndicator ? 1 : 0)
            };
            vertical.ChangedPosition += delegate {
                ContentOffset = new Point(ContentOffset.X, vertical.Position);
            };
            vertical.Host = this;
            horizontal    = new ScrollBarView(1, 0, isVertical: false)
            {
                X      = 0,
                Y      = Pos.AnchorEnd(1),
                Width  = Dim.Fill(showVerticalScrollIndicator ? 1 : 0),
                Height = 1
            };
            horizontal.ChangedPosition += delegate {
                ContentOffset = new Point(horizontal.Position, ContentOffset.Y);
            };
            horizontal.Host               = this;
            vertical.OtherScrollBarView   = horizontal;
            horizontal.OtherScrollBarView = vertical;
            base.Add(contentView);
            CanFocus = true;

            MouseEnter             += View_MouseEnter;
            MouseLeave             += View_MouseLeave;
            contentView.MouseEnter += View_MouseEnter;
            contentView.MouseLeave += View_MouseLeave;

            // Things this view knows how to do
            AddCommand(Command.ScrollUp, () => ScrollUp(1));
            AddCommand(Command.ScrollDown, () => ScrollDown(1));
            AddCommand(Command.ScrollLeft, () => ScrollLeft(1));
            AddCommand(Command.ScrollRight, () => ScrollRight(1));
            AddCommand(Command.PageUp, () => ScrollUp(Bounds.Height));
            AddCommand(Command.PageDown, () => ScrollDown(Bounds.Height));
            AddCommand(Command.PageLeft, () => ScrollLeft(Bounds.Width));
            AddCommand(Command.PageRight, () => ScrollRight(Bounds.Width));
            AddCommand(Command.TopHome, () => ScrollUp(contentSize.Height));
            AddCommand(Command.BottomEnd, () => ScrollDown(contentSize.Height));
            AddCommand(Command.LeftHome, () => ScrollLeft(contentSize.Width));
            AddCommand(Command.RightEnd, () => ScrollRight(contentSize.Width));

            // Default keybindings for this view
            AddKeyBinding(Key.CursorUp, Command.ScrollUp);
            AddKeyBinding(Key.CursorDown, Command.ScrollDown);
            AddKeyBinding(Key.CursorLeft, Command.ScrollLeft);
            AddKeyBinding(Key.CursorRight, Command.ScrollRight);

            AddKeyBinding(Key.PageUp, Command.PageUp);
            AddKeyBinding((Key)'v' | Key.AltMask, Command.PageUp);

            AddKeyBinding(Key.PageDown, Command.PageDown);
            AddKeyBinding(Key.V | Key.CtrlMask, Command.PageDown);

            AddKeyBinding(Key.PageUp | Key.CtrlMask, Command.PageLeft);
            AddKeyBinding(Key.PageDown | Key.CtrlMask, Command.PageRight);
            AddKeyBinding(Key.Home, Command.TopHome);
            AddKeyBinding(Key.End, Command.BottomEnd);
            AddKeyBinding(Key.Home | Key.CtrlMask, Command.LeftHome);
            AddKeyBinding(Key.End | Key.CtrlMask, Command.RightEnd);
        }