Files
Terminal.Gui/Examples/UICatalog/Scenarios/LineExample.cs
Copilot fc9c40c2a0 Fixes #4150 - Finish implementing Line View (#4260)
* Initial plan

* Add comprehensive analysis of Line implementation status

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

* Complete Line implementation with documentation, example, and tests

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

* Add PR summary documenting Line implementation completion

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

* Add comprehensive completion report for Issue 4150

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

* Fix Line rendering: use SuperView's LineCanvas instead of own

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

* Redesign Line to use Border instead of manual LineCanvas

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

* Add Line.Style property to avoid BorderStyle conflict

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

* Add SetWidth/SetHeight methods to preserve dimensions on Orientation change

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

* Implement CWP events for Width/Height properties; update Line to use events

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

* WIP: Updating Line.
Cleaned up Layout tests.

* Made Height/Width non-nullable

* Add doWork stage to CWPPropertyHelper to execute between Changing and Changed events

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

* Move ViewLayoutEventTests to parallelizable tests without AutoInitShutdown

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

* Replace tracking fields with Length property for thread-safe Line implementation

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

* Fix orientation handling to preserve user-set dimensions in object initializers

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

* Simplify orientation handling with dimension swapping - all tests passing

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

* Add Length backing field and fix object initializer dimension handling

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

* Use CWP OnChanging events to manage dimensions instead of OnChanged

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

* Move LineTests to parallelizable; simplify tests with GetAnchor; fix Length property

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

* Code cleanup.

* Code cleanup.

* Update Terminal.Gui/ViewBase/View.Layout.cs

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

* Update Terminal.Gui/ViewBase/View.Layout.cs

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

* Update Terminal.Gui/ViewBase/View.Layout.cs

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

* Update Terminal.Gui/ViewBase/View.Layout.cs

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

* Fixed nullable warning in test

* Removed PR files and updated copilot guidance

* Reverted .gitignore change

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Tig <tig@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-10-03 12:26:45 -07:00

235 lines
6.3 KiB
C#

namespace UICatalog.Scenarios;
[ScenarioMetadata ("Line", "Demonstrates the Line view with LineCanvas integration.")]
[ScenarioCategory ("Controls")]
[ScenarioCategory ("Drawing")]
[ScenarioCategory ("Adornments")]
public class LineExample : Scenario
{
public override void Main ()
{
Application.Init ();
var app = new Window
{
Title = GetQuitKeyAndName ()
};
// Section 1: Basic Lines
var basicLabel = new Label
{
X = 0,
Y = 0,
Text = "Basic Lines:"
};
app.Add (basicLabel);
// Horizontal line
var hLine = new Line
{
X = 0,
Y = 1,
Width = 30
};
app.Add (hLine);
// Vertical line
var vLine = new Line
{
X = 32,
Y = 0,
Height = 10,
Orientation = Orientation.Vertical
};
app.Add (vLine);
// Section 2: Different Line Styles
var stylesLabel = new Label
{
X = 0,
Y = 3,
Text = "Line Styles:"
};
app.Add (stylesLabel);
(LineStyle, string) [] styles = new []
{
(LineStyle.Single, "Single"),
(LineStyle.Double, "Double"),
(LineStyle.Heavy, "Heavy"),
(LineStyle.Rounded, "Rounded"),
(LineStyle.Dashed, "Dashed"),
(LineStyle.Dotted, "Dotted")
};
var yPos = 4;
foreach ((LineStyle style, string name) in styles)
{
app.Add (new Label { X = 0, Y = yPos, Width = 15, Text = name + ":" });
app.Add (new Line { X = 16, Y = yPos, Width = 14, Style = style });
yPos++;
}
// Section 3: Line Intersections
var intersectionLabel = new Label
{
X = 35,
Y = 3,
Text = "Line Intersections:"
};
app.Add (intersectionLabel);
// Create a grid of intersecting lines
var gridX = 35;
var gridY = 5;
// Horizontal lines in the grid
for (var i = 0; i < 5; i++)
{
app.Add (
new Line
{
X = gridX,
Y = gridY + i * 2,
Width = 21,
Style = LineStyle.Single
});
}
// Vertical lines in the grid
for (var i = 0; i < 5; i++)
{
app.Add (
new Line
{
X = gridX + i * 5,
Y = gridY,
Height = 9,
Orientation = Orientation.Vertical,
Style = LineStyle.Single
});
}
// Section 4: Mixed Styles (shows how LineCanvas handles different line styles)
var mixedLabel = new Label
{
X = 60,
Y = 3,
Text = "Mixed Style Intersections:"
};
app.Add (mixedLabel);
// Double horizontal
app.Add (
new Line
{
X = 60,
Y = 5,
Width = 20,
Style = LineStyle.Double
});
// Single vertical through double horizontal
app.Add (
new Line
{
X = 70,
Y = 4,
Height = 3,
Orientation = Orientation.Vertical,
Style = LineStyle.Single
});
// Heavy horizontal
app.Add (
new Line
{
X = 60,
Y = 8,
Width = 20,
Style = LineStyle.Heavy
});
// Single vertical through heavy horizontal
app.Add (
new Line
{
X = 70,
Y = 7,
Height = 3,
Orientation = Orientation.Vertical,
Style = LineStyle.Single
});
// Section 5: Box Example (showing borders and lines working together)
var boxLabel = new Label
{
X = 0,
Y = 12,
Text = "Lines with Borders:"
};
app.Add (boxLabel);
var framedView = new FrameView
{
Title = "Frame",
X = 0,
Y = 13,
Width = 30,
Height = 8,
BorderStyle = LineStyle.Single
};
// Add a cross inside the frame
framedView.Add (
new Line
{
X = 0,
Y = 3,
Width = Dim.Fill (),
Style = LineStyle.Single
});
framedView.Add (
new Line
{
X = 14,
Y = 0,
Height = Dim.Fill (),
Orientation = Orientation.Vertical,
Style = LineStyle.Single
});
app.Add (framedView);
// Section 6: Comparison with LineView
var comparisonLabel = new Label
{
X = 35,
Y = 15,
Text = "Line vs LineView Comparison:"
};
app.Add (comparisonLabel);
app.Add (new Label { X = 35, Y = 16, Text = "Line (uses LineCanvas):" });
app.Add (new Line { X = 35, Y = 17, Width = 20, Style = LineStyle.Single });
app.Add (new Label { X = 35, Y = 18, Text = "LineView (direct render):" });
app.Add (new LineView { X = 35, Y = 19, Width = 20 });
// Add help text
var helpLabel = new Label
{
X = Pos.Center (),
Y = Pos.AnchorEnd (1),
Text = "Line integrates with LineCanvas for automatic intersection handling"
};
app.Add (helpLabel);
Application.Run (app);
app.Dispose ();
Application.Shutdown ();
}
}