From 6fbccd6659eb591f4c598156b1a86eab2b3bd99b Mon Sep 17 00:00:00 2001 From: miguel Date: Fri, 4 May 2018 22:41:59 -0400 Subject: [PATCH] Fix the Fill computations for layout, by only special casing the Pos.Center scenarios and unrolling the rest --- Designer/Designer.csproj | 51 +++++++++++++++++++++++++++++ Designer/Program.cs | 45 +++++++++++++++++++++++++ Designer/Properties/AssemblyInfo.cs | 26 +++++++++++++++ Designer/packages.config | 4 +++ Example/demo.cs | 2 +- Terminal.Gui/Core.cs | 46 +++++++++++++++----------- Terminal.sln | 8 ++++- 7 files changed, 161 insertions(+), 21 deletions(-) create mode 100644 Designer/Designer.csproj create mode 100644 Designer/Program.cs create mode 100644 Designer/Properties/AssemblyInfo.cs create mode 100644 Designer/packages.config diff --git a/Designer/Designer.csproj b/Designer/Designer.csproj new file mode 100644 index 000000000..8c571c3a2 --- /dev/null +++ b/Designer/Designer.csproj @@ -0,0 +1,51 @@ + + + + Debug + x86 + {1228D992-C801-49BB-839A-7BD28A3FFF0A} + Exe + Designer + Designer + v4.7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + true + x86 + + + true + bin\Release + prompt + 4 + true + x86 + + + + + ..\packages\NStack.Core.0.11.0\lib\netstandard1.5\NStack.dll + + + + + + + + + {00F366F8-DEE4-482C-B9FD-6DB0200B79E5} + Terminal.Gui + + + + + + + \ No newline at end of file diff --git a/Designer/Program.cs b/Designer/Program.cs new file mode 100644 index 000000000..d3dac91a4 --- /dev/null +++ b/Designer/Program.cs @@ -0,0 +1,45 @@ +using System; +using Terminal.Gui; + +namespace Designer { + class Surface : Window { + public Surface () : base ("Designer") + { + } + } + + class MainClass { + public static void Main (string [] args) + { + Application.Init (); + + var menu = new MenuBar (new MenuBarItem [] { + new MenuBarItem ("_File", new MenuItem [] { + new MenuItem ("_Quit", "", () => { Application.RequestStop (); }) + }), + new MenuBarItem ("_Edit", new MenuItem [] { + new MenuItem ("_Copy", "", null), + new MenuItem ("C_ut", "", null), + new MenuItem ("_Paste", "", null) + }), + }); + + var login = new Label ("Login: ") { X = 3, Y = 6 }; + var password = new Label ("Password: ") { + X = Pos.Left (login), + Y = Pos.Bottom (login) + 1 + }; + + var surface = new Surface () { + X = 0, + Y = 1, + Width = Dim.Percent (80), + Height = Dim.Fill () + }; + + //Application.Top.Add (menu); + Application.Top.Add (login, password); + Application.Run (); + } + } +} diff --git a/Designer/Properties/AssemblyInfo.cs b/Designer/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..626785eed --- /dev/null +++ b/Designer/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle ("Designer")] +[assembly: AssemblyDescription ("")] +[assembly: AssemblyConfiguration ("")] +[assembly: AssemblyCompany ("")] +[assembly: AssemblyProduct ("")] +[assembly: AssemblyCopyright ("${AuthorCopyright}")] +[assembly: AssemblyTrademark ("")] +[assembly: AssemblyCulture ("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion ("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/Designer/packages.config b/Designer/packages.config new file mode 100644 index 000000000..1cb98166f --- /dev/null +++ b/Designer/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Example/demo.cs b/Example/demo.cs index 799384a73..1cc99557b 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -217,7 +217,7 @@ static class Demo { X = 0, Y = 1, Width = Dim.Fill (), - Height = Dim.Fill () - 1 + Height = Dim.Fill () }; #else var win = new Window (new Rect (0, 1, tframe.Width, tframe.Height - 1), "Hello"); diff --git a/Terminal.Gui/Core.cs b/Terminal.Gui/Core.cs index 6d0c5d109..3a311de0f 100644 --- a/Terminal.Gui/Core.cs +++ b/Terminal.Gui/Core.cs @@ -1006,38 +1006,46 @@ namespace Terminal.Gui { /// /// Computes the RelativeLayout for the view, given the frame for its container. + /// /// The Frame for the host. internal void RelativeLayout (Rect hostFrame) { int w, h, _x, _y; - if (width == null) - w = hostFrame.Width; - else - w = width.Anchor (hostFrame.Width); - if (x == null) - _x = 0; - else { - if (x is Pos.PosCenter) - _x = x.Anchor (hostFrame.Width - w); + if (x is Pos.PosCenter) { + if (width == null) + w = hostFrame.Width; else + w = width.Anchor (hostFrame.Width); + _x = x.Anchor (hostFrame.Width - w); + } else { + if (x == null) + _x = 0; + else _x = x.Anchor (hostFrame.Width); + if (width == null) + w = hostFrame.Width; + else + w = width.Anchor (hostFrame.Width - _x); } - if (height == null) - h = hostFrame.Height; - else - h = height.Anchor (hostFrame.Height); - if (y == null) - _y = 0; - else { - if (y is Pos.PosCenter) - _y = y.Anchor (hostFrame.Height - h); + if (y is Pos.PosCenter) { + if (height == null) + h = hostFrame.Height; + else + h = height.Anchor (hostFrame.Height); + _y = y.Anchor (hostFrame.Height - h); + } else { + if (y == null) + _y = 0; else _y = y.Anchor (hostFrame.Height); + if (height == null) + h = hostFrame.Height; + else + h = height.Anchor (hostFrame.Height - _y); } - Frame = new Rect (_x, _y, w, h); } diff --git a/Terminal.sln b/Terminal.sln index 4cd9782b6..c5070ec8a 100644 --- a/Terminal.sln +++ b/Terminal.sln @@ -1,10 +1,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example\Example", "Example\Example.csproj", "{B0A602CD-E176-449D-8663-64238D54F857}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{B0A602CD-E176-449D-8663-64238D54F857}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Terminal.Gui", "Terminal.Gui\Terminal.Gui.csproj", "{00F366F8-DEE4-482C-B9FD-6DB0200B79E5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Designer", "Designer\Designer.csproj", "{1228D992-C801-49BB-839A-7BD28A3FFF0A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -19,6 +21,10 @@ Global {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Debug|x86.Build.0 = Debug|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|x86.ActiveCfg = Release|Any CPU {00F366F8-DEE4-482C-B9FD-6DB0200B79E5}.Release|x86.Build.0 = Release|Any CPU + {1228D992-C801-49BB-839A-7BD28A3FFF0A}.Debug|x86.ActiveCfg = Debug|x86 + {1228D992-C801-49BB-839A-7BD28A3FFF0A}.Debug|x86.Build.0 = Debug|x86 + {1228D992-C801-49BB-839A-7BD28A3FFF0A}.Release|x86.ActiveCfg = Release|x86 + {1228D992-C801-49BB-839A-7BD28A3FFF0A}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0