WIP: Figuring out how to make margin transparent

This commit is contained in:
Tig
2024-10-30 15:47:38 -06:00
parent d835b569d8
commit fdeb8e90d1
11 changed files with 129 additions and 57 deletions

View File

@@ -437,8 +437,8 @@ public abstract class ConsoleDriver
/// </returns>
public virtual bool IsRuneSupported (Rune rune) { return Rune.IsValid (rune.Value); }
/// <summary>Tests whether the specified coordinate are valid for drawing.</summary>
/// <param name="rune"></param>
/// <summary>Tests whether the specified coordinate are valid for drawing the specified Rune.</summary>
/// <param name="rune">Used to determine if one or two columns are required.</param>
/// <param name="col">The column.</param>
/// <param name="row">The row.</param>
/// <returns>

View File

@@ -68,7 +68,12 @@ public class TextFormatter
return;
}
driver ??= Application.Driver;
if (driver is null)
{
driver = Application.Driver;
}
Debug.Assert (driver is { });
driver?.SetAttribute (normalColor);

View File

@@ -64,6 +64,39 @@ public class Border : Adornment
HighlightStyle |= HighlightStyle.Pressed;
Highlight += Border_Highlight;
ThicknessChanged += OnThicknessChanged;
}
private void OnThicknessChanged (object? sender, EventArgs e)
{
if (IsInitialized)
{
ShowHideDrawIndicator();
}
}
private void ShowHideDrawIndicator ()
{
if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator) && Thickness != Thickness.Empty)
{
if (DrawIndicator is null)
{
DrawIndicator = new SpinnerView ()
{
X = 1,
Style = new SpinnerStyle.Dots2 (),
SpinDelay = 0,
};
Add (DrawIndicator);
}
}
else if (DrawIndicator is { })
{
Remove (DrawIndicator);
DrawIndicator!.Dispose ();
DrawIndicator = null;
}
}
#if SUBVIEW_BASED_BORDER
@@ -80,6 +113,7 @@ public class Border : Adornment
{
base.BeginInit ();
ShowHideDrawIndicator ();
#if SUBVIEW_BASED_BORDER
if (Parent is { })
{
@@ -105,16 +139,6 @@ public class Border : Adornment
LayoutStarted += OnLayoutStarted;
}
#endif
if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator))
{
DrawIndicator = new SpinnerView ()
{
X = 1,
Style = new SpinnerStyle.Dots2 (),
SpinDelay = 0,
};
Add (DrawIndicator);
}
}
#if SUBVIEW_BASED_BORDER

View File

@@ -1,9 +1,17 @@
#nullable enable
using Microsoft.VisualBasic;
using static Terminal.Gui.SpinnerStyle;
using static Unix.Terminal.Curses;
using System.Text;
namespace Terminal.Gui;
/// <summary>The Margin for a <see cref="View"/>. Accessed via <see cref="View.Margin"/></summary>
/// <remarks>
/// <para>
/// The margin is typically transparent. This can be overriden by explicitly setting <see cref="ColorScheme"/>.
/// </para>
/// <para>See the <see cref="Adornment"/> class.</para>
/// </remarks>
public class Margin : Adornment
@@ -70,6 +78,7 @@ public class Margin : Adornment
/// <inheritdoc />
protected override bool OnClearingViewport ()
{
return ColorScheme is null;
if (Thickness == Thickness.Empty)
{
return true;
@@ -89,6 +98,25 @@ public class Margin : Adornment
return true;
}
/// <inheritdoc />
protected override bool OnDrawingContent ()
{
Rectangle screen = FrameToScreen();
for (int r = 0; r < screen.Height; r++)
{
for (int c = 0; c < screen.Width; c++)
{
Driver?.Move (c, r);
if (Driver?.Contents is { } && c < Driver.Contents.GetLength (1) && r < Driver.Contents.GetLength (0))
{
Driver.AddRune (Driver.Contents [r, c].Rune);
}
}
}
return true;
}
///// <inheritdoc />
////protected override bool OnDrawSubviews (Rectangle viewport) { return true; }

View File

@@ -46,6 +46,9 @@ public partial class View // Adornments
/// </summary>
/// <remarks>
/// <para>
/// The margin is typically transparent. This can be overriden by explicitly setting <see cref="ColorScheme"/>.
/// </para>
/// <para>
/// Enabling <see cref="ShadowStyle"/> will change the Thickness of the Margin to include the shadow.
/// </para>
/// <para>

View File

@@ -170,7 +170,6 @@ public partial class View
public Point ContentToScreen (in Point location)
{
// Subtract the ViewportOffsetFromFrame to get the Viewport-relative location.
Point viewportOffset = GetViewportOffsetFromFrame ();
Point contentRelativeToViewport = location;
contentRelativeToViewport.Offset (-Viewport.X, -Viewport.Y);

View File

@@ -25,23 +25,8 @@ public partial class View // Drawing APIs
Region? saved = null;
if (CanBeVisible (this) && (NeedsDraw || SubViewNeedsDraw))
{
if (Border is { Diagnostics: ViewDiagnosticFlags.DrawIndicator })
{
if (Border.DrawIndicator is { })
{
Border.DrawIndicator.AdvanceAnimation (false);
Border.DrawIndicator.DrawText ();
}
}
// Frame/View-relative relative, thus the bounds location should be 0,0
//Debug.Assert(clipRegion.GetBounds().X == 0 && clipRegion.GetBounds ().Y == 0);
saved = SetClipToFrame ();
DoDrawAdornments ();
DoSetAttribute ();
Application.SetClip (saved);
// By default, we clip to the viewport preventing drawing outside the viewport
@@ -51,19 +36,34 @@ public partial class View // Drawing APIs
saved = SetClipToViewport ();
DoSetAttribute ();
DoDrawSubviews ();
DoSetAttribute ();
DoClearViewport ();
DoSetAttribute ();
DoDrawText ();
DoSetAttribute ();
DoDrawContent ();
DoDrawSubviews ();
// Restore the clip before rendering the line canvas and adornment subviews
// because they may draw outside the viewport.
Application.SetClip (saved);
saved = SetClipToFrame ();
DoRenderLineCanvas ();
DoDrawAdornmentSubViews ();
if (Border is { Diagnostics: ViewDiagnosticFlags.DrawIndicator, DrawIndicator: { } })
{
Border.DrawIndicator.AdvanceAnimation (false);
Border.DrawIndicator.Render ();
}
ClearNeedsDraw ();
}
@@ -71,7 +71,8 @@ public partial class View // Drawing APIs
DoDrawComplete ();
Application.SetClip (saved);
if (this is not Adornment && Driver?.Clip is {})
if (this is not Adornment && Driver?.Clip is { })
{
Application.ExcludeFromClip (FrameToScreen ());
}
@@ -454,7 +455,7 @@ public partial class View // Drawing APIs
IEnumerable<View> subviewsNeedingDraw = _subviews.Where (view => (view.Visible));
#endif
foreach (View view in subviewsNeedingDraw.Reverse())
foreach (View view in subviewsNeedingDraw.Reverse ())
{
#if HACK_DRAW_OVERLAPPED
if (view.Arrangement.HasFlag (ViewArrangement.Overlapped))

View File

@@ -762,6 +762,8 @@ public class Shortcut : View, IOrientation, IDesignable
};
KeyView.ColorScheme = cs;
}
CommandView.Margin.ColorScheme = base.ColorScheme;
}
/// <inheritdoc/>

View File

@@ -186,14 +186,22 @@ public class SpinnerView : View, IDesignable
protected override bool OnClearingViewport () { return true; }
/// <inheritdoc />
protected override bool OnDrawingText ()
protected override bool OnDrawingContent ()
{
Render ();
return true;
}
/// <summary>
/// Renders the current frame of the spinner.
/// </summary>
public void Render ()
{
if (Sequence is { Length: > 0 } && _currentIdx < Sequence.Length)
{
Move (Viewport.X, Viewport.Y);
View.Driver?.AddStr (Sequence [_currentIdx]);
}
return true;
}
/// <inheritdoc/>

View File

@@ -17,9 +17,16 @@ public class AdvancedClipping : Scenario
Window app = new ()
{
Title = GetQuitKeyAndName (),
BorderStyle = LineStyle.None
//BorderStyle = LineStyle.None
};
app.DrawingText += (s, e) =>
{
Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
//app.SetSubViewNeedsDraw();
e.Cancel = true;
};
//var arrangementEditor = new ArrangementEditor()
//{
// X = Pos.AnchorEnd (),
@@ -30,26 +37,27 @@ public class AdvancedClipping : Scenario
View tiledView1 = CreateTiledView (1, 0, 0);
ProgressBar tiledProgressBar = new ()
{
X = 0,
Y = 1,
Y = Pos.AnchorEnd(),
Width = Dim.Fill (),
Id = "tiledProgressBar",
BidirectionalMarquee = true,
ProgressBarStyle = ProgressBarStyle.MarqueeBlocks
// BorderStyle = LineStyle.Rounded
};
tiledView1.Add (tiledProgressBar);
View tiledView2 = CreateTiledView (2, 2, 2);
View tiledView2 = CreateTiledView (2, 4, 2);
app.Add (tiledView1);
app.Add (tiledView2);
//View tiledView3 = CreateTiledView (3, 6, 6);
//app.Add (tiledView3);
View tiledView3 = CreateTiledView (3, 8, 4);
app.Add (tiledView3);
//using View overlappedView1 = CreateOverlappedView (1, 30, 2);
// View overlappedView1 = CreateOverlappedView (1, 30, 2);
//ProgressBar progressBar = new ()
//{
@@ -69,23 +77,15 @@ public class AdvancedClipping : Scenario
//app.Add (overlappedView2);
//app.Add (overlappedView3);
Timer progressTimer = new Timer (250)
Timer progressTimer = new Timer (150)
{
AutoReset = true
};
progressTimer.Elapsed += (s, e) =>
{
if (tiledProgressBar.Fraction == 1.0)
{
tiledProgressBar.Fraction = 0;
}
tiledProgressBar.Pulse();
Application.Wakeup ();
tiledProgressBar.Fraction += 0.1f;
// tiledProgressBar.SetNeedsDraw ();
};
progressTimer.Start ();
@@ -123,8 +123,8 @@ public class AdvancedClipping : Scenario
{
X = x,
Y = y,
Height = Dim.Auto (minimumContentDim: 4),
Width = Dim.Auto (minimumContentDim: 14),
Height = Dim.Auto (minimumContentDim: 8),
Width = Dim.Auto (minimumContentDim: 15),
Title = $"Tiled{id} _{GetNextHotKey ()}",
Id = $"Tiled{id}",
Text = $"Tiled{id}",
@@ -133,14 +133,16 @@ public class AdvancedClipping : Scenario
TabStop = TabBehavior.TabStop,
Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable
};
tiled.Padding.Thickness = new (1);
tiled.Padding.Diagnostics = ViewDiagnosticFlags.Thickness;
//tiled.Padding.Thickness = new (1);
//tiled.Padding.Diagnostics = ViewDiagnosticFlags.Thickness;
tiled.Margin.Thickness = new (1);
FrameView fv = new ()
{
Title = "FrameView",
Width = 15,
Height = 1,
Height = 3,
};
tiled.Add (fv);

View File

@@ -45,7 +45,7 @@ public class ShadowStyles : Scenario
app.DrawingText += (s, e) =>
{
Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), '*');
Application.Driver?.FillRect (app.ViewportToScreen (app.Viewport), CM.Glyphs.Dot);
e.Cancel = true;
};