mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixes #775. Menu now is working properly on another toplevel and supports unicode.
This commit is contained in:
@@ -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; }
|
||||
|
||||
|
||||
@@ -228,13 +228,13 @@ namespace Terminal.Gui {
|
||||
///<inheritdoc/>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -276,7 +276,7 @@ namespace Terminal.Gui {
|
||||
s = ((Toplevel)SuperView).StatusBar != null;
|
||||
}
|
||||
if (SuperView == null || SuperView is Toplevel) {
|
||||
l = s ? Driver.Rows - 1 : Driver.Rows;
|
||||
l = s ? Frame.Height - 1 : Frame.Height;
|
||||
} else {
|
||||
l = s ? SuperView.Frame.Height - 1 : SuperView.Frame.Height;
|
||||
}
|
||||
@@ -296,17 +296,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 ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
@@ -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)) {
|
||||
|
||||
@@ -114,10 +114,6 @@ namespace UICatalog {
|
||||
Text = unicode,
|
||||
};
|
||||
Win.Add (textView);
|
||||
|
||||
// Move Win down to row 1, below menu
|
||||
Win.Y = 1;
|
||||
Top.LayoutSubviews ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user