diff --git a/Terminal.Gui/Drawing/Glyphs.cs b/Terminal.Gui/Drawing/Glyphs.cs
index 18d83de50..a42c1c40b 100644
--- a/Terminal.Gui/Drawing/Glyphs.cs
+++ b/Terminal.Gui/Drawing/Glyphs.cs
@@ -437,4 +437,24 @@ public class GlyphDefinitions
public Rune CrossHv { get; set; } = (Rune)'╋';
#endregion
+
+ #region ----------------- ShadowStyle -----------------
+
+
+ /// Shadow - Vertical Start - Left Half Block - ▌ U+0258c
+ public Rune ShadowVerticalStart { get; set; } = (Rune)'▌'; // Half: '\u2596' ▖;
+
+ /// Shadow - Vertical - Left Half Block - ▌ U+0258c
+ public Rune ShadowVertical { get; set; } = (Rune)'▌';
+
+ /// Shadow - Horizontal Start - Upper Half Block - ▀ U+02580
+ public Rune ShadowHorizontalStart { get; set; } = (Rune)'▀'; // Half: ▝ U+0259d;
+
+ /// Shadow - Horizontal - Upper Half Block - ▀ U+02580
+ public Rune ShadowHorizontal { get; set; } = (Rune)'▀';
+
+ /// Shadow - Horizontal End - Quadrant Upper Left - ▘ U+02598
+ public Rune ShadowHorizontalEnd { get; set; } = (Rune)'▘';
+
+ #endregion
}
diff --git a/Terminal.Gui/View/Adornment/ShadowStyle.cs b/Terminal.Gui/View/Adornment/ShadowStyle.cs
index e95d76d5b..a410292c6 100644
--- a/Terminal.Gui/View/Adornment/ShadowStyle.cs
+++ b/Terminal.Gui/View/Adornment/ShadowStyle.cs
@@ -1,18 +1,17 @@
-#nullable enable
-namespace Terminal.Gui;
+namespace Terminal.Gui;
///
-/// Defines the style of shadow to be drawn on the right and bottom sides of the .
+/// Defines the style of shadow to be drawn on the right and bottom sides of the .
///
public enum ShadowStyle
{
///
- /// No shadow.
+ /// No shadow.
///
None,
///
- /// A shadow that is drawn using block elements. Ideal for smaller views such as buttons.
+ /// A shadow that is drawn using block elements. Ideal for smaller views such as buttons.
///
Opaque,
diff --git a/Terminal.Gui/View/Adornment/ShadowView.cs b/Terminal.Gui/View/Adornment/ShadowView.cs
index a2849e8b1..c5e7a428a 100644
--- a/Terminal.Gui/View/Adornment/ShadowView.cs
+++ b/Terminal.Gui/View/Adornment/ShadowView.cs
@@ -6,19 +6,15 @@ namespace Terminal.Gui;
///
internal class ShadowView : View
{
- // TODO: Add these to CM.Glyphs
- private readonly char VERTICAL_START_GLYPH = '\u258C'; // Half: '\u2596';
- private readonly char VERTICAL_GLYPH = '\u258C';
- private readonly char HORIZONTAL_START_GLYPH = '\u2580'; // Half: '\u259d';
- private readonly char HORIZONTAL_GLYPH = '\u2580';
- private readonly char HORIZONTAL_END_GLYPH = '\u2598';
+ private ShadowStyle _shadowStyle;
///
public override Attribute GetNormalColor ()
{
if (SuperView is Adornment adornment)
{
- Attribute attr = Attribute.Default;
+ var attr = Attribute.Default;
+
if (adornment.Parent.SuperView is { })
{
attr = adornment.Parent.SuperView.GetNormalColor ();
@@ -27,8 +23,11 @@ internal class ShadowView : View
{
attr = Application.Top.GetNormalColor ();
}
- return new (new Attribute (ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
- ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor()));
+
+ return new (
+ new Attribute (
+ ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
+ ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor ()));
}
return base.GetNormalColor ();
@@ -77,7 +76,6 @@ internal class ShadowView : View
///
public Orientation Orientation { get; set; }
- private ShadowStyle _shadowStyle;
public override ShadowStyle ShadowStyle
{
get => _shadowStyle;
@@ -91,22 +89,23 @@ internal class ShadowView : View
private void DrawHorizontalShadowOpaque (Rectangle rectangle)
{
// Draw the start glyph
- AddRune (0, 0, (Rune)HORIZONTAL_START_GLYPH);
+ AddRune (0, 0, Glyphs.ShadowHorizontalStart);
- // Fill the rest of the rectangle with the glyph
+ // Fill the rest of the rectangle with the glyph - note we skip the last since vertical will draw it
for (var i = 1; i < rectangle.Width - 1; i++)
{
- AddRune (i, 0, (Rune)HORIZONTAL_GLYPH);
+ AddRune (i, 0, Glyphs.ShadowHorizontal);
}
// Last is special
- AddRune (rectangle.Width - 1, 0, (Rune)HORIZONTAL_END_GLYPH);
+ AddRune (rectangle.Width - 1, 0, Glyphs.ShadowHorizontalEnd);
}
private void DrawHorizontalShadowTransparent (Rectangle viewport)
{
Rectangle screen = ViewportToScreen (viewport);
+ // Fill the rest of the rectangle - note we skip the last since vertical will draw it
for (int i = screen.X; i < screen.X + screen.Width - 1; i++)
{
Driver.Move (i, screen.Y);
@@ -117,12 +116,12 @@ internal class ShadowView : View
private void DrawVerticalShadowOpaque (Rectangle viewport)
{
// Draw the start glyph
- AddRune (0, 0, (Rune)VERTICAL_START_GLYPH);
+ AddRune (0, 0, Glyphs.ShadowVerticalStart);
// Fill the rest of the rectangle with the glyph
for (var i = 1; i < viewport.Height; i++)
{
- AddRune (0, i, (Rune)VERTICAL_GLYPH);
+ AddRune (0, i, Glyphs.ShadowVertical);
}
}
@@ -130,7 +129,7 @@ internal class ShadowView : View
{
Rectangle screen = ViewportToScreen (viewport);
- // Fill the rest of the rectangle with the glyph
+ // Fill the rest of the rectangle
for (int i = screen.Y; i < screen.Y + viewport.Height; i++)
{
Driver.Move (screen.X, i);
diff --git a/UICatalog/Scenarios/ThreeD.cs b/UICatalog/Scenarios/ShadowStyles.cs
similarity index 92%
rename from UICatalog/Scenarios/ThreeD.cs
rename to UICatalog/Scenarios/ShadowStyles.cs
index ea23f73a9..c3eccc9a9 100644
--- a/UICatalog/Scenarios/ThreeD.cs
+++ b/UICatalog/Scenarios/ShadowStyles.cs
@@ -7,9 +7,9 @@ using Terminal.Gui;
namespace UICatalog.Scenarios;
-[ScenarioMetadata ("3D Effects Demo", "Demonstrates 3D UI Effects.")]
+[ScenarioMetadata ("ShadowStyles Demo", "Demonstrates ShadowStyles Effects.")]
[ScenarioCategory ("Layout")]
-public class ThreeD : Scenario
+public class ShadowStyles : Scenario
{
public override void Main ()
{
diff --git a/UnitTests/View/Adornment/ShadowStyletests.cs b/UnitTests/View/Adornment/ShadowStyletests.cs
index 19fe61d4d..c8f3f8063 100644
--- a/UnitTests/View/Adornment/ShadowStyletests.cs
+++ b/UnitTests/View/Adornment/ShadowStyletests.cs
@@ -7,11 +7,10 @@ public class ShadowStyleTests (ITestOutputHelper _output)
[Fact]
public void Default_None ()
{
- View view = new View ();
+ var view = new View ();
Assert.Equal (ShadowStyle.None, view.ShadowStyle);
Assert.Equal (ShadowStyle.None, view.Margin.ShadowStyle);
view.Dispose ();
-
}
[Theory]
@@ -20,13 +19,12 @@ public class ShadowStyleTests (ITestOutputHelper _output)
[InlineData (ShadowStyle.Transparent)]
public void Set_View_Sets_Margin (ShadowStyle style)
{
- View view = new View ();
+ var view = new View ();
view.ShadowStyle = style;
Assert.Equal (style, view.ShadowStyle);
Assert.Equal (style, view.Margin.ShadowStyle);
view.Dispose ();
-
}
[Theory]
@@ -35,41 +33,46 @@ public class ShadowStyleTests (ITestOutputHelper _output)
[InlineData (ShadowStyle.Transparent, 4)]
public void Style_Changes_Magin_Thickness (ShadowStyle style, int expected)
{
- View view = new View ();
+ var view = new View ();
view.Margin.Thickness = new (3);
view.ShadowStyle = style;
- Assert.Equal (new Thickness (3, 3, expected, expected), view.Margin.Thickness);
+ Assert.Equal (new (3, 3, expected, expected), view.Margin.Thickness);
view.ShadowStyle = ShadowStyle.None;
- Assert.Equal (new Thickness (3), view.Margin.Thickness);
+ Assert.Equal (new (3), view.Margin.Thickness);
view.Dispose ();
-
}
// Visual tests
[Theory]
- [InlineData (ShadowStyle.None, """
- 01#$
- AB#$
- !@#$
- !@#$
- """)]
- [InlineData (ShadowStyle.Opaque, """
- 01#$
- AB▌$
- !▀▘$
- !@#$
- """)]
- [InlineData (ShadowStyle.Transparent, """
- 01#$
- AB#$
- !@#$
- !@#$
- """)]
+ [InlineData (
+ ShadowStyle.None,
+ """
+ 01#$
+ AB#$
+ !@#$
+ !@#$
+ """)]
+ [InlineData (
+ ShadowStyle.Opaque,
+ """
+ 01#$
+ AB▌$
+ !▀▘$
+ !@#$
+ """)]
+ [InlineData (
+ ShadowStyle.Transparent,
+ """
+ 01#$
+ AB#$
+ !@#$
+ !@#$
+ """)]
[SetupFakeDriver]
public void Visual_Test (ShadowStyle style, string expected)
{
- View superView = new View ()
+ var superView = new View
{
Width = 4,
Height = 4,
@@ -77,19 +80,18 @@ public class ShadowStyleTests (ITestOutputHelper _output)
};
superView.TextFormatter.WordWrap = true;
- View view = new View ()
+ var view = new View
{
Text = "01\nAB",
Width = Dim.Auto (),
- Height = Dim.Auto (),
+ Height = Dim.Auto ()
};
view.ShadowStyle = style;
superView.Add (view);
- superView.BeginInit();
- superView.EndInit();
+ superView.BeginInit ();
+ superView.EndInit ();
superView.Draw ();
-// view.Draw ();
TestHelpers.AssertDriverContentsWithFrameAre (expected, _output);
view.Dispose ();
}