mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 16:58:01 +01:00
Initial work in progress
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -652,7 +652,7 @@ namespace Terminal.Gui {
|
||||
// the superview's width or height
|
||||
// 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 newLocation, int newDimension) GetNewLocationAndDimension (bool horiz, int superviewLocation, int superviewDimension, Pos pos, Dim dim, int autosizeDimension)
|
||||
{
|
||||
int newDimension, newLocation;
|
||||
|
||||
@@ -669,14 +669,14 @@ namespace Terminal.Gui {
|
||||
|
||||
case Pos.PosCombine combine:
|
||||
int left, right;
|
||||
(left, newDimension) = GetNewLocationAndDimension (superviewLocation, superviewDimension, combine.left, dim, autosizeDimension);
|
||||
(right, newDimension) = GetNewLocationAndDimension (superviewLocation, superviewDimension, combine.right, dim, autosizeDimension);
|
||||
(left, newDimension) = GetNewLocationAndDimension (horiz, superviewLocation, superviewDimension, combine.left, dim, autosizeDimension);
|
||||
(right, newDimension) = GetNewLocationAndDimension (horiz, 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);
|
||||
newDimension = Math.Max (CalculateNewDimension (horiz, dim, newLocation, superviewDimension, autosizeDimension), 0);
|
||||
break;
|
||||
|
||||
case Pos.PosAbsolute:
|
||||
@@ -686,7 +686,7 @@ namespace Terminal.Gui {
|
||||
case Pos.PosView:
|
||||
default:
|
||||
newLocation = pos?.Anchor (superviewDimension) ?? 0;
|
||||
newDimension = Math.Max (CalculateNewDimension (dim, newLocation, superviewDimension, autosizeDimension), 0);
|
||||
newDimension = Math.Max (CalculateNewDimension (horiz, dim, newLocation, superviewDimension, autosizeDimension), 0);
|
||||
break;
|
||||
}
|
||||
return (newLocation, newDimension);
|
||||
@@ -695,7 +695,7 @@ namespace Terminal.Gui {
|
||||
// Recursively calculates the new dimension (width or height) of the given Dim given:
|
||||
// the current location (x or y)
|
||||
// the current dimension (width or height)
|
||||
int CalculateNewDimension (Dim d, int location, int dimension, int autosize)
|
||||
int CalculateNewDimension (bool horiz, Dim d, int location, int dimension, int autosize)
|
||||
{
|
||||
int newDimension;
|
||||
switch (d) {
|
||||
@@ -703,20 +703,33 @@ namespace Terminal.Gui {
|
||||
newDimension = AutoSize ? autosize : dimension;
|
||||
break;
|
||||
case Dim.DimCombine combine:
|
||||
int leftNewDim = CalculateNewDimension (combine.left, location, dimension, autosize);
|
||||
int rightNewDim = CalculateNewDimension (combine.right, location, dimension, autosize);
|
||||
if (combine.add) {
|
||||
int leftNewDim = CalculateNewDimension (horiz, combine._left, location, dimension, autosize);
|
||||
int rightNewDim = CalculateNewDimension (horiz, combine._right, location, dimension, autosize);
|
||||
if (combine._add) {
|
||||
newDimension = leftNewDim + rightNewDim;
|
||||
} else {
|
||||
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.DimAutoSize:
|
||||
var thickness = GetFramesThickness ();
|
||||
if (horiz) {
|
||||
var furthestLeft = Subviews.Where (v => v.Frame.X >= 0).Min (v => v.Frame.X);
|
||||
var furthestRight = Subviews.Where (v => v.Frame.X >= 0).Max (v => v.Frame.X + v.Frame.Width);
|
||||
newDimension = furthestLeft + furthestRight + thickness.Left + thickness.Right;
|
||||
} else {
|
||||
var furthestTop = Subviews.Where (v => v.Frame.Y >= 0).Min (v => v.Frame.Y);
|
||||
var furthestBottom = Subviews.Where (v => v.Frame.Y >= 0).Max (v => v.Frame.Y + v.Frame.Height);
|
||||
newDimension = furthestTop + furthestBottom + thickness.Top + thickness.Bottom;
|
||||
}
|
||||
break;
|
||||
|
||||
case Dim.DimFill:
|
||||
default:
|
||||
@@ -729,10 +742,10 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
// horizontal
|
||||
(newX, newW) = GetNewLocationAndDimension (superviewFrame.X, superviewFrame.Width, _x, _width, autosize.Width);
|
||||
(newX, newW) = GetNewLocationAndDimension (true, superviewFrame.X, superviewFrame.Width, _x, _width, autosize.Width);
|
||||
|
||||
// vertical
|
||||
(newY, newH) = GetNewLocationAndDimension (superviewFrame.Y, superviewFrame.Height, _y, _height, autosize.Height);
|
||||
(newY, newH) = GetNewLocationAndDimension (false, superviewFrame.Y, superviewFrame.Height, _y, _height, autosize.Height);
|
||||
|
||||
var r = new Rect (newX, newY, newW, newH);
|
||||
if (Frame != r) {
|
||||
@@ -815,8 +828,8 @@ namespace Terminal.Gui {
|
||||
}
|
||||
return;
|
||||
case Dim.DimCombine dc:
|
||||
CollectDim (dc.left, from, ref nNodes, ref nEdges);
|
||||
CollectDim (dc.right, from, ref nNodes, ref nEdges);
|
||||
CollectDim (dc._left, from, ref nNodes, ref nEdges);
|
||||
CollectDim (dc._right, from, ref nNodes, ref nEdges);
|
||||
break;
|
||||
}
|
||||
}
|
||||
67
UICatalog/Scenarios/DimAutoSize.cs
Normal file
67
UICatalog/Scenarios/DimAutoSize.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace UICatalog.Scenarios;
|
||||
|
||||
[ScenarioMetadata ("DimAutoSize", "Demonstrates Dim.AutoSize")]
|
||||
[ScenarioCategory ("Layout")]
|
||||
public class DimAutoSize : Scenario {
|
||||
public override void Init ()
|
||||
{
|
||||
// The base `Scenario.Init` implementation:
|
||||
// - Calls `Application.Init ()`
|
||||
// - Adds a full-screen Window to Application.Top with a title
|
||||
// that reads "Press <hotkey> to Quit". Access this Window with `this.Win`.
|
||||
// - Sets the Theme & the ColorScheme property of `this.Win` to `colorScheme`.
|
||||
// To override this, implement an override of `Init`.
|
||||
|
||||
//base.Init ();
|
||||
|
||||
// A common, alternate, implementation where `this.Win` is not used is below. This code
|
||||
// leverages ConfigurationManager to borrow the color scheme settings from UICatalog:
|
||||
|
||||
Application.Init ();
|
||||
ConfigurationManager.Themes.Theme = Theme;
|
||||
ConfigurationManager.Apply ();
|
||||
Application.Top.ColorScheme = Colors.ColorSchemes [TopLevelColorScheme];
|
||||
}
|
||||
|
||||
public override void Setup ()
|
||||
{
|
||||
// Put scenario code here (in a real app, this would be the code
|
||||
// that would setup the app before `Application.Run` is called`).
|
||||
// With a Scenario, after UI Catalog calls `Scenario.Setup` it calls
|
||||
// `Scenario.Run` which calls `Application.Run`. Example:
|
||||
|
||||
var textField = new TextField { Text = "Type here", X = 1, Y = 0, Width = 20, Height = 1 };
|
||||
|
||||
var label = new Label {
|
||||
X = Pos.Left (textField),
|
||||
Y = Pos.Bottom (textField),
|
||||
AutoSize = true,
|
||||
};
|
||||
|
||||
textField.TextChanged += (s, e) => {
|
||||
label.Text = textField.Text;
|
||||
};
|
||||
|
||||
var button = new Button () { Text = "Press to make button move down.",
|
||||
X = Pos.Center(),
|
||||
Y = Pos.Bottom (label),
|
||||
};
|
||||
button.Clicked += (s, e) => {
|
||||
button.Y = button.Frame.Y + 1;
|
||||
};
|
||||
|
||||
var view = new FrameView () {
|
||||
Title = "Type in the TextField to make it grow.",
|
||||
X = 3,
|
||||
Y = 3,
|
||||
Width = Dim.AutoSize (),
|
||||
Height = Dim.AutoSize ()
|
||||
};
|
||||
|
||||
view.Add (textField, label, button);
|
||||
|
||||
Application.Top.Add (view);
|
||||
}
|
||||
}
|
||||
@@ -1251,8 +1251,8 @@ namespace Terminal.Gui.ViewTests {
|
||||
Assert.Equal (99, dimFill.Anchor (100));
|
||||
|
||||
var dimCombine = new Dim.DimCombine (true, dimFactor, dimAbsolute);
|
||||
Assert.Equal (dimCombine.left, dimFactor);
|
||||
Assert.Equal (dimCombine.right, dimAbsolute);
|
||||
Assert.Equal (dimCombine._left, dimFactor);
|
||||
Assert.Equal (dimCombine._right, dimAbsolute);
|
||||
Assert.Equal (20, dimCombine.Anchor (100));
|
||||
|
||||
var view = new View (new Rect (20, 10, 20, 1));
|
||||
|
||||
Reference in New Issue
Block a user