Files
Terminal.Gui/Terminal.Gui/Views/LinearRange/LinearRangeOption.cs
Copilot fb4043afbc Fixes #3829. Rename Slider to LinearRange and implement CWP (#4509)
* Initial plan

* Rename Slider to LinearRange - files and code updated

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix variable name mismatches in scenario files

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix typos in comments identified by code review

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update HelpText for consistency with LinearRange rename

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Refactor LinearRange properties to use CWP with CWPPropertyHelper

- Added CWP events (Changing/Changed) for Type, LegendsOrientation, MinimumInnerSpacing, ShowLegends, ShowEndSpacing, and UseMinimumSize properties
- Used CWPPropertyHelper for consistent property change workflow
- Added virtual OnChanging/OnChanged methods for each property
- All existing tests pass

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix CWP property implementations - remove duplicate field updates in doWork

- CWPPropertyHelper updates the ref parameter, so doWork should only contain side effects
- Fixed Type, MinimumInnerSpacing, LegendsOrientation, ShowLegends, ShowEndSpacing, and UseMinimumSize
- Added comprehensive CWP tests for property changes (9 new tests, all passing)
- All 45 pre-existing LinearRange tests still pass (10 were already failing before changes)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add fluent integration tests for LinearRange

- Created LinearRangeFluentTests with 5 test scenarios
- Tests cover rendering, navigation, type changes with CWP events, range selection, and vertical orientation
- All tests build successfully

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix unit tests and address review comments

- Fixed review comments: Updated Title properties from "_Slider" to "_LinearRange" in DimAutoDemo and ViewportSettings
- Fixed review comment: Renamed filterSlider to filterLinearRange in Mouse.cs
- Fixed CWP implementation: Use local variable instead of backing field as ref parameter to CWPPropertyHelper
- This ensures doWork can update the backing field BEFORE SetContentSize() reads it
- All 55 LinearRange tests now passing (was 45/55, now 55/55)

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update DimAutoDemo.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update ViewportSettings.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* code cleanup

* Refactor LinearRanges scenario for clarity and modularity

Refactored the LinearRanges scenario to separate UI setup, configuration, and event logic. The Main() method now handles all UI layout, configuration controls, and event wiring, while MakeSliders() is responsible only for adding LinearRange controls to the main window. Updated event handlers to use discard parameters for unused arguments and modernized code with collection initializers and LINQ. This results in a clearer separation of concerns and improved maintainability.

* un did change

* cleanup

* cleanup

* cleanup

* fixed unit test
code cleanup

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-21 10:40:09 -07:00

51 lines
2.1 KiB
C#

namespace Terminal.Gui.Views;
/// <summary>Represents an option in a <see cref="LinearRange{T}"/> .</summary>
/// <typeparam name="T">Data type of the option.</typeparam>
public class LinearRangeOption<T>
{
/// <summary>Creates a new empty instance of the <see cref="LinearRangeOption{T}"/> class.</summary>
public LinearRangeOption () { }
/// <summary>Creates a new instance of the <see cref="LinearRangeOption{T}"/> class with values for each property.</summary>
public LinearRangeOption (string legend, Rune legendAbbr, T data)
{
Legend = legend;
LegendAbbr = legendAbbr;
Data = data;
}
/// <summary>Event fired when an option has changed.</summary>
public event EventHandler<LinearRangeOptionEventArgs>? Changed;
/// <summary>Custom data of the option.</summary>
public T? Data { get; set; }
/// <summary>Legend of the option.</summary>
public string? Legend { get; set; }
/// <summary>
/// Abbreviation of the Legend. When the <see cref="LinearRange{T}.MinimumInnerSpacing"/> too small to fit
/// <see cref="Legend"/>.
/// </summary>
public Rune LegendAbbr { get; set; }
/// <summary>Event Raised when this option is set.</summary>
public event EventHandler<LinearRangeOptionEventArgs>? Set;
/// <summary>Creates a human-readable string that represents this <see cref="LinearRangeOption{T}"/>.</summary>
public override string ToString () => "{Legend=" + Legend + ", LegendAbbr=" + LegendAbbr + ", Data=" + Data + "}";
/// <summary>Event Raised when this option is unset.</summary>
public event EventHandler<LinearRangeOptionEventArgs>? UnSet;
/// <summary>To Raise the <see cref="Changed"/> event from the LinearRange.</summary>
internal void OnChanged (bool isSet) { Changed?.Invoke (this, new (isSet)); }
/// <summary>To Raise the <see cref="Set"/> event from the LinearRange.</summary>
internal void OnSet () { Set?.Invoke (this, new (true)); }
/// <summary>To Raise the <see cref="UnSet"/> event from the LinearRange.</summary>
internal void OnUnSet () { UnSet?.Invoke (this, new (false)); }
}