Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,7 +1820,7 @@ public void ClearKeybinding (Key key)
/// <param name="command"></param>
public void ClearKeybinding (params Command [] command)
{
foreach (var kvp in KeyBindings.Where (kvp => kvp.Value.SequenceEqual (command)).ToArray()) {
foreach (var kvp in KeyBindings.Where (kvp => kvp.Value.SequenceEqual (command)).ToArray ()) {
KeyBindings.Remove (kvp.Key);
}
}
Expand Down Expand Up @@ -2556,6 +2556,11 @@ public override bool Enabled {
}
}

/// <summary>
/// Gets or sets whether a view is cleared if the <see cref="Visible"/> property is <see langword="false"/>.
/// </summary>
public bool ClearOnVisibleFalse { get; set; } = true;

/// <inheritdoc/>>
public override bool Visible {
get => base.Visible;
Expand All @@ -2566,7 +2571,9 @@ public override bool Visible {
if (HasFocus) {
SetHasFocus (false, this);
}
Clear ();
if (ClearOnVisibleFalse) {
Clear ();
}
}
OnVisibleChanged ();
SetNeedsDisplay ();
Expand Down
58 changes: 43 additions & 15 deletions Terminal.Gui/Views/ScrollBarView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ScrollBarView (View host, bool isVertical, bool showBothScrollIndicator =
OtherScrollBarView.X = OtherScrollBarView.IsVertical ? Pos.Right (host) - 1 : Pos.Left (host);
OtherScrollBarView.Y = OtherScrollBarView.IsVertical ? Pos.Top (host) : Pos.Bottom (host) - 1;
OtherScrollBarView.Host.SuperView.Add (OtherScrollBarView);
OtherScrollBarView.showScrollIndicator = true;
OtherScrollBarView.ShowScrollIndicator = true;
}
ShowScrollIndicator = true;
contentBottomRightCorner = new View (" ") { Visible = host.Visible };
Expand All @@ -116,6 +116,7 @@ public ScrollBarView (View host, bool isVertical, bool showBothScrollIndicator =
contentBottomRightCorner.Width = 1;
contentBottomRightCorner.Height = 1;
contentBottomRightCorner.MouseClick += ContentBottomRightCorner_MouseClick;
ClearOnVisibleFalse = false;
}

private void Host_VisibleChanged ()
Expand Down Expand Up @@ -188,11 +189,9 @@ public bool IsVertical {
public int Size {
get => size;
set {
if (hosted || (otherScrollBarView != null && otherScrollBarView.hosted)) {
size = value + 1;
} else {
size = value;
}
size = value;
SetRelativeLayout (Bounds);
ShowHideScrollBars (false);
SetNeedsDisplay ();
}
}
Expand Down Expand Up @@ -220,9 +219,6 @@ public int Position {
position = Math.Max (position + max, 0);
}
var s = GetBarsize (vertical);
if (position + s == size && (hosted || (otherScrollBarView != null && otherScrollBarView.hosted))) {
position++;
}
OnChangedPosition ();
SetNeedsDisplay ();
}
Expand Down Expand Up @@ -327,11 +323,13 @@ public virtual void Refresh ()
ShowHideScrollBars ();
}

void ShowHideScrollBars ()
void ShowHideScrollBars (bool redraw = true)
{
if (!hosted || (hosted && !autoHideScrollBars)) {
if (contentBottomRightCorner != null && contentBottomRightCorner.Visible) {
contentBottomRightCorner.Visible = false;
} else if (otherScrollBarView != null && otherScrollBarView.contentBottomRightCorner != null && otherScrollBarView.contentBottomRightCorner.Visible) {
otherScrollBarView.contentBottomRightCorner.Visible = false;
}
return;
}
Expand All @@ -350,24 +348,34 @@ void ShowHideScrollBars ()
if (showBothScrollIndicator) {
if (contentBottomRightCorner != null) {
contentBottomRightCorner.Visible = true;
} else if (otherScrollBarView != null && otherScrollBarView.contentBottomRightCorner != null) {
otherScrollBarView.contentBottomRightCorner.Visible = true;
}
} else if (!showScrollIndicator) {
if (contentBottomRightCorner != null) {
contentBottomRightCorner.Visible = false;
} else if (otherScrollBarView != null && otherScrollBarView.contentBottomRightCorner != null) {
otherScrollBarView.contentBottomRightCorner.Visible = false;
}
if (Application.mouseGrabView != null && Application.mouseGrabView == this) {
Application.UngrabMouse ();
}
} else {
} else if (contentBottomRightCorner != null) {
contentBottomRightCorner.Visible = false;
} else if (otherScrollBarView != null && otherScrollBarView.contentBottomRightCorner != null) {
otherScrollBarView.contentBottomRightCorner.Visible = false;
}
if (Host?.Visible == true && showScrollIndicator && !Visible) {
Visible = true;
}
if (Host?.Visible == true && otherScrollBarView != null && otherScrollBarView.showScrollIndicator
&& !otherScrollBarView.Visible) {
if (Host?.Visible == true && otherScrollBarView?.showScrollIndicator == true && !otherScrollBarView.Visible) {
otherScrollBarView.Visible = true;
}

if (!redraw) {
return;
}

if (showScrollIndicator) {
Redraw (Bounds);
}
Expand All @@ -384,24 +392,39 @@ bool CheckBothScrollBars (ScrollBarView scrollBarView, bool pending = false)
if (scrollBarView.showScrollIndicator) {
scrollBarView.ShowScrollIndicator = false;
}
if (scrollBarView.Visible) {
scrollBarView.Visible = false;
}
} else if (barsize > 0 && barsize == scrollBarView.size && scrollBarView.OtherScrollBarView != null && pending) {
if (scrollBarView.showScrollIndicator) {
scrollBarView.ShowScrollIndicator = false;
}
if (scrollBarView.Visible) {
scrollBarView.Visible = false;
}
if (scrollBarView.OtherScrollBarView != null && scrollBarView.showBothScrollIndicator) {
scrollBarView.OtherScrollBarView.ShowScrollIndicator = false;
}
if (scrollBarView.OtherScrollBarView.Visible) {
scrollBarView.OtherScrollBarView.Visible = false;
}
} else if (barsize > 0 && barsize == size && scrollBarView.OtherScrollBarView != null && !pending) {
pending = true;
} else {
if (scrollBarView.OtherScrollBarView != null && pending) {
if (!scrollBarView.showBothScrollIndicator) {
scrollBarView.OtherScrollBarView.ShowScrollIndicator = true;
}
if (!scrollBarView.OtherScrollBarView.Visible) {
scrollBarView.OtherScrollBarView.Visible = true;
}
}
if (!scrollBarView.showScrollIndicator) {
scrollBarView.ShowScrollIndicator = true;
}
if (!scrollBarView.Visible) {
scrollBarView.Visible = true;
}
}

return pending;
Expand All @@ -418,7 +441,7 @@ void SetWidthHeight ()
} else if (showScrollIndicator) {
Width = vertical ? 1 : Dim.Width (Host) - 0;
Height = vertical ? Dim.Height (Host) - 0 : 1;
} else if (otherScrollBarView != null && otherScrollBarView.showScrollIndicator) {
} else if (otherScrollBarView?.showScrollIndicator == true) {
otherScrollBarView.Width = otherScrollBarView.vertical ? 1 : Dim.Width (Host) - 0;
otherScrollBarView.Height = otherScrollBarView.vertical ? Dim.Height (Host) - 0 : 1;
}
Expand All @@ -432,7 +455,10 @@ void SetWidthHeight ()
///<inheritdoc/>
public override void Redraw (Rect region)
{
if (ColorScheme == null || Size == 0) {
if (ColorScheme == null || ((!showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible)) {
if ((!showScrollIndicator || Size == 0) && AutoHideScrollBars && Visible) {
ShowHideScrollBars (false);
}
return;
}

Expand Down Expand Up @@ -578,6 +604,8 @@ public override void Redraw (Rect region)

if (contentBottomRightCorner != null && hosted && showBothScrollIndicator) {
contentBottomRightCorner.Redraw (contentBottomRightCorner.Bounds);
} else if (otherScrollBarView != null && otherScrollBarView.contentBottomRightCorner != null && otherScrollBarView.hosted && otherScrollBarView.showBothScrollIndicator) {
otherScrollBarView.contentBottomRightCorner.Redraw (otherScrollBarView.contentBottomRightCorner.Bounds);
}
}

Expand Down
Loading