Skip to content

Commit

Permalink
Made Arrangement = ViewArrangement.Fixed the default for Toplevels
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Apr 15, 2024
1 parent de1a844 commit 069089e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ public void FillRect (Rectangle rect, Rune rune = default)
{
Contents [r, c] = new Cell
{
Rune = (Rune)' ', Attribute = CurrentAttribute, IsDirty = true
Rune = (rune != default ? rune : (Rune)' '),
Attribute = CurrentAttribute, IsDirty = true
};
_dirtyLines [r] = true;
}
Expand Down
1 change: 1 addition & 0 deletions Terminal.Gui/Views/Dialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public enum ButtonAlignments
/// </remarks>
public Dialog ()
{
Arrangement = ViewArrangement.Movable;
X = Pos.Center ();
Y = Pos.Center ();
ValidatePosDim = true;
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/Toplevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public partial class Toplevel : View
/// </summary>
public Toplevel ()
{
Arrangement = ViewArrangement.Movable;
Arrangement = ViewArrangement.Fixed;
Width = Dim.Fill ();
Height = Dim.Fill ();

Expand Down
1 change: 1 addition & 0 deletions UICatalog/Scenarios/Adornments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override void Main ()
var window = new Window
{
Title = "The _Window",
Arrangement = ViewArrangement.Movable,
X = Pos.Right(editor),
Width = Dim.Percent (60),
Height = Dim.Percent (80),
Expand Down
5 changes: 5 additions & 0 deletions UICatalog/Scenarios/BackgroundWorkerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private class OverlappedMain : Toplevel

public OverlappedMain ()
{
Arrangement = ViewArrangement.Movable;
Data = "OverlappedMain";

IsOverlappedContainer = true;
Expand Down Expand Up @@ -258,6 +259,8 @@ public StagingUIController (Staging staging, List<string> list) : this ()

public StagingUIController ()
{
Arrangement = ViewArrangement.Movable;

X = Pos.Center ();
Y = Pos.Center ();
Width = Dim.Percent (85);
Expand Down Expand Up @@ -338,6 +341,8 @@ private class WorkerApp : Toplevel

public WorkerApp ()
{
Arrangement = ViewArrangement.Movable;

Data = "WorkerApp";
Title = "Worker collection Log";

Expand Down
40 changes: 22 additions & 18 deletions UICatalog/Scenarios/TextFormatterDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ namespace UICatalog.Scenarios;
[ScenarioCategory ("Text and Formatting")]
public class TextFormatterDemo : Scenario
{
public override void Setup ()
public override void Main ()
{
// TODO: Move this to another Scenario that specifically tests `Views` that have no subviews.
//Top.Text = "Press CTRL-Q to Quit. This is the Text for the TopLevel View. TextAlignment.Centered was specified. It is intentionally very long to illustrate word wrap.\n" +
// "<-- There is a new line here to show a hard line break. You should see this text bleed underneath the subviews, which start at Y = 3.";
//Top.TextAlignment = TextAlignment.Centered;
//Top.ColorScheme = Colors.ColorSchemes ["Base"];
Application.Init ();

var app = new Window ()
{
Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}",
};

// Make Win smaller so sizing the window horizontally will make the
// labels shrink to zero-width
Win.X = 10;
Win.Width = Dim.Fill (10);
app.X = 10;
app.Width = Dim.Fill (10);

var text = "Hello world, how are you today? Pretty neat!\nSecond line\n\nFourth Line.";

Expand All @@ -35,7 +36,7 @@ public override void Setup ()
Y = 0,
AutoSize = false,
Height = 10,
Width = Dim.Fill ()
Width = Dim.Fill (),
};

var block = new StringBuilder ();
Expand All @@ -50,17 +51,17 @@ public override void Setup ()
block.AppendLine (" ░ ░ ░ ░ ░ ░ ░ ");
block.AppendLine (" ░ ░ ");
blockText.Text = block.ToString (); // .Replace(" ", "\u00A0"); // \u00A0 is 'non-breaking space
Win.Add (blockText);
app.Add (blockText);

var unicodeCheckBox = new CheckBox
{
X = 0,
Y = Pos.Bottom (blockText) + 1,
Text = "Unicode",
Checked = Top.HotKeySpecifier == (Rune)' '
Checked = app.HotKeySpecifier == (Rune)' '
};

Win.Add (unicodeCheckBox);
app.Add (unicodeCheckBox);

List<TextAlignment> alignments = Enum.GetValues (typeof (TextAlignment)).Cast<TextAlignment> ().ToList ();
Label [] singleLines = new Label [alignments.Count];
Expand Down Expand Up @@ -97,26 +98,26 @@ public override void Setup ()
{
Y = Pos.Bottom (unicodeCheckBox) + 1, Text = "Demonstrating multi-line and word wrap:"
};
Win.Add (label);
app.Add (label);

foreach (TextAlignment alignment in alignments)
{
label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" };
Win.Add (label);
app.Add (label);
singleLines [(int)alignment].Y = Pos.Bottom (label);
Win.Add (singleLines [(int)alignment]);
app.Add (singleLines [(int)alignment]);
label = singleLines [(int)alignment];
}

label = new Label { Y = Pos.Bottom (label), Text = "Demonstrating multi-line and word wrap:" };
Win.Add (label);
app.Add (label);

foreach (TextAlignment alignment in alignments)
{
label = new Label { Y = Pos.Bottom (label), Text = $"{alignment}:" };
Win.Add (label);
app.Add (label);
multipleLines [(int)alignment].Y = Pos.Bottom (label);
Win.Add (multipleLines [(int)alignment]);
app.Add (multipleLines [(int)alignment]);
label = multipleLines [(int)alignment];
}

Expand All @@ -128,5 +129,8 @@ public override void Setup ()
multipleLines [(int)alignment].Text = e.OldValue == true ? text : unicode;
}
};

Application.Run (app);
app.Dispose ();
}
}
6 changes: 5 additions & 1 deletion UnitTests/Application/ApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,11 @@ public void Run_A_Modal_Toplevel_Refresh_Background_On_Moving ()
Init ();

// Don't use Dialog here as it has more layout logic. Use Window instead.
var w = new Window { Width = 5, Height = 5 };
var w = new Window
{
Width = 5, Height = 5,
Arrangement = ViewArrangement.Movable
};
((FakeDriver)Application.Driver).SetBufferSize (10, 10);
RunState rs = Application.Begin (w);

Expand Down
15 changes: 8 additions & 7 deletions UnitTests/Views/ToplevelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public void Constructor_Default ()
}

[Fact]
public void Arrangement_Is_Movable ()
public void Arrangement_Default_Is_Fixed ()
{
var top = new Toplevel ();
Assert.Equal (ViewArrangement.Movable, top.Arrangement);
Assert.Equal (ViewArrangement.Fixed, top.Arrangement);
}

#if BROKE_IN_2927
Expand Down Expand Up @@ -869,7 +869,8 @@ public void Mouse_Drag_On_Top_With_Superview_Null ()
X = 2,
Y = 2,
Width = 10,
Height = 3
Height = 3,
Arrangement = ViewArrangement.Movable
};
Application.Run (testWindow);
}
Expand Down Expand Up @@ -964,7 +965,7 @@ public void Mouse_Drag_On_Top_With_Superview_Null ()
[AutoInitShutdown]
public void Mouse_Drag_On_Top_With_Superview_Not_Null ()
{
var win = new Window { X = 3, Y = 2, Width = 10, Height = 5 };
var win = new Window { X = 3, Y = 2, Width = 10, Height = 5, Arrangement = ViewArrangement.Movable };
Toplevel top = new ();
top.Add (win);

Expand Down Expand Up @@ -1331,7 +1332,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView ()
Height = 16,
ContentSize = new (200, 100)
};
var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3) };
var win = new Window { X = 3, Y = 3, Width = Dim.Fill (3), Height = Dim.Fill (3), Arrangement = ViewArrangement.Movable };
scrollView.Add (win);
Toplevel top = new ();
top.Add (scrollView);
Expand Down Expand Up @@ -1380,7 +1381,7 @@ public void Toplevel_Inside_ScrollView_MouseGrabView ()
public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_Left_Right_And_Bottom ()
{
Toplevel top = new ();
var window = new Window { Width = 20, Height = 3 };
var window = new Window { Width = 20, Height = 3, Arrangement = ViewArrangement.Movable};
RunState rsTop = Application.Begin (top);
((FakeDriver)Application.Driver).SetBufferSize (40, 10);
RunState rsWindow = Application.Begin (window);
Expand Down Expand Up @@ -1471,7 +1472,7 @@ public void Window_Viewport_Bigger_Than_Driver_Cols_And_Rows_Allow_Drag_Beyond_L
public void Modal_As_Top_Will_Drag_Cleanly ()
{
// Don't use Dialog as a Top, use a Window instead - dialog has complex layout behavior that is not needed here.
var window = new Window { Width = 10, Height = 3 };
var window = new Window { Width = 10, Height = 3, Arrangement = ViewArrangement.Movable };

window.Add (
new Label
Expand Down

0 comments on commit 069089e

Please sign in to comment.