-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Consolonia.Themes.TurboVision/Templates/Controls/Helpers/FastLineSeparator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Layout; | ||
using Avalonia.Media; | ||
|
||
namespace Consolonia.Themes.TurboVision.Templates.Controls.Helpers | ||
{ | ||
public class FastLineSeparator : Control | ||
{ | ||
public static readonly StyledProperty<Orientation> OrientationProperty = | ||
AvaloniaProperty.Register<FastLineSeparator, Orientation>(nameof(Orientation), Orientation.Horizontal); | ||
|
||
public Orientation Orientation | ||
{ | ||
get => GetValue(OrientationProperty); | ||
set => SetValue(OrientationProperty, value); | ||
} | ||
|
||
public static readonly StyledProperty<IBrush> BrushProperty = | ||
AvaloniaProperty.Register<FastLineSeparator, IBrush>(nameof(Brush), Brushes.Black); | ||
|
||
public IBrush Brush | ||
{ | ||
get => GetValue(BrushProperty); | ||
set => SetValue(BrushProperty, value); | ||
} | ||
|
||
|
||
public FastLineSeparator() | ||
{ | ||
AffectsRender<FastLineSeparator>(OrientationProperty); | ||
} | ||
|
||
protected override Size MeasureOverride(Size availableSize) | ||
{ | ||
return Orientation == Orientation.Horizontal | ||
? new Size(0, 1) | ||
: new Size(1, 0); | ||
} | ||
|
||
protected override Size ArrangeOverride(Size finalSize) | ||
{ | ||
return finalSize; | ||
} | ||
|
||
public override void Render(DrawingContext context) | ||
{ | ||
var pen = new Pen(Brush); | ||
|
||
if (Orientation == Orientation.Horizontal) | ||
{ | ||
// Draw a horizontal line across the control's width | ||
var startPoint = new Point(0, Bounds.Height / 2); | ||
var endPoint = new Point(Bounds.Width-1, Bounds.Height / 2); | ||
context.DrawLine(pen, startPoint, endPoint); | ||
} | ||
else | ||
{ | ||
// Draw a vertical line across the control's height | ||
var startPoint = new Point(Bounds.Width / 2, 0); | ||
var endPoint = new Point(Bounds.Width / 2, Bounds.Height-1); | ||
context.DrawLine(pen, startPoint, endPoint); | ||
} | ||
} | ||
|
||
} | ||
} |