public void PosSide_SetsValue() { string side; // used in format string var testRect = Rect.Empty; var testInt = 0; Pos pos; // Pos.Left side = "x"; testInt = 0; testRect = Rect.Empty; pos = Pos.Left(new View()); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); pos = Pos.Left(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testRect = new Rect(1, 2, 3, 4); pos = Pos.Left(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Left(win) + 0 pos = Pos.Left(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = 1; // Pos.Left(win) +1 pos = Pos.Left(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = -1; // Pos.Left(win) -1 pos = Pos.Left(new View(testRect)) - testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.X side = "x"; testInt = 0; testRect = Rect.Empty; pos = Pos.X(new View()); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); pos = Pos.X(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testRect = new Rect(1, 2, 3, 4); pos = Pos.X(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.X(win) + 0 pos = Pos.X(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = 1; // Pos.X(win) +1 pos = Pos.X(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = -1; // Pos.X(win) -1 pos = Pos.X(new View(testRect)) - testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Top side = "y"; testInt = 0; testRect = Rect.Empty; pos = Pos.Top(new View()); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); pos = Pos.Top(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testRect = new Rect(1, 2, 3, 4); pos = Pos.Top(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Top(win) + 0 pos = Pos.Top(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = 1; // Pos.Top(win) +1 pos = Pos.Top(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = -1; // Pos.Top(win) -1 pos = Pos.Top(new View(testRect)) - testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Y side = "y"; testInt = 0; testRect = Rect.Empty; pos = Pos.Y(new View()); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); pos = Pos.Y(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testRect = new Rect(1, 2, 3, 4); pos = Pos.Y(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Y(win) + 0 pos = Pos.Y(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = 1; // Pos.Y(win) +1 pos = Pos.Y(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = -1; // Pos.Y(win) -1 pos = Pos.Y(new View(testRect)) - testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Bottom side = "bottom"; testRect = Rect.Empty; testInt = 0; pos = Pos.Bottom(new View()); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); pos = Pos.Bottom(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testRect = new Rect(1, 2, 3, 4); pos = Pos.Bottom(new View(testRect)); Assert.Equal($"Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}})){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); // Pos.Bottom(win) + 0 pos = Pos.Bottom(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = 1; // Pos.Bottom(win) +1 pos = Pos.Bottom(new View(testRect)) + testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); testInt = -1; // Pos.Bottom(win) -1 pos = Pos.Bottom(new View(testRect)) - testInt; Assert.Equal($"Pos.Combine(Pos.Combine(Pos.View(side={side}, target=View()({{X={testRect.X},Y={testRect.Y},Width={testRect.Width},Height={testRect.Height}}}))+Pos.Absolute(0)){(testInt < 0 ? '-' : '+')}Pos.Absolute({testInt}))", pos.ToString()); }
public void LeftTopBottomRight_Win_ShouldNotThrow() { // Setup Fake driver (Window win, Button button) setup() { Application.Init(new FakeDriver(), new NetMainLoop(() => FakeConsole.ReadKey(true))); Application.Iteration = () => { Application.RequestStop(); }; var win = new Window("window") { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), }; Application.Top.Add(win); var button = new Button("button") { X = Pos.Center(), }; win.Add(button); return(win, button); } Application.RunState rs; void cleanup(Application.RunState rs) { // Cleanup Application.End(rs); } // Test cases: var app = setup(); app.button.Y = Pos.Left(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); app = setup(); app.button.Y = Pos.X(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); app = setup(); app.button.Y = Pos.Top(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); app = setup(); app.button.Y = Pos.Y(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); app = setup(); app.button.Y = Pos.Bottom(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); app = setup(); app.button.Y = Pos.Right(app.win); rs = Application.Begin(Application.Top); Application.Run(); cleanup(rs); }
/// <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; }