diff --git a/Terminal.Gui/Core/PosDim.cs b/Terminal.Gui/Core/PosDim.cs
index 33e3a5eee..c364b9527 100644
--- a/Terminal.Gui/Core/PosDim.cs
+++ b/Terminal.Gui/Core/PosDim.cs
@@ -165,7 +165,7 @@ namespace Terminal.Gui {
return pCenter;
}
- class PosAbsolute : Pos {
+ internal class PosAbsolute : Pos {
int n;
public PosAbsolute (int n) { this.n = n; }
diff --git a/Terminal.Gui/Core/Toplevel.cs b/Terminal.Gui/Core/Toplevel.cs
index b52f9dcbc..3419c5b1a 100644
--- a/Terminal.Gui/Core/Toplevel.cs
+++ b/Terminal.Gui/Core/Toplevel.cs
@@ -228,13 +228,13 @@ namespace Terminal.Gui {
///
public override void Remove (View view)
{
- if (this == Application.Top) {
+ if (this is Toplevel && ((Toplevel)this).MenuBar != null) {
if (view is MenuBar) {
MenuBar?.Dispose ();
MenuBar = null;
}
if (view is StatusBar) {
- StatusBar = null;
+ StatusBar?.Dispose ();
StatusBar = null;
}
}
@@ -286,6 +286,7 @@ namespace Terminal.Gui {
internal void PositionToplevels ()
{
+ PositionToplevel (this);
foreach (var top in Subviews) {
if (top is Toplevel) {
PositionToplevel ((Toplevel)top);
@@ -296,17 +297,21 @@ namespace Terminal.Gui {
private void PositionToplevel (Toplevel top)
{
EnsureVisibleBounds (top, top.Frame.X, top.Frame.Y, out int nx, out int ny);
- if ((nx != top.Frame.X || ny != top.Frame.Y) && top.LayoutStyle != LayoutStyle.Computed) {
- top.X = nx;
- top.Y = ny;
+ if ((nx != top.Frame.X || ny != top.Frame.Y) && top.LayoutStyle == LayoutStyle.Computed) {
+ if (top.X is Pos.PosAbsolute && top.Bounds.X != nx) {
+ top.X = nx;
+ }
+ if (top.Y is Pos.PosAbsolute && top.Bounds.Y != ny) {
+ top.Y = ny;
+ }
}
if (StatusBar != null) {
- if (ny + top.Frame.Height > Driver.Rows - 1) {
+ if (ny + top.Frame.Height > top.Frame.Height - 1) {
if (top.Height is Dim.DimFill)
top.Height = Dim.Fill () - 1;
}
- if (StatusBar.Frame.Y != Driver.Rows - 1) {
- StatusBar.Y = Driver.Rows - 1;
+ if (StatusBar.Frame.Y != Frame.Height - 1) {
+ StatusBar.Y = Frame.Height - 1;
SetNeedsDisplay ();
}
}
diff --git a/Terminal.Gui/Views/Menu.cs b/Terminal.Gui/Views/Menu.cs
index 337b4f23b..a197d5ccc 100644
--- a/Terminal.Gui/Views/Menu.cs
+++ b/Terminal.Gui/Views/Menu.cs
@@ -132,7 +132,7 @@ namespace Terminal.Gui {
return CanExecute == null ? true : CanExecute ();
}
- internal int Width => Title.RuneCount + Help.Length + 1 + 2 +
+ internal int Width => Title.RuneCount + Help.RuneCount + 1 + 2 +
(Checked || CheckType.HasFlag (MenuItemCheckStyle.Checked) || CheckType.HasFlag (MenuItemCheckStyle.Radio) ? 2 : 0);
///
@@ -527,10 +527,9 @@ namespace Terminal.Gui {
me.Flags == MouseFlags.Button1TripleClicked || me.Flags == MouseFlags.ReportMousePosition ||
me.Flags.HasFlag (MouseFlags.Button1Pressed | MouseFlags.ReportMousePosition)) {
disabled = false;
- if (me.Y < 1)
- return true;
- if (me.Y - 1 >= barItems.Children.Length)
+ if (me.Y < 1 || me.Y - 1 >= barItems.Children.Length) {
return true;
+ }
var item = barItems.Children [me.Y - 1];
if (item == null || !item.IsEnabled ()) disabled = true;
if (item != null && !disabled)
@@ -553,6 +552,9 @@ namespace Terminal.Gui {
host.Activate (host.selected, pos, subMenu);
} else if (host.openSubMenu != null && !barItems.Children [current].IsFromSubMenu)
host.CloseMenu (false, true);
+ else {
+ SetNeedsDisplay ();
+ }
}
int GetSubMenuIndex (MenuBarItem subMenu)
@@ -799,7 +801,7 @@ namespace Terminal.Gui {
}
for (int i = 0; i < index; i++)
- pos += Menus [i].Title.Length + 2;
+ pos += Menus [i].Title.RuneCount + 2;
openMenu = new Menu (this, pos, 1, Menus [index]);
openCurrentMenu = openMenu;
openCurrentMenu.previousSubFocused = openMenu;
@@ -1055,7 +1057,7 @@ namespace Terminal.Gui {
// TODO: this code is duplicated, hotkey should be part of the MenuBarItem
var mi = Menus [i];
int p = mi.Title.IndexOf ('_');
- if (p != -1 && p + 1 < mi.Title.Length) {
+ if (p != -1 && p + 1 < mi.Title.RuneCount) {
if (Char.ToUpperInvariant ((char)mi.Title [p + 1]) == c) {
ProcessMenu (i, mi);
return true;
@@ -1144,7 +1146,7 @@ namespace Terminal.Gui {
if (mi == null)
continue;
int p = mi.Title.IndexOf ('_');
- if (p != -1 && p + 1 < mi.Title.Length) {
+ if (p != -1 && p + 1 < mi.Title.RuneCount) {
if (mi.Title [p + 1] == c) {
Selected (mi);
return true;
@@ -1212,8 +1214,19 @@ namespace Terminal.Gui {
if (me.View is MenuBar || me.View is Menu) {
if (me.View != current) {
Application.UngrabMouse ();
- Application.GrabMouse (me.View);
- me.View.MouseEvent (me);
+ var v = me.View;
+ Application.GrabMouse (v);
+ var newxy = v.ScreenToView (me.X, me.Y);
+ var nme = new MouseEvent () {
+ X = newxy.X,
+ Y = newxy.Y,
+ Flags = me.Flags,
+ OfX = me.X - newxy.X,
+ OfY = me.Y - newxy.Y,
+ View = v
+ };
+
+ v.MouseEvent (nme);
}
} else if (!(me.View is MenuBar || me.View is Menu) && (me.Flags.HasFlag (MouseFlags.Button1Clicked) ||
me.Flags == MouseFlags.Button1Pressed || me.Flags == MouseFlags.Button1DoubleClicked || me.Flags == MouseFlags.Button1TripleClicked)) {
diff --git a/Terminal.Gui/Views/StatusBar.cs b/Terminal.Gui/Views/StatusBar.cs
index 76dbf0e3a..8b8ef6b0c 100644
--- a/Terminal.Gui/Views/StatusBar.cs
+++ b/Terminal.Gui/Views/StatusBar.cs
@@ -88,7 +88,7 @@ namespace Terminal.Gui {
CanFocus = false;
ColorScheme = Colors.Menu;
X = 0;
- Y = Driver.Rows - 1;
+ Y = SuperView != null ? SuperView.Frame.Height - 1 : Pos.AnchorEnd (1);
Width = Dim.Fill ();
Height = 1;
@@ -100,8 +100,8 @@ namespace Terminal.Gui {
return delegate {
X = 0;
Height = 1;
- if (SuperView == null || SuperView == Application.Top) {
- Y = Driver.Rows - 1;
+ if (SuperView == null || SuperView is Toplevel) {
+ Y = SuperView.Frame.Height - 1;
} else {
//Y = Pos.Bottom (SuperView);
}
@@ -125,7 +125,7 @@ namespace Terminal.Gui {
//}
Move (0, 0);
- Driver.SetAttribute (ColorScheme.Normal);
+ Driver.SetAttribute (Colors.Menu.Normal);
for (int i = 0; i < Frame.Width; i++)
Driver.AddRune (' ');
@@ -133,8 +133,8 @@ namespace Terminal.Gui {
var scheme = ColorScheme.Normal;
Driver.SetAttribute (scheme);
for (int i = 0; i < Items.Length; i++) {
- var title = Items [i].Title;
- for (int n = 0; n < title.Length; n++) {
+ var title = Items [i].Title.ToString ();
+ for (int n = 0; n < Items [i].Title.RuneCount; n++) {
if (title [n] == '~') {
scheme = ToggleScheme (scheme);
continue;
diff --git a/UICatalog/Scenarios/Unicode.cs b/UICatalog/Scenarios/Unicode.cs
index 60fec0187..d30a7a695 100644
--- a/UICatalog/Scenarios/Unicode.cs
+++ b/UICatalog/Scenarios/Unicode.cs
@@ -36,6 +36,13 @@ namespace UICatalog {
});
Top.Add (menu);
+ var statusBar = new StatusBar (new StatusItem [] {
+ new StatusItem (Key.ControlQ, "~^Q~ Выход", () => Application.RequestStop()),
+ new StatusItem (Key.Unknown, "~F2~ Создать", null),
+ new StatusItem(Key.Unknown, "~F3~ Со_хранить", null),
+ });
+ Top.Add (statusBar);
+
var label = new Label ("Label:") { X = 0, Y = 1 };
Win.Add (label);
var testlabel = new Label (gitString) { X = 20, Y = Pos.Y (label), Width = Dim.Percent (50), };
@@ -114,10 +121,6 @@ namespace UICatalog {
Text = unicode,
};
Win.Add (textView);
-
- // Move Win down to row 1, below menu
- Win.Y = 1;
- Top.LayoutSubviews ();
}
}
}