Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Terminal.Gui/View/Adornment/Margin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Margin (View parent) : base (parent)

internal void CacheClip ()
{
if (Thickness != Thickness.Empty)
if (Thickness != Thickness.Empty && ShadowStyle != ShadowStyle.None)
{
// PERFORMANCE: How expensive are these clones?
_cachedClip = GetClip ()?.Clone ();
Expand Down
38 changes: 24 additions & 14 deletions Terminal.Gui/View/View.Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal static void Draw (IEnumerable<View> views, bool force)
view.Draw (context);
}

// Draw the margins (those whith Shadows) last to ensure they are drawn on top of the content.
Margin.DrawMargins (viewsArray);
}

Expand Down Expand Up @@ -57,9 +58,9 @@ public void Draw (DrawContext? context = null)
{
// ------------------------------------
// Draw the Border and Padding.
// Note Margin is special-cased and drawn in a separate pass to support
// Note Margin with a Shadow is special-cased and drawn in a separate pass to support
// transparent shadows.
DoDrawBorderAndPadding (originalClip);
DoDrawAdornments (originalClip);
SetClip (originalClip);

// ------------------------------------
Expand Down Expand Up @@ -106,7 +107,7 @@ public void Draw (DrawContext? context = null)
// ------------------------------------
// Re-draw the border and padding subviews
// HACK: This is a hack to ensure that the border and padding subviews are drawn after the line canvas.
DoDrawBorderAndPaddingSubViews ();
DoDrawAdornmentsSubViews ();

// ------------------------------------
// Advance the diagnostics draw indicator
Expand All @@ -116,8 +117,8 @@ public void Draw (DrawContext? context = null)
}

// ------------------------------------
// This causes the Margin to be drawn in a second pass
// PERFORMANCE: If there is a Margin, it will be redrawn each iteration of the main loop.
// This causes the Margin to be drawn in a second pass if it has a ShadowStyle
// PERFORMANCE: If there is a Margin w/ Shadow, it will be redrawn each iteration of the main loop.
Margin?.CacheClip ();

// ------------------------------------
Expand All @@ -131,8 +132,11 @@ public void Draw (DrawContext? context = null)

#region DrawAdornments

private void DoDrawBorderAndPaddingSubViews ()
private void DoDrawAdornmentsSubViews ()
{

// NOTE: We do not support subviews of Margin?

if (Border?.SubViews is { } && Border.Thickness != Thickness.Empty)
{
// PERFORMANCE: Get the check for DrawIndicator out of this somehow.
Expand Down Expand Up @@ -164,7 +168,7 @@ private void DoDrawBorderAndPaddingSubViews ()
}
}

private void DoDrawBorderAndPadding (Region? originalClip)
private void DoDrawAdornments (Region? originalClip)
{
if (this is Adornment)
{
Expand Down Expand Up @@ -194,27 +198,28 @@ private void DoDrawBorderAndPadding (Region? originalClip)
// A SubView may add to the LineCanvas. This ensures any Adornment LineCanvas updates happen.
Border?.SetNeedsDraw ();
Padding?.SetNeedsDraw ();
Margin?.SetNeedsDraw ();
}

if (OnDrawingBorderAndPadding ())
if (OnDrawingAdornments ())
{
return;
}

// TODO: add event.

DrawBorderAndPadding ();
DrawAdornments ();
}

/// <summary>
/// Causes <see cref="Border"/> and <see cref="Padding"/> to be drawn.
/// Causes <see cref="Margin"/>, <see cref="Border"/>, and <see cref="Padding"/> to be drawn.
/// </summary>
/// <remarks>
/// <para>
/// <see cref="Margin"/> is drawn in a separate pass.
/// <see cref="Margin"/> is drawn in a separate pass if <see cref="ShadowStyle"/> is set.
/// </para>
/// </remarks>
public void DrawBorderAndPadding ()
public void DrawAdornments ()
{
// We do not attempt to draw Margin. It is drawn in a separate pass.

Expand All @@ -230,6 +235,11 @@ public void DrawBorderAndPadding ()
Padding?.Draw ();
}


if (Margin is { } && Margin.Thickness != Thickness.Empty && Margin.ShadowStyle == ShadowStyle.None)
{
Margin?.Draw ();
}
}

private void ClearFrame ()
Expand All @@ -255,7 +265,7 @@ private void ClearFrame ()
/// false (the default), this method will cause the <see cref="LineCanvas"/> be prepared to be rendered.
/// </summary>
/// <returns><see langword="true"/> to stop further drawing of the Adornments.</returns>
protected virtual bool OnDrawingBorderAndPadding () { return false; }
protected virtual bool OnDrawingAdornments () { return false; }

#endregion DrawAdornments

Expand Down Expand Up @@ -635,7 +645,7 @@ private void DoRenderLineCanvas ()
/// <summary>
/// Gets or sets whether this View will use it's SuperView's <see cref="LineCanvas"/> for rendering any
/// lines. If <see langword="true"/> the rendering of any borders drawn by this Frame will be done by its parent's
/// SuperView. If <see langword="false"/> (the default) this View's <see cref="OnDrawingBorderAndPadding"/> method will
/// SuperView. If <see langword="false"/> (the default) this View's <see cref="OnDrawingAdornments"/> method will
/// be
/// called to render the borders.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/GraphView/Annotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void Render (GraphView graph)

if (BorderStyle != LineStyle.None)
{
DrawBorderAndPadding ();
DrawAdornments ();
RenderLineCanvas ();
}

Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/Menu/Menu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ private void Top_DrawComplete (object? sender, DrawEventArgs e)
return;
}

DrawBorderAndPadding ();
DrawAdornments ();
RenderLineCanvas ();

// BUGBUG: Views should not change the clip. Doing so is an indcation of poor design or a bug in the framework.
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/Views/TileView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public int IndexOf (View toFind, bool recursive = false)

/// <summary>Overridden so no Frames get drawn</summary>
/// <returns></returns>
protected override bool OnDrawingBorderAndPadding () { return true; }
protected override bool OnDrawingAdornments () { return true; }

/// <inheritdoc/>
protected override bool OnRenderingLineCanvas () { return false; }
Expand Down
18 changes: 16 additions & 2 deletions UICatalog/Scenarios/Generic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@ public override void Main ()
Title = GetQuitKeyAndName (),
};

var button = new Button { Id = "button", X = Pos.Center (), Y = 1, Text = "_Press me!" };
FrameView frame = new ()
{
Height = Dim.Fill (),
Width = Dim.Fill (),
Title = "Frame"
};
appWindow.Add (frame);

var button = new Shortcut ()
{
Id = "button",
X = Pos.Center (),
Y = 1,
Text = "_Press me!"
};

button.Accepting += (s, e) =>
{
Expand All @@ -27,7 +41,7 @@ public override void Main ()
MessageBox.ErrorQuery ("Error", "You pressed the button!", "_Ok");
};

appWindow.Add (button);
frame.Add (button);

// Run - Start the application.
Application.Run (appWindow);
Expand Down