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
10 changes: 7 additions & 3 deletions Terminal.Gui/ViewBase/Layout/DimAuto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private readonly struct ViewCategories
/// Categorizes views in a single pass to reduce iterations and allocations.
/// Phase 1 and 2 Performance Optimization.
/// </summary>
private static ViewCategories CategorizeViews (IList<View> subViews, Dimension dimension, int superviewContentSize)
private static ViewCategories CategorizeViews (IList<View> subViews, Dimension dimension)
{
ViewCategories categories = new ()
{
Expand Down Expand Up @@ -191,7 +191,11 @@ internal override int Calculate (int location, int superviewContentSize, View us

if (us.TextFormatter.ConstrainToWidth is null)
{
width = us.TextFormatter.FormatAndGetSize (new Size (us.Viewport.Width, screenX4)).Width;
// 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;
}

textSize = us.TextFormatter.FormatAndGetSize (new Size (us.TextFormatter.ConstrainToWidth ?? width, screenX4)).Height;
Expand Down Expand Up @@ -219,7 +223,7 @@ internal override int Calculate (int location, int superviewContentSize, View us
// Work directly with the collection to avoid unnecessary ToList() allocation

// Categorize views in a single pass
ViewCategories categories = CategorizeViews (us.InternalSubViews, dimension, superviewContentSize);
ViewCategories categories = CategorizeViews (us.InternalSubViews, dimension);

// Process not-dependent views
foreach (View notDependentSubView in categories.NotDependent)
Expand Down
44 changes: 26 additions & 18 deletions Terminal.Gui/ViewBase/View.Content.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,31 @@

// DimAuto.Calculate adds the Adornments thickness, so we need to subtract it here since
// we want the content size only.
Dim.Auto ().Calculate (0, GetContainerSize ().Width, this, Dimension.Width) - GetAdornmentsThickness ().Horizontal;
GetAutoWidth () - GetAdornmentsThickness ().Horizontal;

/// <summary>
/// Gets the natural (auto-size) width of the view as calculated by <see cref="Dim.Auto ()"/>.

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 105 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'Auto ()' that could not be resolved
/// </summary>
/// <remarks>
/// The returned width is the full auto-calculated width for the view, including adornment thickness.
/// Unlike <see cref="GetWidthRequiredForSubViews ()"/>, this value is not content-only.
/// The calculation may also respect minimum and maximum content constraints applied by the auto dimension logic
/// before adornments are added.
/// </remarks>
/// <returns></returns>
public int GetAutoWidth () => Dim.Auto ().Calculate (0, GetContainerSize ().Width, this, Dimension.Width);

/// <summary>
/// Gets the natural (auto-size) height of the view as calculated by <see cref="Dim.Auto ()"/>.

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'Auto ()' that could not be resolved

Check warning on line 117 in Terminal.Gui/ViewBase/View.Content.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'Auto ()' that could not be resolved
/// </summary>
/// <remarks>
/// The returned height is the full auto-calculated height for the view, including adornment thickness.
/// Unlike <see cref="GetHeightRequiredForSubViews ()"/>, this value is not content-only.
/// The calculation may also respect minimum and maximum content constraints applied by the auto dimension logic
/// before adornments are added.
/// </remarks>
/// <returns></returns>
public int GetAutoHeight () => Dim.Auto ().Calculate (0, GetContainerSize ().Height, this, Dimension.Height);

/// <summary>
/// Gets the minimum number of rows required for all the View's SubViews to fit in the content area.
Expand All @@ -109,7 +133,7 @@

// DimAuto.Calculate adds the Adornments thickness, so we need to subtract it here since
// we want the content size only.
Dim.Auto ().Calculate (0, GetContainerSize ().Height, this, Dimension.Height) - GetAdornmentsThickness ().Vertical;
GetAutoHeight () - GetAdornmentsThickness ().Vertical;

/// <summary>
/// Gets or sets a value indicating whether the view's content size tracks the <see cref="Viewport"/>'s
Expand Down Expand Up @@ -243,22 +267,6 @@
return ViewportToScreen (contentRelativeToViewport);
}

/// <summary>Converts a Screen-relative coordinate to a Content-relative coordinate.</summary>
/// <remarks>
/// Content-relative means relative to the top-left corner of the view's Content, which is
/// always at <c>0, 0</c>.
/// </remarks>
/// <param name="location">The Screen-relative location.</param>
/// <returns>The coordinate relative to this view's Content.</returns>
public Point ScreenToContent (in Point location)
{
Point viewportOffset = GetViewportOffsetFromFrame ();
Point screen = ScreenToFrame (location);
screen.Offset (Viewport.X - viewportOffset.X, Viewport.Y - viewportOffset.Y);

return screen;
}

#endregion Content Area

#region Viewport
Expand Down
42 changes: 11 additions & 31 deletions Terminal.Gui/Views/Color/AttributePicker.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Claude - Opus 4.5

using System.Diagnostics;

namespace Terminal.Gui.Views;

/// <summary>
Expand Down Expand Up @@ -35,7 +31,6 @@ public Attribute? Value
out _);
}


/// <summary>
/// Raised when <see cref="Value"/> is about to change.
/// Set <see cref="ValueChangingEventArgs{T}.Handled"/> to <see langword="true"/> to cancel the change.
Expand All @@ -47,7 +42,7 @@ public Attribute? Value
/// </summary>
public event EventHandler<ValueChangedEventArgs<Attribute?>>? ValueChanged;

/// <inheritdoc />
/// <inheritdoc/>
public event EventHandler<ValueChangedEventArgs<object?>>? ValueChangedUntyped;

private ColorPicker? _foregroundPicker;
Expand All @@ -65,11 +60,12 @@ public string SampleText
get => _sampleText;
set
{
if (_sampleText != value)
if (_sampleText == value)
{
_sampleText = value;
UpdateSampleLabel ();
return;
}
_sampleText = value;
UpdateSampleLabel ();
}
}

Expand All @@ -81,26 +77,19 @@ public AttributePicker ()
CanFocus = true;
TabStop = TabBehavior.TabStop;
Height = Dim.Auto ();
Width = Dim.Fill (0, minimumContentDim: 64);
Width = Dim.Fill (0, 64);
CommandsToBubbleUp = [Command.Accept];
SetupSubViews ();
}

private void SetupSubViews ()
{
ColorPickerStyle colorPickerStyle = new ()
{
ShowTextFields = true,
ShowColorName = true
};
ColorPickerStyle colorPickerStyle = new () { ShowTextFields = true, ShowColorName = true };

// Create foreground picker - offset X = -1 for border auto-joining with parent
_foregroundPicker = new ColorPicker
{
Title = "Foreground",
BorderStyle = LineStyle.Single,
SuperViewRendersLineCanvas = true,
Style = colorPickerStyle,
Title = "Foreground", BorderStyle = LineStyle.Single, SuperViewRendersLineCanvas = true, Style = colorPickerStyle
};
_foregroundPicker.ValueChanged += OnForegroundColorChanged;
_foregroundPicker.ApplyStyleChanges ();
Expand Down Expand Up @@ -130,7 +119,7 @@ private void SetupSubViews ()
Width = Dim.Auto (),
Height = Dim.Height (_foregroundPicker) + Dim.Height (_backgroundPicker) - 1
};
_styleSelector.Width = _styleSelector.GetWidthRequiredForSubViews () + _styleSelector.GetAdornmentsThickness ().Horizontal;
_styleSelector.Width = _styleSelector.GetAutoWidth ();
_styleSelector.ValueChanged += OnStyleChanged;

// Set color picker widths relative to style selector
Expand All @@ -155,16 +144,6 @@ private void SetupSubViews ()
UpdateSampleLabel ();
}

/// <summary>
/// Performs the work after value change is confirmed (sync subviews, update sample).
/// </summary>
private void DoValueChanged (Attribute? newValue)
{
_value = newValue;
SyncSubViewsToValue ();
UpdateSampleLabel ();
}

/// <summary>
/// Called before <see cref="Value"/> changes. Return <see langword="true"/> to cancel the change.
/// </summary>
Expand All @@ -173,7 +152,8 @@ private void DoValueChanged (Attribute? newValue)
/// <summary>
/// Called after <see cref="Value"/> has changed.
/// </summary>
protected virtual void OnValueChanged (ValueChangedEventArgs<Attribute?> args) => ValueChangedUntyped?.Invoke (this, new ValueChangedEventArgs<object?> (args.OldValue, args.NewValue));
protected virtual void OnValueChanged (ValueChangedEventArgs<Attribute?> args) =>
ValueChangedUntyped?.Invoke (this, new ValueChangedEventArgs<object?> (args.OldValue, args.NewValue));

private void OnForegroundColorChanged (object? sender, ValueChangedEventArgs<Color?> e) => UpdateValueFromSubViews ();

Expand Down
Loading
Loading