Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions Examples/UICatalog/Scenarios/PopoverMenus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ void CreateAction (List<MenuItem> cultures, MenuItem culture) =>

foreach (MenuItem item in cultures)
{
((CheckBox)item.CommandView).Value =
Thread.CurrentThread.CurrentUICulture.Name == item.HelpText ? CheckState.Checked : CheckState.UnChecked;
(item.CommandView as CheckBox)?.Value = Thread.CurrentThread.CurrentUICulture.Name == item.HelpText ? CheckState.Checked : CheckState.UnChecked;
}
};
}
Expand Down
13 changes: 5 additions & 8 deletions Examples/UICatalog/Scenarios/Shortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private void HandleOnIsRunningChanged (object? sender, EventArgs<bool> e)
Command = Command.New
};

_window.CommandNotBound += (o, args) =>
_window.CommandNotBound += (_, args) =>
{
if (args.Context?.Command != Command.New)
{
Expand Down Expand Up @@ -329,13 +329,10 @@ private void HandleOnIsRunningChanged (object? sender, EventArgs<bool> e)

//framedShortcut.Orientation = Orientation.Horizontal;

if (framedShortcut.Padding is { })
{
framedShortcut.Padding.Thickness = new Thickness (0, 1, 0, 0);
framedShortcut.Padding.Diagnostics = ViewDiagnosticFlags.Ruler;
}
framedShortcut.Padding.Thickness = new Thickness (0, 1, 0, 0);
framedShortcut.Padding.Diagnostics = ViewDiagnosticFlags.Ruler;

if (framedShortcut.CommandView.Margin is { })
if (framedShortcut.CommandView?.Margin is { })
{
framedShortcut.CommandView.SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Dialog);
framedShortcut.HelpView.SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Error);
Expand Down Expand Up @@ -537,7 +534,7 @@ void SetCommandViewsCanFocus (bool canFocus)
{
if (peer.CanFocus)
{
peer.CommandView.CanFocus = canFocus;
peer.CommandView?.CanFocus = canFocus;
}
}
focused?.SetFocus ();
Expand Down
64 changes: 31 additions & 33 deletions Examples/UICatalog/Scenarios/TreeViewFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,27 @@ public override void Main ()
using IApplication app = Application.Create ();
app.Init ();

using Window win = new ();
using Runnable win = new ();
Comment thread
tig marked this conversation as resolved.
win.Title = GetName ();
win.Y = 1; // menu
win.Height = Dim.Fill ();

// MenuBar
MenuBar menu = new ();

_treeViewFiles = new TreeView<IFileSystemInfo> { X = 0, Y = Pos.Bottom (menu), Width = Dim.Percent (50), Height = Dim.Fill () };
_treeViewFiles = new TreeView<IFileSystemInfo>
{
Y = Pos.Bottom (menu),
Height = Dim.Fill (),
};
_treeViewFiles.DrawLine += TreeViewFiles_DrawLine;

// Scrollbars are disabled by default (VisibilityMode.Manual)

_detailsFrame = new DetailsFrame (_iconProvider)
{
X = Pos.Right (_treeViewFiles), Y = Pos.Top (_treeViewFiles), Width = Dim.Fill (), Height = Dim.Fill ()
X = Pos.AnchorEnd (), Y = Pos.Bottom (menu), Width = 50, Height = Dim.Fill ()
};
_treeViewFiles.Width = Dim.Fill (_detailsFrame);

win.Add (menu, _treeViewFiles, _detailsFrame);

win.Add (_detailsFrame);
_treeViewFiles.Activating += TreeViewFiles_Activating;
_treeViewFiles.KeyDown += TreeViewFiles_KeyPress;
_treeViewFiles.SelectionChanged += TreeViewFiles_SelectionChanged;
Expand All @@ -70,8 +72,6 @@ public override void Main ()
_miMultiSelectCheckBox = new CheckBox
{
Title = "_Multi Select"

//CheckedState = CheckState.Checked
};
_miMultiSelectCheckBox.ValueChanged += (_, _) => SetMultiSelect ();

Expand Down Expand Up @@ -140,10 +140,9 @@ public override void Main ()
]));

SetNerdIcons ();
win.Add (menu, _treeViewFiles);

_treeViewFiles.GoToFirst ();
_treeViewFiles.Expand ();

_treeViewFiles.SetFocus ();

UpdateIconCheckState ();
Expand Down Expand Up @@ -205,20 +204,20 @@ private void SetCustomColors ()
if (_miCustomColorsCheckBox.Value == CheckState.Checked)
{
_treeViewFiles.ColorGetter = m =>
{
if ((m is IDirectoryInfo && m.Attributes.HasFlag (FileAttributes.Hidden)) || (m is IFileInfo && m.Attributes.HasFlag (FileAttributes.Hidden)))
{
return new Scheme
{
Focus = new Attribute (Color.BrightRed,
_treeViewFiles.GetAttributeForRole (VisualRole.Focus).Background),
Normal = new Attribute (Color.BrightYellow,
_treeViewFiles.GetAttributeForRole (VisualRole.Normal).Background)
};
}

return null;
};
{
if ((m is IDirectoryInfo && m.Attributes.HasFlag (FileAttributes.Hidden)) || (m is IFileInfo && m.Attributes.HasFlag (FileAttributes.Hidden)))
{
return new Scheme
{
Focus = new Attribute (Color.BrightRed,
_treeViewFiles.GetAttributeForRole (VisualRole.Focus).Background),
Normal = new Attribute (Color.BrightYellow,
_treeViewFiles.GetAttributeForRole (VisualRole.Normal).Background)
};
}

return null;
};
}
else
{
Expand Down Expand Up @@ -393,13 +392,13 @@ private void TreeViewFiles_DrawLine (object? sender, DrawTreeViewLineEventArgs<I
return;

case { }:
{
Cell cell = e.Cells [e.IndexOfModelText];
{
Cell cell = e.Cells [e.IndexOfModelText];

cell.Attribute = new Attribute (Color.BrightYellow, cell.Attribute!.Value.Background, cell.Attribute!.Value.Style);
cell.Attribute = new Attribute (Color.BrightYellow, cell.Attribute!.Value.Background, cell.Attribute!.Value.Style);

break;
}
break;
}
}
}

Expand Down Expand Up @@ -482,8 +481,7 @@ private class DetailsFrame : FrameView
public DetailsFrame (FileSystemIconProvider iconProvider)
{
Title = "Details";
base.Visible = true;
CanFocus = true;
SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Dialog);
_iconProvider = iconProvider;
}

Expand Down
24 changes: 20 additions & 4 deletions Terminal.Gui/ViewBase/Adornment/AdornmentImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,30 @@ public Thickness Thickness
get;
set
{
Thickness current = field;
field = value;

if (current == field)
if (value == field)
{
return;
}

// this is a useful assert to enable to find places where Thickness is being set to an unreasonably
// large value that will cause layout issues, but it is noisy in debug since some adornments (e.g. Border)
// intentionally allow large thicknesses and assert would need to be disabled for those cases.
//#if DEBUG
// // If the new thickness is larger than the Parent.Frame, throw as this is likely a mistake and will cause layout issues.
// if (Parent is { } p)
// {
// int width = p.Frame.Size.Width - value.Horizontal;
// int height = p.Frame.Size.Height - value.Vertical;
//
// if (width < 0 || height < 0)
// {
// throw new ArgumentException (@$"Thickness {value} is too large for the parent frame {p.Frame}.", nameof (value));
// }
// }
//#endif

Comment thread
tig marked this conversation as resolved.
Outdated
field = value;

OnThicknessChanged ();
ThicknessChanged?.Invoke (this, EventArgs.Empty);
}
Expand Down
8 changes: 5 additions & 3 deletions Terminal.Gui/ViewBase/View.Content.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Terminal.Gui.ViewBase;
using System.Diagnostics;

namespace Terminal.Gui.ViewBase;

Comment thread
tig marked this conversation as resolved.
Outdated
public partial class View
{
Expand Down Expand Up @@ -523,9 +525,9 @@ private void SetViewport (Rectangle viewport)

Size newSize = new (viewport.Size.Width + thickness.Horizontal, viewport.Size.Height + thickness.Vertical);

if (newSize == Frame.Size)
if (newSize == Frame.Size || viewport.Size.Width - thickness.Horizontal < 0 || viewport.Size.Height - thickness.Vertical < 0)
{
// The change is not changing the Frame, so we don't need to update it.
// The change is not changing the Frame, or it is invalid, so we don't need to update it.
// Just call SetNeedsLayout to update the layout.
if (_viewportLocation != viewport.Location)
Comment thread
tig marked this conversation as resolved.
{
Comment thread
tig marked this conversation as resolved.
Expand Down
30 changes: 30 additions & 0 deletions Terminal.Gui/ViewBase/View.ScrollBars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ private void ConfigureVerticalScrollBarEvents (ScrollBar scrollBar)
Viewport = Viewport with { Y = Math.Min (args.NewValue, scrollBar.ScrollableContentSize - scrollBar.VisibleContentSize) };
};

scrollBar.VisibleChanging += (_, args) =>
{
if (!args.NewValue)
{
return;
}
int width = Frame.Size.Width - GetAdornmentsThickness ().Horizontal;

if (width < 1 || Viewport.Height < 2)
Comment thread
tig marked this conversation as resolved.
{
// Prevent scrollbar from becoming visible if it would cause negative available space for content
Comment thread
tig marked this conversation as resolved.
args.Cancel = true;
}
};

scrollBar.VisibleChanged += (_, _) =>
{
// Reset scrolling
Expand All @@ -166,6 +181,21 @@ private void ConfigureHorizontalScrollBarEvents (ScrollBar scrollBar)
Viewport = Viewport with { X = Math.Min (args.NewValue, scrollBar.ScrollableContentSize - scrollBar.VisibleContentSize) };
};

scrollBar.VisibleChanging += (_, args) =>
{
if (!args.NewValue)
{
return;
}
int height = Frame.Size.Height - GetAdornmentsThickness ().Vertical;

if (Viewport.Width < 2 || height < 1)
Comment thread
tig marked this conversation as resolved.
{
// Prevent scrollbar from becoming visible if it would cause negative available space for content
Comment thread
tig marked this conversation as resolved.
args.Cancel = true;
}
};

scrollBar.VisibleChanged += (_, _) =>
{
// Reset scrolling
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/Menu/MenuBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public bool EnableForDesign<TContext> (ref TContext targetView) where TContext :
]) { Id = "Preferences" }
},
new Line (),
new MenuItem { TargetView = targetView as View, Key = Application.GetDefaultKey (Command.Quit), Command = Command.Quit }
new MenuItem { TargetView = targetView as View, Command = Command.Quit }
Comment thread
tig marked this conversation as resolved.
]));

Add (new MenuBarItem ("_Edit",
Expand Down
8 changes: 8 additions & 0 deletions Terminal.Gui/Views/ScrollBar/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ private void ShowHide ()
switch (VisibilityMode)
{
case ScrollBarVisibilityMode.Auto:
if (VisibleContentSize < 2)
{
// Not enough room to show both buttons, so hide the scrollbar
Visible = false;

break;
}

// VisibilityMode is the authority. ViewportSettings flags are a
// convenience that *sets* VisibilityMode via SyncOneScrollBar; they
// should not be re-checked here. When the flag is later removed,
Expand Down
Loading
Loading