Skip to content

Commit 2214d8c

Browse files
committed
#nullable enable
1 parent 66485a0 commit 2214d8c

File tree

11 files changed

+145
-157
lines changed

11 files changed

+145
-157
lines changed

Terminal.Gui/View/Adornment/Border.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void OnThicknessChanged (object? sender, EventArgs e)
7272
{
7373
if (IsInitialized)
7474
{
75-
ShowHideDrawIndicator();
75+
ShowHideDrawIndicator ();
7676
}
7777
}
7878

@@ -87,6 +87,7 @@ private void ShowHideDrawIndicator ()
8787
X = 1,
8888
Style = new SpinnerStyle.Dots2 (),
8989
SpinDelay = 0,
90+
Visible = false
9091
};
9192
Add (DrawIndicator);
9293
}
@@ -99,6 +100,15 @@ private void ShowHideDrawIndicator ()
99100
}
100101
}
101102

103+
internal void AdvanceDrawIndicator ()
104+
{
105+
if (View.Diagnostics.HasFlag (ViewDiagnosticFlags.DrawIndicator) && DrawIndicator is { })
106+
{
107+
DrawIndicator.AdvanceAnimation (false);
108+
DrawIndicator.Render ();
109+
}
110+
}
111+
102112
#if SUBVIEW_BASED_BORDER
103113
private Line _left;
104114

@@ -164,15 +174,7 @@ private void OnLayoutStarted (object sender, LayoutEventArgs e)
164174
/// </summary>
165175
public override ColorScheme? ColorScheme
166176
{
167-
get
168-
{
169-
if (base.ColorScheme is { })
170-
{
171-
return base.ColorScheme;
172-
}
173-
174-
return Parent?.ColorScheme;
175-
}
177+
get => base.ColorScheme ?? Parent?.ColorScheme;
176178
set
177179
{
178180
base.ColorScheme = value;

Terminal.Gui/View/Adornment/Margin.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,20 @@ public Margin (View parent) : base (parent)
4040

4141
// When the Parent is drawn, we cache the clip region so we can draw the Margin after all other Views
4242
// QUESTION: Why can't this just be the NeedsDisplay region?
43-
internal Region? CachedClip { get; set; }
43+
private Region? _cachedClip;
44+
45+
internal Region? GetCachedClip () { return _cachedClip; }
46+
47+
internal void ClearCachedClip () { _cachedClip = null; }
48+
49+
internal void CacheClip ()
50+
{
51+
if (Thickness != Thickness.Empty)
52+
{
53+
// PERFORMANCE: How expensive are these clones?
54+
_cachedClip = GetClip ()?.Clone ();
55+
}
56+
}
4457

4558
// PERFORMANCE: Margins are ALWAYS drawn. This may be an issue for apps that have a large number of views with shadows.
4659
/// <summary>
@@ -57,22 +70,22 @@ internal static bool DrawMargins (IEnumerable<View> margins)
5770
{
5871
var view = stack.Pop ();
5972

60-
if (view.Margin is { CachedClip: { } })
73+
if (view.Margin?.GetCachedClip() != null)
6174
{
6275
view.Margin.NeedsDraw = true;
6376
Region? saved = GetClip ();
64-
View.SetClip (view.Margin.CachedClip);
77+
View.SetClip (view.Margin.GetCachedClip ());
6578
view.Margin.Draw ();
6679
View.SetClip (saved);
67-
view.Margin.CachedClip = null;
80+
view.Margin.ClearCachedClip ();
6881
}
6982

83+
view.NeedsDraw = false;
84+
7085
foreach (var subview in view.Subviews)
7186
{
7287
stack.Push (subview);
7388
}
74-
75-
view.NeedsDraw = false;
7689
}
7790

7891
return true;
@@ -297,4 +310,5 @@ private void Margin_LayoutStarted (object? sender, LayoutEventArgs e)
297310
}
298311

299312
#endregion Shadow
313+
300314
}

Terminal.Gui/View/Adornment/Padding.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace Terminal.Gui;
1+
#nullable enable
2+
namespace Terminal.Gui;
23

34
/// <summary>The Padding for a <see cref="View"/>. Accessed via <see cref="View.Padding"/></summary>
45
/// <remarks>
@@ -21,17 +22,9 @@ public Padding (View parent) : base (parent)
2122
/// The color scheme for the Padding. If set to <see langword="null"/>, gets the <see cref="Adornment.Parent"/>
2223
/// scheme. color scheme.
2324
/// </summary>
24-
public override ColorScheme ColorScheme
25+
public override ColorScheme? ColorScheme
2526
{
26-
get
27-
{
28-
if (base.ColorScheme is { })
29-
{
30-
return base.ColorScheme;
31-
}
32-
33-
return Parent?.ColorScheme;
34-
}
27+
get => base.ColorScheme ?? Parent?.ColorScheme;
3528
set
3629
{
3730
base.ColorScheme = value;

Terminal.Gui/View/Adornment/ShadowView.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@ internal class ShadowView : View
1414
/// <inheritdoc/>
1515
public override Attribute GetNormalColor ()
1616
{
17-
if (SuperView is Adornment adornment)
17+
if (SuperView is not Adornment adornment)
1818
{
19-
var attr = Attribute.Default;
19+
return base.GetNormalColor ();
20+
}
2021

21-
if (adornment.Parent?.SuperView is { })
22-
{
23-
attr = adornment.Parent.SuperView.GetNormalColor ();
24-
}
25-
else if (Application.Top is { })
26-
{
27-
attr = Application.Top.GetNormalColor ();
28-
}
22+
var attr = Attribute.Default;
2923

30-
return new (
31-
new Attribute (
32-
ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
33-
ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor ()));
24+
if (adornment.Parent?.SuperView is { })
25+
{
26+
attr = adornment.Parent.SuperView.GetNormalColor ();
27+
}
28+
else if (Application.Top is { })
29+
{
30+
attr = Application.Top.GetNormalColor ();
3431
}
3532

36-
return base.GetNormalColor ();
33+
return new (
34+
new Attribute (
35+
ShadowStyle == ShadowStyle.Opaque ? Color.Black : attr.Foreground.GetDarkerColor (),
36+
ShadowStyle == ShadowStyle.Opaque ? attr.Background : attr.Background.GetDarkerColor ()));
37+
3738
}
3839

3940
/// <inheritdoc />

Terminal.Gui/View/View.Attribute.cs

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,23 @@ public partial class View
1313
/// <summary>The color scheme for this view, if it is not defined, it returns the <see cref="SuperView"/>'s color scheme.</summary>
1414
public virtual ColorScheme? ColorScheme
1515
{
16-
get
17-
{
18-
if (_colorScheme is null)
19-
{
20-
return SuperView?.ColorScheme;
21-
}
22-
23-
return _colorScheme;
24-
}
16+
get => _colorScheme ?? SuperView?.ColorScheme;
2517
set
2618
{
27-
if (_colorScheme != value)
19+
if (_colorScheme == value)
2820
{
29-
_colorScheme = value;
21+
return;
22+
}
3023

31-
// BUGBUG: This should be in Border.cs somehow
32-
if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { })
33-
{
34-
Border.ColorScheme = _colorScheme;
35-
}
24+
_colorScheme = value;
3625

37-
SetNeedsDraw ();
26+
// BUGBUG: This should be in Border.cs somehow
27+
if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { })
28+
{
29+
Border.ColorScheme = _colorScheme;
3830
}
31+
32+
SetNeedsDraw ();
3933
}
4034
}
4135

@@ -47,12 +41,7 @@ public virtual ColorScheme? ColorScheme
4741
/// </returns>
4842
public virtual Attribute GetFocusColor ()
4943
{
50-
ColorScheme? cs = ColorScheme;
51-
52-
if (cs is null)
53-
{
54-
cs = new ();
55-
}
44+
ColorScheme? cs = ColorScheme ?? new ();
5645

5746
return Enabled ? GetColor (cs.Focus) : cs.Disabled;
5847
}
@@ -78,12 +67,7 @@ public virtual Attribute GetHotFocusColor ()
7867
/// </returns>
7968
public virtual Attribute GetHotNormalColor ()
8069
{
81-
ColorScheme? cs = ColorScheme;
82-
83-
if (cs is null)
84-
{
85-
cs = new ();
86-
}
70+
ColorScheme? cs = ColorScheme ?? new ();
8771

8872
return Enabled ? GetColor (cs.HotNormal) : cs.Disabled;
8973
}
@@ -96,12 +80,7 @@ public virtual Attribute GetHotNormalColor ()
9680
/// </returns>
9781
public virtual Attribute GetNormalColor ()
9882
{
99-
ColorScheme? cs = ColorScheme;
100-
101-
if (cs is null)
102-
{
103-
cs = new ();
104-
}
83+
ColorScheme? cs = ColorScheme ?? new ();
10584

10685
Attribute disabled = new (cs.Disabled.Foreground, cs.Disabled.Background);
10786

Terminal.Gui/View/View.Drawing.cs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public void Draw ()
6464
if (SubViewNeedsDraw)
6565
{
6666
DoSetAttribute ();
67-
6867
DoDrawSubviews ();
6968
}
7069

@@ -84,22 +83,14 @@ public void Draw ()
8483

8584
DoDrawBorderAndPaddingSubViews ();
8685

87-
if (Border is { Diagnostics: ViewDiagnosticFlags.DrawIndicator, DrawIndicator: { } })
88-
{
89-
Border.DrawIndicator.AdvanceAnimation (false);
90-
Border.DrawIndicator.Render ();
91-
}
86+
Border?.AdvanceDrawIndicator ();
9287

9388
ClearNeedsDraw ();
9489
}
9590

9691
// This causes the Margin to be drawn in a second pass
9792
// PERFORMANCE: If there is a Margin, it will be redrawn each iteration of the main loop.
98-
if (Margin is { } && Margin?.Thickness != Thickness.Empty)
99-
{
100-
// PERFORMANCE: How expensive are these clones?
101-
Margin!.CachedClip = GetClip ()?.Clone ();
102-
}
93+
Margin?.CacheClip ();
10394

10495
// We're done drawing
10596
DoDrawComplete ();
@@ -622,7 +613,7 @@ protected virtual void OnDrawComplete () { }
622613
public bool NeedsDraw
623614
{
624615
// TODO: Figure out if we can decouple NeedsDraw from NeedsLayout. This is a temporary fix.
625-
get => _needsDrawRect != Rectangle.Empty || NeedsLayout;
616+
get => Visible && (_needsDrawRect != Rectangle.Empty || NeedsLayout);
626617
set
627618
{
628619
if (value)
@@ -636,8 +627,22 @@ public bool NeedsDraw
636627
}
637628
}
638629

630+
private bool _subViewNeedsDraw;
631+
639632
/// <summary>Gets whether any Subviews need to be redrawn.</summary>
640-
public bool SubViewNeedsDraw { get; private set; }
633+
public bool SubViewNeedsDraw
634+
{
635+
get => _subViewNeedsDraw;
636+
private set
637+
{
638+
//if (!Visible)
639+
//{
640+
// _subViewNeedsDraw = false;
641+
// return;
642+
//}
643+
_subViewNeedsDraw = value;
644+
}
645+
}
641646

642647
/// <summary>Sets that the <see cref="Viewport"/> of this View needs to be redrawn.</summary>
643648
/// <remarks>
@@ -648,7 +653,7 @@ public void SetNeedsDraw ()
648653
{
649654
Rectangle viewport = Viewport;
650655

651-
if (_needsDrawRect != Rectangle.Empty && viewport.IsEmpty)
656+
if (/*!Visible || */(_needsDrawRect != Rectangle.Empty && viewport.IsEmpty))
652657
{
653658
// This handles the case where the view has not been initialized yet
654659
return;
@@ -670,6 +675,10 @@ public void SetNeedsDraw ()
670675
/// <param name="viewPortRelativeRegion">The <see cref="Viewport"/>relative region that needs to be redrawn.</param>
671676
public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
672677
{
678+
//if (!Visible)
679+
//{
680+
// return;
681+
//}
673682
if (_needsDrawRect.IsEmpty)
674683
{
675684
_needsDrawRect = viewPortRelativeRegion;
@@ -683,10 +692,10 @@ public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
683692
_needsDrawRect = new (x, y, w, h);
684693
}
685694

686-
if (Margin is { } && Margin.Thickness != Thickness.Empty)
687-
{
688-
Margin?.SetNeedsDraw ();
689-
}
695+
//if (Margin is { } && Margin.Thickness != Thickness.Empty)
696+
//{
697+
// Margin?.SetNeedsDraw ();
698+
//}
690699

691700
if (Border is { } && Border.Thickness != Thickness.Empty)
692701
{
@@ -700,7 +709,7 @@ public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
700709

701710
SuperView?.SetSubViewNeedsDraw ();
702711

703-
if (this is Adornment adornment)
712+
if (this is Adornment adornment /*and (Gui.Padding or Gui.Border)*/)
704713
{
705714
adornment.Parent?.SetSubViewNeedsDraw ();
706715
}
@@ -720,9 +729,15 @@ public void SetNeedsDraw (Rectangle viewPortRelativeRegion)
720729
/// <summary>Sets <see cref="SubViewNeedsDraw"/> to <see langword="true"/> for this View and all Superviews.</summary>
721730
public void SetSubViewNeedsDraw ()
722731
{
732+
//if (!Visible)
733+
//{
734+
// SubViewNeedsDraw = false;
735+
// return;
736+
//}
737+
723738
SubViewNeedsDraw = true;
724739

725-
if (this is Adornment adornment)
740+
if (this is Adornment adornment/* and (Gui.Padding or Gui.Border)*/)
726741
{
727742
adornment.Parent?.SetSubViewNeedsDraw ();
728743
}
@@ -758,6 +773,11 @@ protected void ClearNeedsDraw ()
758773
{
759774
subview.ClearNeedsDraw ();
760775
}
776+
777+
if (SuperView is { })
778+
{
779+
SuperView.SubViewNeedsDraw = false;
780+
}
761781
}
762782

763783
#endregion NeedsDraw

0 commit comments

Comments
 (0)