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
7 changes: 2 additions & 5 deletions Examples/UICatalog/Scenarios/Arrangement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,10 @@ public override void Main ()
ShadowStyle = ShadowStyles.Transparent,
BorderStyle = LineStyle.Double,
TabStop = TabBehavior.TabGroup,
Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped
Arrangement = ViewArrangement.Movable | ViewArrangement.Overlapped,
SchemeName = SchemeManager.SchemesToSchemeName (Schemes.Error)
};

datePicker.SetScheme (new Scheme (new Attribute (SchemeManager.GetScheme (Schemes.Accent).Normal.Foreground.GetBrighterColor (),
SchemeManager.GetScheme (Schemes.Accent).Normal.Background.GetBrighterColor (),
SchemeManager.GetScheme (Schemes.Accent).Normal.Style)));

TransparentView transparentView = new ()
{
Title = "Transparent",
Expand Down
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
7 changes: 3 additions & 4 deletions Terminal.Gui/ViewBase/Adornment/AdornmentImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ public Thickness Thickness
get;
set
{
Thickness current = field;
field = value;

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

field = value;

OnThicknessChanged ();
ThicknessChanged?.Invoke (this, EventArgs.Empty);
}
Expand Down
19 changes: 9 additions & 10 deletions Terminal.Gui/ViewBase/Layout/DimAuto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ internal override int Calculate (int location, int superviewContentSize, View us
// 2048 x 2048 supports unit testing where no App is running.
Size screenSize = us.App?.Screen.Size ?? new Size (2048, 2048);
int autoMin = MinimumContentDim?.GetAnchor (superviewContentSize) ?? 0;
int screenX4 = dimension == Dimension.Width ? screenSize.Width * 4 : screenSize.Height * 4;
int autoMax = MaximumContentDim?.GetAnchor (superviewContentSize) ?? screenX4;
int autoMax = MaximumContentDim?.GetAnchor (superviewContentSize) ?? int.MaxValue;

if (Style.FastHasFlags (DimAutoStyle.Text))
{
Expand All @@ -177,7 +176,7 @@ internal override int Calculate (int location, int superviewContentSize, View us
{
// Set BOTH width and height (by setting Size). We do this because we will be called again, next
// for Dimension.Height. We need to know the width to calculate the height.
us.TextFormatter.ConstrainToSize = us.TextFormatter.FormatAndGetSize (new Size (int.Min (autoMax, screenX4), screenX4));
us.TextFormatter.ConstrainToSize = us.TextFormatter.FormatAndGetSize (new Size (autoMax, int.MaxValue));
}

textSize = us.TextFormatter.ConstrainToWidth ?? 0;
Expand All @@ -187,18 +186,18 @@ internal override int Calculate (int location, int superviewContentSize, View us
// For height, we need to make sure width has been calculated.
if (us.TextFormatter.ConstrainToHeight is null)
{
int width = int.Min (MaximumContentDim?.GetAnchor (superviewContentSize) ?? screenX4, screenSize.Width * 4);
int width = int.Min (MaximumContentDim?.GetAnchor (superviewContentSize) ?? int.MaxValue, screenSize.Width * 4);

if (us.TextFormatter.ConstrainToWidth is null)
{
// Use Viewport.Width if available; fall back to the max-based width when
// the view hasn't been laid out yet (Viewport.Width == 0) to avoid
// constraining the text to zero width which produces height = 0.
int constrainWidth = us.Viewport.Width > 0 ? us.Viewport.Width : width;
width = us.TextFormatter.FormatAndGetSize (new Size (constrainWidth, screenX4)).Width;
width = us.TextFormatter.FormatAndGetSize (new Size (constrainWidth, int.MaxValue)).Width;
}

textSize = us.TextFormatter.FormatAndGetSize (new Size (us.TextFormatter.ConstrainToWidth ?? width, screenX4)).Height;
textSize = us.TextFormatter.FormatAndGetSize (new Size (us.TextFormatter.ConstrainToWidth ?? width, int.MaxValue)).Height;
us.TextFormatter.ConstrainToHeight = textSize;
}
else
Expand Down Expand Up @@ -248,8 +247,8 @@ internal override int Calculate (int location, int superviewContentSize, View us
foreach (View v in categories.Centered)
{
maxCentered = dimension == Dimension.Width
? v.X.GetAnchor (0) + v.Width.Calculate (0, screenX4, v, dimension)
: v.Y.GetAnchor (0) + v.Height.Calculate (0, screenX4, v, dimension);
? v.X.GetAnchor (0) + v.Width.Calculate (0, int.MaxValue, v, dimension)
: v.Y.GetAnchor (0) + v.Height.Calculate (0, int.MaxValue, v, dimension);
}

maxCalculatedSize = int.Max (maxCalculatedSize, maxCentered);
Expand All @@ -272,8 +271,8 @@ internal override int Calculate (int location, int superviewContentSize, View us
{
// Need to set the relative layout for PosAnchorEnd subviews to calculate the size
anchoredSubView.SetRelativeLayout (dimension == Dimension.Width
? new Size (maxCalculatedSize, screenX4)
: new Size (screenX4, maxCalculatedSize));
? new Size (maxCalculatedSize, int.MaxValue)
: new Size (int.MaxValue, maxCalculatedSize));

maxAnchorEnd = dimension == Dimension.Width
? anchoredSubView.X.GetAnchor (maxCalculatedSize + anchoredSubView.Frame.Width)
Expand Down
7 changes: 5 additions & 2 deletions Terminal.Gui/ViewBase/View.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,12 @@ private void SetViewport (Rectangle viewport)

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

if (newSize == Frame.Size)
// Detect the "adornments consume entire viewport" no-op: when the requested viewport size equals
// the current Viewport size (which may already be clamped to zero when Frame is smaller than adornments).
// In this case updating Frame would incorrectly grow it, so treat it as a no-op.
if (newSize == Frame.Size || viewport.Size == Viewport.Size)
{
// The change is not changing the Frame, so we don't need to update it.
// The change is not changing the Frame, or the adornments consume the entire Frame, 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
13 changes: 13 additions & 0 deletions Terminal.Gui/ViewBase/View.Drawing.Scheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ Scheme DefaultAction ()

if (SchemeManager.TryGetScheme (SchemeName, out Scheme? namedScheme))
{
if (SchemeName != "Accent")
{
return namedScheme;
}

// If the "Accent" scheme is requested but the theme's definition has no normal background color,
// derive it from the base scheme to ensure it has a valid background.
// There may be cases where a Theme defines an Accent like this; that should be a rare case.
if (namedScheme.Normal.Background == Color.None)
{
return SchemeManager.TryGetScheme ("Base", out Scheme? baseScheme) ? Scheme.DeriveAccent (baseScheme, Driver?.DefaultAttribute) : namedScheme;
}

return namedScheme;
}

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
29 changes: 21 additions & 8 deletions Terminal.Gui/Views/DropDownList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,19 @@ public override void EndInit ()
base.EndInit ();
}

/// <inheritdoc/>
protected override bool OnMouseEvent (Mouse ev)
{
if (!ReadOnly || !ev.Flags.FastHasFlags (MouseFlags.LeftButtonPressed))
{
return base.OnMouseEvent (ev);
}

App?.Popovers?.Register (_listPopover);

return InvokeCommand (Command.Activate) is true;
}

/// <inheritdoc/>
protected override bool OnHasFocusChanging (bool currentHasFocus, bool newHasFocus, View? currentFocused, View? newFocused)
{
Expand Down Expand Up @@ -304,18 +317,18 @@ protected override bool OnGettingAttributeForRole (in VisualRole role, ref Attri
case VisualRole.ReadOnly when ReadOnly:

case VisualRole.Active when ReadOnly:
{
currentAttribute = GetAttributeForRole (HasFocus ? VisualRole.Focus : VisualRole.Normal);
{
currentAttribute = GetAttributeForRole (HasFocus ? VisualRole.Focus : VisualRole.Normal);

return true;
}
return true;
}

case VisualRole.Editable when ReadOnly:
{
currentAttribute = GetAttributeForRole (HasFocus ? VisualRole.Focus : VisualRole.Normal);
{
currentAttribute = GetAttributeForRole (HasFocus ? VisualRole.Focus : VisualRole.Normal);

break;
}
break;
}
}

return false;
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
Loading
Loading