Smarter StatusBar bottom tracking.

This commit is contained in:
Charlie Kindel
2020-04-15 18:25:04 -06:00
parent cd2c9e219d
commit c211dffb46
2 changed files with 219 additions and 200 deletions

View File

@@ -7,8 +7,8 @@ using System.Globalization;
using System.Reflection;
using NStack;
static class Demo {
//class Box10x : View, IScrollView {
static class Demo {
//class Box10x : View, IScrollView {
class Box10x : View {
int w = 40;
int h = 50;
@@ -30,20 +30,20 @@ static class Demo {
}
public override void Redraw (Rect region)
{
//Point pos = new Point (region.X, region.Y);
{
//Point pos = new Point (region.X, region.Y);
Driver.SetAttribute (ColorScheme.Focus);
for (int y = 0; y < h; y++) {
Move (0, y);
Driver.AddStr (y.ToString ());
for (int x = 0; x < w - y.ToString ().Length; x++) {
//Driver.AddRune ((Rune)('0' + (x + y) % 10));
for (int x = 0; x < w - y.ToString ().Length; x++) {
//Driver.AddRune ((Rune)('0' + (x + y) % 10));
if (y.ToString ().Length < w)
Driver.AddStr (" ");
}
}
//Move (pos.X, pos.Y);
}
//Move (pos.X, pos.Y);
}
}
@@ -93,10 +93,10 @@ static class Demo {
int i = 0;
string txt = "Hello world, how are you doing today";
container.Add (
new Label (new Rect (0, 1, 40, 3), $"{i+1}-{txt}") { TextAlignment = TextAlignment.Left },
new Label (new Rect (0, 3, 40, 3), $"{i+2}-{txt}") { TextAlignment = TextAlignment.Right },
new Label (new Rect (0, 5, 40, 3), $"{i+3}-{txt}") { TextAlignment = TextAlignment.Centered },
new Label (new Rect (0, 7, 40, 3), $"{i+4}-{txt}") { TextAlignment = TextAlignment.Justified }
new Label (new Rect (0, 1, 40, 3), $"{i + 1}-{txt}") { TextAlignment = TextAlignment.Left },
new Label (new Rect (0, 3, 40, 3), $"{i + 2}-{txt}") { TextAlignment = TextAlignment.Right },
new Label (new Rect (0, 5, 40, 3), $"{i + 3}-{txt}") { TextAlignment = TextAlignment.Centered },
new Label (new Rect (0, 7, 40, 3), $"{i + 4}-{txt}") { TextAlignment = TextAlignment.Justified }
);
Application.Run (container);
@@ -105,18 +105,18 @@ static class Demo {
static void ShowEntries (View container)
{
var scrollView = new ScrollView (new Rect (50, 10, 20, 8)) {
ContentSize = new Size (20, 50),
//ContentOffset = new Point (0, 0),
ContentSize = new Size (20, 50),
//ContentOffset = new Point (0, 0),
ShowVerticalScrollIndicator = true,
ShowHorizontalScrollIndicator = true
};
};
#if false
scrollView.Add (new Box10x (0, 0));
#else
scrollView.Add (new Filler (new Rect (0, 0, 40, 40)));
scrollView.Add (new Filler (new Rect (0, 0, 40, 40)));
#endif
// This is just to debug the visuals of the scrollview when small
// This is just to debug the visuals of the scrollview when small
var scrollView2 = new ScrollView (new Rect (72, 10, 3, 3)) {
ContentSize = new Size (100, 100),
ShowVerticalScrollIndicator = true,
@@ -130,12 +130,12 @@ static class Demo {
return true;
}
Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer);
// A little convoluted, this is because I am using this to test the
// layout based on referencing elements of another view:
Application.MainLoop.AddTimeout (TimeSpan.FromMilliseconds (300), timer);
// A little convoluted, this is because I am using this to test the
// layout based on referencing elements of another view:
var login = new Label ("Login: ") { X = 3, Y = 6 };
var password = new Label ("Password: ") {
X = Pos.Left (login),
@@ -154,8 +154,8 @@ static class Demo {
Width = Dim.Width (loginText)
};
var tf = new Button (3, 19, "Ok");
// Add some content
var tf = new Button (3, 19, "Ok");
// Add some content
container.Add (
login,
loginText,
@@ -202,10 +202,10 @@ static class Demo {
ml2 = new Label (1, 1, "Mouse Debug Line");
d.Add (ml2);
Application.Run (d);
}
//
// Creates a nested editor
}
//
// Creates a nested editor
static void Editor (Toplevel top)
{
var tframe = top.Frame;
@@ -255,12 +255,12 @@ static class Demo {
static void Close ()
{
MessageBox.ErrorQuery (50, 7, "Error", "There is nothing to close", "Ok");
}
// Watch what happens when I try to introduce a newline after the first open brace
// it introduces a new brace instead, and does not indent. Then watch me fight
// the editor as more oddities happen.
}
// Watch what happens when I try to introduce a newline after the first open brace
// it introduces a new brace instead, and does not indent. Then watch me fight
// the editor as more oddities happen.
public static void Open ()
{
var d = new OpenDialog ("Open", "Open a file") { AllowsMultipleSelection = true };
@@ -368,10 +368,10 @@ static class Demo {
static void Help ()
{
MessageBox.Query (50, 7, "Help", "This is a small help\nBe kind.", "Ok");
}
}
#region Selection Demo
static void ListSelectionDemo (bool multiple)
{
var d = new Dialog ("Selection Demo", 60, 20,
@@ -404,20 +404,19 @@ static class Demo {
}
}
MessageBox.Query (60, 10, "Selected Animals", result == "" ? "No animals selected" : result, "Ok");
}
}
#endregion
#region OnKeyDown / OnKeyUp Demo
private static void OnKeyDownUpDemo ()
{
var container = new Dialog (
"OnKeyDown & OnKeyUp demo", 80, 20,
new Button ("Close") { Clicked = () => { Application.RequestStop (); } }) {
Width = Dim.Fill (),
"OnKeyDown & OnKeyUp demo", 0, 0) {
Width = Dim.Fill () ,
Height = Dim.Fill (),
};
};
var list = new List<string> ();
var listView = new ListView (list) {
X = 0,
@@ -431,23 +430,24 @@ static class Demo {
void KeyUpDown (KeyEvent keyEvent, string updown)
{
if ((keyEvent.Key & Key.CtrlMask) != 0) {
list.Add ($"Key{updown, -4}: Ctrl ");
list.Add ($"Key{updown,-4}: Ctrl ");
} else if ((keyEvent.Key & Key.AltMask) != 0) {
list.Add ($"Key{updown, -4}: Alt ");
list.Add ($"Key{updown,-4}: Alt ");
} else {
list.Add ($"Key{updown, -4}: {(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}");
list.Add ($"Key{updown,-4}: {(((uint)keyEvent.KeyValue & (uint)Key.CharMask) > 26 ? $"{(char)keyEvent.KeyValue}" : $"{keyEvent.Key}")}");
}
listView.MoveDown ();
}
container.OnKeyDown += (KeyEvent keyEvent) => KeyUpDown (keyEvent, "Down");
container.OnKeyUp += (KeyEvent keyEvent) => KeyUpDown (keyEvent, "Up");
container.OnKeyUp += (KeyEvent keyEvent) => KeyUpDown (keyEvent, "Up");
Application.Run (container);
}
#endregion
}
#endregion
public static Label ml;
public static MenuBar menu;
public static CheckBox menuKeysStyle;
@@ -455,23 +455,23 @@ static class Demo {
static void Main ()
{
if (Debugger.IsAttached)
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
//Application.UseSystemConsole = true;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US");
//Application.UseSystemConsole = true;
Console.WindowHeight = 35;
Application.Init ();
var top = Application.Top;
//Open ();
var top = Application.Top;
//Open ();
#if true
var win = new Window ("Hello") {
X = 1,
Y = 1,
Width = Dim.Fill (),
Height = Dim.Fill () - 1
};
};
#else
var tframe = top.Frame;
@@ -561,27 +561,30 @@ static class Demo {
new StatusItem(Key.F2, "~F2~ Load", null),
new StatusItem(Key.F3, "~F3~ Save", null),
new StatusItem(Key.ControlX, "~^X~ Quit", () => { if (Quit ()) top.Running = false; }),
});
win.Add (drag, dragText);
#if true
// This currently causes a stack overflow, because it is referencing a window that has not had its size allocated yet
}) {
Style = StatusBar.StatusBarStyle.SnapToBottom,
Parent = null,
};
win.Add (drag, dragText);
#if false
// This currently causes a stack overflow, because it is referencing a window that has not had its size allocated yet
var bottom = new Label ("This should go on the bottom!");
win.Add (bottom);
Application.OnResized = () => {
Application.OnResized += () => {
bottom.X = Pos.Left (win);
bottom.Y = Pos.Bottom (win);
};
};
#endif
top.Add (win);
//top.Add (menu);
top.Add (win);
//top.Add (menu);
top.Add (menu, statusBar, ml);
OnKeyDownUpDemo ();
//OnKeyDownUpDemo ();
Application.Run ();
}