mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Initial commit. Made all calls to AnchorEnd() be AnchorEnd(0) in prep
This commit is contained in:
@@ -125,20 +125,35 @@
|
||||
public class Pos
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Pos"/> object that is anchored to the end (right side or bottom) of the dimension, useful
|
||||
/// to flush the layout from the right or bottom.
|
||||
/// Creates a <see cref="Pos"/> object that has its end (right side or bottom) anchored to the end (right side or
|
||||
/// bottom)
|
||||
/// of the SuperView, useful to flush the layout from the right or bottom.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
|
||||
/// <example>
|
||||
/// This sample shows how align a <see cref="Button"/> to the bottom-right the SuperView.
|
||||
/// <code>
|
||||
/// anchorButton.X = Pos.AnchorEnd (0);
|
||||
/// anchorButton.Y = Pos.AnchorEnd (0);
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static Pos AnchorEnd () { return new PosAnchorEnd (0); }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Pos"/> object that is anchored to the end (right side or bottom) of the SuperView,
|
||||
/// useful to flush the layout from the right or bottom.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Pos"/> object anchored to the end (the bottom or the right side).</returns>
|
||||
/// <param name="offset">The view will be shifted left or up by the amount specified.</param>
|
||||
/// <example>
|
||||
/// This sample shows how align a <see cref="Button"/> to the bottom-right of a <see cref="View"/>.
|
||||
/// <code>
|
||||
/// // See Issue #502
|
||||
/// anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
|
||||
/// anchorButton.Y = Pos.AnchorEnd (1);
|
||||
/// This sample shows how align a <see cref="Button"/> such that its left side is offset 10 columns from
|
||||
/// the right edge of the SuperView.
|
||||
/// <code>
|
||||
/// anchorButton.X = Pos.AnchorEnd (10);
|
||||
/// anchorButton.Y = 1
|
||||
/// </code>
|
||||
/// </example>
|
||||
public static Pos AnchorEnd (int offset = 0)
|
||||
public static Pos AnchorEnd (int offset)
|
||||
{
|
||||
if (offset < 0)
|
||||
{
|
||||
|
||||
@@ -44,20 +44,20 @@ public class ColorPickers : Scenario
|
||||
backgroundColorPicker = new ColorPicker
|
||||
{
|
||||
Title = "Background Color",
|
||||
// TODO: Replace with Pos.AnchorEnd () when #2900 is done
|
||||
// TODO: Replace with Pos.AnchorEnd (0) when #2900 is done
|
||||
X = Pos.AnchorEnd ((8 * 4) + 2), // 8 box * 4 width + 2 for border
|
||||
BoxHeight = 1,
|
||||
BoxWidth = 4,
|
||||
BorderStyle = LineStyle.Single
|
||||
};
|
||||
|
||||
//backgroundColorPicker.X = Pos.AnchorEnd () - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
|
||||
//backgroundColorPicker.X = Pos.AnchorEnd (0) - (Pos.Right (backgroundColorPicker) - Pos.Left (backgroundColorPicker));
|
||||
backgroundColorPicker.ColorChanged += BackgroundColor_ColorChanged;
|
||||
Win.Add (backgroundColorPicker);
|
||||
_backgroundColorLabel = new Label ();
|
||||
|
||||
_backgroundColorLabel.X =
|
||||
Pos.AnchorEnd () - (Pos.Right (_backgroundColorLabel) - Pos.Left (_backgroundColorLabel));
|
||||
Pos.AnchorEnd (0) - (Pos.Right (_backgroundColorLabel) - Pos.Left (_backgroundColorLabel));
|
||||
_backgroundColorLabel.Y = Pos.Bottom (backgroundColorPicker) + 1;
|
||||
Win.Add (_backgroundColorLabel);
|
||||
|
||||
|
||||
@@ -316,8 +316,8 @@ public class ComputedLayout : Scenario
|
||||
Top.Add (oddballButton);
|
||||
|
||||
// Demonstrate AnchorEnd - Button is anchored to bottom/right
|
||||
var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd () - 1 };
|
||||
anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
|
||||
var anchorButton = new Button { Text = "Button using AnchorEnd", Y = Pos.AnchorEnd (0) - 1 };
|
||||
anchorButton.X = Pos.AnchorEnd (0) - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
|
||||
|
||||
anchorButton.Accept += (s, e) =>
|
||||
{
|
||||
@@ -362,7 +362,7 @@ public class ComputedLayout : Scenario
|
||||
// Show positioning vertically using Pos.AnchorEnd via Pos.Combine
|
||||
var leftButton = new Button
|
||||
{
|
||||
Text = "Left", Y = Pos.AnchorEnd () - 1 // Pos.Combine
|
||||
Text = "Left", Y = Pos.AnchorEnd (0) - 1 // Pos.Combine
|
||||
};
|
||||
|
||||
leftButton.Accept += (s, e) =>
|
||||
|
||||
@@ -604,7 +604,7 @@ public class DynamicMenuBar : Scenario
|
||||
|
||||
var _btnRemoveMenuBar = new Button { Y = 1, Text = "Remove a MenuBar" };
|
||||
|
||||
_btnRemoveMenuBar.X = Pos.AnchorEnd () - (Pos.Right (_btnRemoveMenuBar) - Pos.Left (_btnRemoveMenuBar));
|
||||
_btnRemoveMenuBar.X = Pos.AnchorEnd (0) - (Pos.Right (_btnRemoveMenuBar) - Pos.Left (_btnRemoveMenuBar));
|
||||
_frmMenu.Add (_btnRemoveMenuBar);
|
||||
|
||||
var _btnPrevious = new Button
|
||||
@@ -614,7 +614,7 @@ public class DynamicMenuBar : Scenario
|
||||
_frmMenu.Add (_btnPrevious);
|
||||
|
||||
var _btnAdd = new Button { Y = Pos.Top (_btnPrevious) + 2, Text = " Add " };
|
||||
_btnAdd.X = Pos.AnchorEnd () - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
|
||||
_btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
|
||||
_frmMenu.Add (_btnAdd);
|
||||
|
||||
var _btnNext = new Button { X = Pos.X (_btnAdd), Y = Pos.Top (_btnPrevious), Text = ">" };
|
||||
|
||||
@@ -371,11 +371,11 @@ public class DynamicStatusBar : Scenario
|
||||
|
||||
var _btnRemoveStatusBar = new Button { Y = 1, Text = "Remove a StatusBar" };
|
||||
|
||||
_btnRemoveStatusBar.X = Pos.AnchorEnd () - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
|
||||
_btnRemoveStatusBar.X = Pos.AnchorEnd (0) - (Pos.Right (_btnRemoveStatusBar) - Pos.Left (_btnRemoveStatusBar));
|
||||
_frmStatusBar.Add (_btnRemoveStatusBar);
|
||||
|
||||
var _btnAdd = new Button { Y = Pos.Top (_btnRemoveStatusBar) + 2, Text = " Add " };
|
||||
_btnAdd.X = Pos.AnchorEnd () - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
|
||||
_btnAdd.X = Pos.AnchorEnd (0) - (Pos.Right (_btnAdd) - Pos.Left (_btnAdd));
|
||||
_frmStatusBar.Add (_btnAdd);
|
||||
|
||||
_lstItems = new ListView
|
||||
|
||||
@@ -122,10 +122,10 @@ public class Scrolling : Scenario
|
||||
);
|
||||
|
||||
// Demonstrate AnchorEnd - Button is anchored to bottom/right
|
||||
var anchorButton = new Button { Y = Pos.AnchorEnd () - 1, Text = "Bottom Right" };
|
||||
var anchorButton = new Button { Y = Pos.AnchorEnd (0) - 1, Text = "Bottom Right" };
|
||||
|
||||
// TODO: Use Pos.Width instead of (Right-Left) when implemented (#502)
|
||||
anchorButton.X = Pos.AnchorEnd () - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
|
||||
anchorButton.X = Pos.AnchorEnd (0) - (Pos.Right (anchorButton) - Pos.Left (anchorButton));
|
||||
|
||||
anchorButton.Accept += (s, e) =>
|
||||
{
|
||||
|
||||
@@ -200,7 +200,7 @@ public class ViewExperiments : Scenario
|
||||
view.Add (edit);
|
||||
|
||||
edit = new TextField { Text = "AnchorEnd[Right];AnchorEnd (1)", Y = Pos.AnchorEnd (1), Width = 30, Height = 1 };
|
||||
edit.X = Pos.AnchorEnd () - (Pos.Right (edit) - Pos.Left (edit));
|
||||
edit.X = Pos.AnchorEnd (0) - (Pos.Right (edit) - Pos.Left (edit));
|
||||
view.Add (edit);
|
||||
|
||||
edit = new TextField
|
||||
|
||||
@@ -207,7 +207,7 @@ public class WindowsAndFrameViews : Scenario
|
||||
new CheckBox { X = 0, Y = Pos.AnchorEnd (1), Text = "Btn1 (Y = Pos.AnchorEnd (1))" }
|
||||
);
|
||||
var c = new CheckBox { Y = Pos.AnchorEnd (1), Text = "Btn2 (Y = Pos.AnchorEnd (1))" };
|
||||
c.X = Pos.AnchorEnd () - (Pos.Right (c) - Pos.Left (c));
|
||||
c.X = Pos.AnchorEnd (0) - (Pos.Right (c) - Pos.Left (c));
|
||||
frame.Add (c);
|
||||
|
||||
frame.Add (subFrameViewofFV);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class PosTests
|
||||
public void AnchorEnd_SetsValue ()
|
||||
{
|
||||
var n = 0;
|
||||
Pos pos = Pos.AnchorEnd ();
|
||||
Pos pos = Pos.AnchorEnd (0);
|
||||
Assert.Equal ($"AnchorEnd({n})", pos.ToString ());
|
||||
|
||||
n = 5;
|
||||
@@ -122,7 +122,7 @@ public class PosTests
|
||||
|
||||
int Btn_Width () { return btn?.Viewport.Width ?? 0; }
|
||||
|
||||
btn = new Button { Text = "Ok", X = Pos.AnchorEnd () - Pos.Function (Btn_Width) };
|
||||
btn = new Button { Text = "Ok", X = Pos.AnchorEnd (0) - Pos.Function (Btn_Width) };
|
||||
|
||||
var view = new View
|
||||
{
|
||||
@@ -619,7 +619,7 @@ public class PosTests
|
||||
var super = new View { Width = 10, Height = 10, Text = "super" };
|
||||
var view1 = new View { Width = 2, Height = 2, Text = "view1" };
|
||||
var view2 = new View { Width = 2, Height = 2, Text = "view2" };
|
||||
view2.X = Pos.AnchorEnd () - (Pos.Right (view2) - Pos.Left (view2));
|
||||
view2.X = Pos.AnchorEnd (0) - (Pos.Right (view2) - Pos.Left (view2));
|
||||
|
||||
super.Add (view1, view2);
|
||||
super.BeginInit ();
|
||||
|
||||
@@ -405,7 +405,7 @@ public class SetRelativeLayoutTests
|
||||
{
|
||||
var screen = new Size (30, 1);
|
||||
var view = new View { Text = "abc", AutoSize = true }; // BUGBUG: AutoSize or Width must be set
|
||||
view.X = Pos.AnchorEnd () - Pos.Function (GetViewWidth);
|
||||
view.X = Pos.AnchorEnd (0) - Pos.Function (GetViewWidth);
|
||||
|
||||
int GetViewWidth () { return view.Frame.Width; }
|
||||
|
||||
|
||||
@@ -164,8 +164,8 @@ public class ButtonTests (ITestOutputHelper output)
|
||||
var btn = new Button { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
|
||||
var btnTxt = $"{CM.Glyphs.LeftBracket} {btn.Text} {CM.Glyphs.RightBracket}";
|
||||
|
||||
btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
|
||||
btn.X = Pos.AnchorEnd () - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
|
||||
btn.X = Pos.AnchorEnd (0) - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
|
||||
btn.X = Pos.AnchorEnd (0) - Pos.Function (() => btn.TextFormatter.Text.GetColumns ());
|
||||
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (btn);
|
||||
|
||||
@@ -77,7 +77,7 @@ public class CheckBoxTests
|
||||
{
|
||||
var checkBox = new CheckBox { Y = Pos.Center (), Text = "C_heck this out 你" };
|
||||
|
||||
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
|
||||
checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
|
||||
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
|
||||
win.Add (checkBox);
|
||||
@@ -121,7 +121,7 @@ public class CheckBoxTests
|
||||
{
|
||||
var checkBox = new CheckBox { Y = Pos.Center (), Text = "Check this out 你" };
|
||||
|
||||
checkBox.X = Pos.AnchorEnd () - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
|
||||
checkBox.X = Pos.AnchorEnd (0) - Pos.Function (() => checkBox.GetSizeNeededForTextWithoutHotKey ().Width);
|
||||
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill (), Title = "Test Demo 你" };
|
||||
win.Add (checkBox);
|
||||
|
||||
@@ -92,7 +92,7 @@ public class LabelTests
|
||||
public void AutoSize_Stays_True_AnchorEnd ()
|
||||
{
|
||||
var label = new Label { Y = Pos.Center (), Text = "Say Hello 你", AutoSize = true };
|
||||
label.X = Pos.AnchorEnd () - Pos.Function (() => label.TextFormatter.Text.GetColumns ());
|
||||
label.X = Pos.AnchorEnd (0) - Pos.Function (() => label.TextFormatter.Text.GetColumns ());
|
||||
|
||||
var win = new Window { Width = Dim.Fill (), Height = Dim.Fill () };
|
||||
win.Add (label);
|
||||
|
||||
Reference in New Issue
Block a user