diff --git a/Terminal.Gui/Core/PosDim.cs b/Terminal.Gui/Core/PosDim.cs
index 1169fa049..c7a0c490f 100644
--- a/Terminal.Gui/Core/PosDim.cs
+++ b/Terminal.Gui/Core/PosDim.cs
@@ -52,7 +52,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Pos.PosFunc({function ()})";
+ return $"PosFunc({function ()})";
}
public override int GetHashCode () => function.GetHashCode ();
@@ -85,7 +85,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Pos.Factor({factor})";
+ return $"Factor({factor})";
}
public override int GetHashCode () => factor.GetHashCode ();
@@ -135,7 +135,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Pos.AnchorEnd(margin={n})";
+ return $"AnchorEnd({n})";
}
}
@@ -174,7 +174,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return "Pos.Center";
+ return "Center";
}
}
@@ -209,7 +209,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Pos.Absolute({n})";
+ return $"Absolute({n})";
}
internal override int Anchor (int width)
@@ -244,7 +244,7 @@ namespace Terminal.Gui {
internal class PosCombine : Pos {
internal Pos left, right;
- bool add;
+ internal bool add;
public PosCombine (bool add, Pos left, Pos right)
{
this.left = left;
@@ -264,7 +264,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Pos.Combine({left.ToString ()}{(add ? '+' : '-')}{right.ToString ()})";
+ return $"Combine({left}{(add ? '+' : '-')}{right})";
}
}
@@ -345,7 +345,7 @@ namespace Terminal.Gui {
case 3: tside = "bottom"; break;
default: tside = "unknown"; break;
}
- return $"Pos.View(side={tside}, target={Target.ToString ()})";
+ return $"View({tside},{Target})";
}
public override int GetHashCode () => Target.GetHashCode ();
@@ -442,7 +442,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Dim.DimFunc({function ()})";
+ return $"DimFunc({function ()})";
}
public override int GetHashCode () => function.GetHashCode ();
@@ -482,7 +482,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Dim.Factor(factor={factor}, remaining={remaining})";
+ return $"Factor({factor},{remaining})";
}
public override int GetHashCode () => factor.GetHashCode ();
@@ -522,7 +522,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Dim.Absolute({n})";
+ return $"Absolute({n})";
}
internal override int Anchor (int width)
@@ -541,7 +541,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Dim.Fill(margin={margin})";
+ return $"Fill({margin})";
}
internal override int Anchor (int width)
@@ -613,7 +613,7 @@ namespace Terminal.Gui {
public override string ToString ()
{
- return $"Dim.Combine({left.ToString ()}{(add ? '+' : '-')}{right.ToString ()})";
+ return $"Combine({left}{(add ? '+' : '-')}{right})";
}
}
@@ -691,7 +691,7 @@ namespace Terminal.Gui {
case 1: tside = "Width"; break;
default: tside = "unknown"; break;
}
- return $"DimView(side={tside}, target={Target.ToString ()})";
+ return $"DimView({tside},{Target})";
}
public override int GetHashCode () => Target.GetHashCode ();
diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs
index f1c7d8bd0..66e9ac9e5 100644
--- a/Terminal.Gui/Core/View.cs
+++ b/Terminal.Gui/Core/View.cs
@@ -1532,14 +1532,15 @@ namespace Terminal.Gui {
}
if (!ustring.IsNullOrEmpty (TextFormatter.Text)) {
- Clear ();
+ Rect containerBounds = GetContainerBounds ();
+ Clear (ViewToScreen (GetNeedDisplay (containerBounds)));
SetChildNeedsDisplay ();
// Draw any Text
if (TextFormatter != null) {
TextFormatter.NeedsFormat = true;
}
- TextFormatter?.Draw (ViewToScreen (Bounds), HasFocus ? GetFocusColor () : GetNormalColor (),
- HasFocus ? ColorScheme.HotFocus : GetHotNormalColor (),
+ TextFormatter?.Draw (ViewToScreen (boundsAdjustedForBorder), HasFocus ? ColorScheme.Focus : GetNormalColor (),
+ HasFocus ? ColorScheme.HotFocus : Enabled ? ColorScheme.HotNormal : ColorScheme.Disabled,
containerBounds);
}
@@ -2193,7 +2194,7 @@ namespace Terminal.Gui {
// the current Pos (View.X or View.Y)
// the current Dim (View.Width or View.Height)
(int newLocation, int newDimension) GetNewLocationAndDimension (int superviewLocation, int superviewDimension, Pos pos, Dim dim, int autosizeDimension)
- {
+ {
int newDimension, newLocation;
switch (pos) {
@@ -2207,9 +2208,21 @@ namespace Terminal.Gui {
newLocation = pos.Anchor (superviewDimension - newDimension);
break;
+ case Pos.PosCombine:
+ var combine = pos as Pos.PosCombine;
+ int left, right;
+ (left, newDimension) = GetNewLocationAndDimension (superviewLocation, superviewDimension, combine.left, dim, autosizeDimension);
+ (right, newDimension) = GetNewLocationAndDimension (superviewLocation, superviewDimension, combine.right, dim, autosizeDimension);
+ if (combine.add) {
+ newLocation = left + right;
+ } else {
+ newLocation = left - right;
+ }
+ newDimension = Math.Max (CalculateNewDimension (dim, newLocation, superviewDimension, autosizeDimension), 0);
+ break;
+
case Pos.PosAbsolute:
case Pos.PosAnchorEnd:
- case Pos.PosCombine:
case Pos.PosFactor:
case Pos.PosFunc:
case Pos.PosView:
@@ -2232,19 +2245,22 @@ namespace Terminal.Gui {
newDimension = AutoSize ? autosize : dimension;
break;
case Dim.DimCombine combine:
- int leftActW = CalculateNewDimension (combine.left, location, dimension, autosize);
- int rightActW = CalculateNewDimension (combine.right, dimension, location, autosize);
+ int leftNewDim = CalculateNewDimension (combine.left, location, dimension, autosize);
+ int rightNewDim = CalculateNewDimension (combine.right, location, dimension, autosize);
if (combine.add) {
- newDimension = leftActW + rightActW;
+ newDimension = leftNewDim + rightNewDim;
} else {
- newDimension = leftActW - rightActW;
+ newDimension = leftNewDim - rightNewDim;
}
newDimension = AutoSize && autosize > newDimension ? autosize : newDimension;
break;
+
case Dim.DimFactor factor when !factor.IsFromRemaining ():
newDimension = d.Anchor (dimension);
newDimension = AutoSize && autosize > newDimension ? autosize : newDimension;
break;
+
+ case Dim.DimFill:
default:
newDimension = Math.Max (d.Anchor (dimension - location), 0);
newDimension = AutoSize && autosize > newDimension ? autosize : newDimension;
@@ -2442,7 +2458,7 @@ namespace Terminal.Gui {
// return L (a topologically sorted order)
return result;
} // TopologicalSort
-
+
var ordered = TopologicalSort (nodes, edges);
foreach (var v in ordered) {
diff --git a/UICatalog/Scenario.cs b/UICatalog/Scenario.cs
index e26ce2911..ae06c151c 100644
--- a/UICatalog/Scenario.cs
+++ b/UICatalog/Scenario.cs
@@ -186,8 +186,8 @@ namespace UICatalog {
}
///
- /// Runs the . Override to start the using a different than `Top`.
- ///
+ /// Runs the . Override to start the
+ /// using a different than `Top`.
///
///
/// Overrides that do not call the base., must call before returning.
diff --git a/UICatalog/Scenarios/ComputedLayout.cs b/UICatalog/Scenarios/ComputedLayout.cs
index 5c061fbe3..c0954375f 100644
--- a/UICatalog/Scenarios/ComputedLayout.cs
+++ b/UICatalog/Scenarios/ComputedLayout.cs
@@ -17,28 +17,31 @@ namespace UICatalog.Scenarios {
[ScenarioCategory ("Layout")]
public class ComputedLayout : Scenario {
+ public override void Init (ColorScheme colorScheme)
+ {
+ Application.Init ();
+ Application.Top.ColorScheme = colorScheme;
+ }
+
public override void Setup ()
{
- var statusBar = new StatusBar (new StatusItem [] {
- new StatusItem(Key.CtrlMask | Key.Q, "~^Q~ Quit", () => Quit()),
- });
- Application.Top.Add (statusBar);
-
// Demonstrate using Dim to create a horizontal ruler that always measures the parent window's width
const string rule = "|123456789";
var horizontalRuler = new Label ("") {
+ AutoSize = false,
X = 0,
Y = 0,
Width = Dim.Fill (),
ColorScheme = Colors.Error
};
- Win.Add (horizontalRuler);
+ Application.Top.Add (horizontalRuler);
// Demonstrate using Dim to create a vertical ruler that always measures the parent window's height
const string vrule = "|\n1\n2\n3\n4\n5\n6\n7\n8\n9\n";
var verticalRuler = new Label ("") {
+ AutoSize = false,
X = 0,
Y = 0,
Width = 1,
@@ -46,36 +49,37 @@ namespace UICatalog.Scenarios {
ColorScheme = Colors.Error
};
- Win.LayoutComplete += (a) => {
+ Application.Top.LayoutComplete += (a) => {
horizontalRuler.Text = rule.Repeat ((int)Math.Ceiling ((double)(horizontalRuler.Bounds.Width) / (double)rule.Length)) [0..(horizontalRuler.Bounds.Width)];
- verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height * 2)];
+ verticalRuler.Text = vrule.Repeat ((int)Math.Ceiling ((double)(verticalRuler.Bounds.Height * 2) / (double)rule.Length)) [0..(verticalRuler.Bounds.Height*2)];
};
- Win.Add (verticalRuler);
+ Application.Top.Add (verticalRuler);
// Demonstrate At - Using Pos.At to locate a view in an absolute location
var atButton = new Button ("At(2,1)") {
X = Pos.At (2),
Y = Pos.At (1)
};
- Win.Add (atButton);
+ Application.Top.Add (atButton);
// Throw in a literal absolute - Should funciton identically to above
var absoluteButton = new Button ("X = 30, Y = 1") {
X = 30,
Y = 1
};
- Win.Add (absoluteButton);
+ Application.Top.Add (absoluteButton);
// Demonstrate using Dim to create a window that fills the parent with a margin
int margin = 10;
- var subWin = new Window ($"Centered Window with {margin} character margin") {
+ var subWin = new Window () {
X = Pos.Center (),
Y = 2,
Width = Dim.Fill (margin),
Height = 7
};
- Win.Add (subWin);
+ subWin.Title = $"{subWin.GetType().Name} {{X={subWin.X},Y={subWin.Y},Width={subWin.Width},Height={subWin.Height}}}";
+ Application.Top.Add (subWin);
int i = 1;
string txt = "Resize the terminal to see computed layout in action.";
@@ -88,13 +92,13 @@ namespace UICatalog.Scenarios {
subWin.Add (labelList.ToArray ());
// #522 repro?
- var frameView = new FrameView ($"Centered FrameView with {margin} character margin") {
- X = Pos.Center (),
+ var frameView = new FrameView () {
+ X = 2, //Pos.Center (),
Y = Pos.Bottom (subWin),
- Width = Dim.Fill (margin),
+ Width = 30,
Height = 7
};
- Win.Add (frameView);
+ frameView.Title = $"{frameView.GetType ().Name} {{X={frameView.X},Y={frameView.Y},Width={frameView.Width},Height={frameView.Height}}}";
i = 1;
labelList = new List