|
@@ -1055,10 +1055,14 @@ namespace Terminal.Gui {
|
|
|
/// in a visually sensible place.
|
|
|
public virtual void PositionCursor ()
|
|
|
{
|
|
|
- if (focused != null)
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (focused != null) {
|
|
|
focused.PositionCursor ();
|
|
|
- else {
|
|
|
- if (CanFocus && HasFocus) {
|
|
|
+ } else {
|
|
|
+ if (CanFocus && HasFocus && Visible) {
|
|
|
Move (textFormatter.HotKeyPos == -1 ? 0 : textFormatter.HotKeyPos, 0);
|
|
|
} else {
|
|
|
Move (frame.X, frame.Y);
|
|
@@ -1240,6 +1244,10 @@ namespace Terminal.Gui {
|
|
|
/// </remarks>
|
|
|
public virtual void Redraw (Rect bounds)
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
var clipRect = new Rect (Point.Empty, frame.Size);
|
|
|
|
|
|
if (ColorScheme != null)
|
|
@@ -1267,7 +1275,9 @@ namespace Terminal.Gui {
|
|
|
|
|
|
// Draw the subview
|
|
|
// Use the view's bounds (view-relative; Location will always be (0,0) because
|
|
|
- view.Redraw (view.Bounds);
|
|
|
+ if (view.Visible) {
|
|
|
+ view.Redraw (view.Bounds);
|
|
|
+ }
|
|
|
}
|
|
|
view.NeedDisplay = Rect.Empty;
|
|
|
view.childNeedsDisplay = false;
|
|
@@ -1311,7 +1321,7 @@ namespace Terminal.Gui {
|
|
|
if (view == null)
|
|
|
return;
|
|
|
//Console.WriteLine ($"Request to focus {view}");
|
|
|
- if (!view.CanFocus)
|
|
|
+ if (!view.CanFocus || !view.Visible)
|
|
|
return;
|
|
|
if (focused?.hasFocus == true && focused == view)
|
|
|
return;
|
|
@@ -1341,6 +1351,10 @@ namespace Terminal.Gui {
|
|
|
/// </summary>
|
|
|
public void SetFocus ()
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
SuperView?.SetFocus (this);
|
|
|
}
|
|
|
|
|
@@ -1471,13 +1485,17 @@ namespace Terminal.Gui {
|
|
|
/// </summary>
|
|
|
public void FocusFirst ()
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (tabIndexes == null) {
|
|
|
SuperView?.SetFocus (this);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
foreach (var view in tabIndexes) {
|
|
|
- if (view.CanFocus && view.tabStop) {
|
|
|
+ if (view.CanFocus && view.tabStop && view.Visible) {
|
|
|
SetFocus (view);
|
|
|
return;
|
|
|
}
|
|
@@ -1489,6 +1507,10 @@ namespace Terminal.Gui {
|
|
|
/// </summary>
|
|
|
public void FocusLast ()
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (tabIndexes == null) {
|
|
|
SuperView?.SetFocus (this);
|
|
|
return;
|
|
@@ -1498,7 +1520,7 @@ namespace Terminal.Gui {
|
|
|
i--;
|
|
|
|
|
|
View v = tabIndexes [i];
|
|
|
- if (v.CanFocus && v.tabStop) {
|
|
|
+ if (v.CanFocus && v.tabStop && v.Visible) {
|
|
|
SetFocus (v);
|
|
|
return;
|
|
|
}
|
|
@@ -1511,6 +1533,10 @@ namespace Terminal.Gui {
|
|
|
/// <returns><c>true</c>, if previous was focused, <c>false</c> otherwise.</returns>
|
|
|
public bool FocusPrev ()
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
FocusDirection = Direction.Backward;
|
|
|
if (tabIndexes == null || tabIndexes.Count == 0)
|
|
|
return false;
|
|
@@ -1530,10 +1556,10 @@ namespace Terminal.Gui {
|
|
|
focused_idx = i;
|
|
|
continue;
|
|
|
}
|
|
|
- if (w.CanFocus && focused_idx != -1 && w.tabStop) {
|
|
|
+ if (w.CanFocus && focused_idx != -1 && w.tabStop && w.Visible) {
|
|
|
focused.SetHasFocus (false, w);
|
|
|
|
|
|
- if (w != null && w.CanFocus && w.tabStop)
|
|
|
+ if (w != null && w.CanFocus && w.tabStop && w.Visible)
|
|
|
w.FocusLast ();
|
|
|
|
|
|
SetFocus (w);
|
|
@@ -1553,6 +1579,10 @@ namespace Terminal.Gui {
|
|
|
/// <returns><c>true</c>, if next was focused, <c>false</c> otherwise.</returns>
|
|
|
public bool FocusNext ()
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
FocusDirection = Direction.Forward;
|
|
|
if (tabIndexes == null || tabIndexes.Count == 0)
|
|
|
return false;
|
|
@@ -1572,10 +1602,10 @@ namespace Terminal.Gui {
|
|
|
focused_idx = i;
|
|
|
continue;
|
|
|
}
|
|
|
- if (w.CanFocus && focused_idx != -1 && w.tabStop) {
|
|
|
+ if (w.CanFocus && focused_idx != -1 && w.tabStop && w.Visible) {
|
|
|
focused.SetHasFocus (false, w);
|
|
|
|
|
|
- if (w != null && w.CanFocus && w.tabStop)
|
|
|
+ if (w != null && w.CanFocus && w.tabStop && w.Visible)
|
|
|
w.FocusFirst ();
|
|
|
|
|
|
SetFocus (w);
|
|
@@ -1870,6 +1900,10 @@ namespace Terminal.Gui {
|
|
|
/// <inheritdoc/>
|
|
|
public override bool OnMouseEnter (MouseEvent mouseEvent)
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
MouseEventArgs args = new MouseEventArgs (mouseEvent);
|
|
|
MouseEnter?.Invoke (args);
|
|
|
if (args.Handled)
|
|
@@ -1883,6 +1917,10 @@ namespace Terminal.Gui {
|
|
|
/// <inheritdoc/>
|
|
|
public override bool OnMouseLeave (MouseEvent mouseEvent)
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
MouseEventArgs args = new MouseEventArgs (mouseEvent);
|
|
|
MouseLeave?.Invoke (args);
|
|
|
if (args.Handled)
|
|
@@ -1900,6 +1938,10 @@ namespace Terminal.Gui {
|
|
|
/// <returns><c>true</c>, if the event was handled, <c>false</c> otherwise.</returns>
|
|
|
public virtual bool OnMouseEvent (MouseEvent mouseEvent)
|
|
|
{
|
|
|
+ if (!CanBeVisible (this)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
MouseEventArgs args = new MouseEventArgs (mouseEvent);
|
|
|
MouseClick?.Invoke (args);
|
|
|
if (args.Handled)
|
|
@@ -1963,5 +2005,24 @@ namespace Terminal.Gui {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Gets or sets the view visibility.
|
|
|
+ /// </summary>
|
|
|
+ public bool Visible { get; set; } = true;
|
|
|
+
|
|
|
+ bool CanBeVisible (View view)
|
|
|
+ {
|
|
|
+ if (!view.Visible) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (var c = view.SuperView; c != null; c = c.SuperView) {
|
|
|
+ if (!c.Visible) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|