Skip to content

Commit

Permalink
#nullable enable - Attribute.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
tig committed Nov 4, 2024
1 parent 7656602 commit 66485a0
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions Terminal.Gui/View/View.Attribute.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;

#nullable enable
namespace Terminal.Gui;

public partial class View
Expand All @@ -8,11 +7,11 @@ public partial class View
// TODO: See https://github.com/gui-cs/Terminal.Gui/issues/457

#region ColorScheme
private ColorScheme _colorScheme;

private ColorScheme? _colorScheme;

/// <summary>The color scheme for this view, if it is not defined, it returns the <see cref="SuperView"/>'s color scheme.</summary>
public virtual ColorScheme ColorScheme
public virtual ColorScheme? ColorScheme
{
get
{
Expand All @@ -29,6 +28,7 @@ public virtual ColorScheme ColorScheme
{
_colorScheme = value;

// BUGBUG: This should be in Border.cs somehow
if (Border is { } && Border.LineStyle != LineStyle.None && Border.ColorScheme is { })
{
Border.ColorScheme = _colorScheme;
Expand All @@ -47,7 +47,7 @@ public virtual ColorScheme ColorScheme
/// </returns>
public virtual Attribute GetFocusColor ()
{
ColorScheme cs = ColorScheme;
ColorScheme? cs = ColorScheme;

if (cs is null)
{
Expand All @@ -65,20 +65,20 @@ public virtual Attribute GetFocusColor ()
/// </returns>
public virtual Attribute GetHotFocusColor ()
{
ColorScheme cs = ColorScheme ?? new ();
ColorScheme? cs = ColorScheme ?? new ();

return Enabled ? GetColor (cs.HotFocus) : cs.Disabled;
}

/// <summary>Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.</summary>
/// <returns>
/// <see cref="Terminal.Gui.ColorScheme.HotNormal"/> if <see cref="Enabled"/> is <see langword="true"/> or
/// <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
/// <see cref="ColorScheme.HotNormal"/> if <see cref="Enabled"/> is <see langword="true"/> or
/// <see cref="ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
/// overridden can return other values.
/// </returns>
public virtual Attribute GetHotNormalColor ()
{
ColorScheme cs = ColorScheme;
ColorScheme? cs = ColorScheme;

if (cs is null)
{
Expand All @@ -90,13 +90,13 @@ public virtual Attribute GetHotNormalColor ()

/// <summary>Determines the current <see cref="ColorScheme"/> based on the <see cref="Enabled"/> value.</summary>
/// <returns>
/// <see cref="Terminal.Gui.ColorScheme.Normal"/> if <see cref="Enabled"/> is <see langword="true"/> or
/// <see cref="Terminal.Gui.ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
/// <see cref="ColorScheme.Normal"/> if <see cref="Enabled"/> is <see langword="true"/> or
/// <see cref="ColorScheme.Disabled"/> if <see cref="Enabled"/> is <see langword="false"/>. If it's
/// overridden can return other values.
/// </returns>
public virtual Attribute GetNormalColor ()
{
ColorScheme cs = ColorScheme;
ColorScheme? cs = ColorScheme;

if (cs is null)
{
Expand Down Expand Up @@ -132,16 +132,11 @@ private Attribute GetColor (Attribute inputAttribute)
/// <summary>Selects the specified attribute as the attribute to use for future calls to AddRune and AddString.</summary>
/// <remarks></remarks>
/// <param name="attribute">THe Attribute to set.</param>
public Attribute SetAttribute (Attribute attribute)
{
return Driver?.SetAttribute (attribute) ?? Attribute.Default;
}
public Attribute SetAttribute (Attribute attribute) { return Driver?.SetAttribute (attribute) ?? Attribute.Default; }

/// <summary>Gets the current <see cref="Attribute"/>.</summary>
/// <returns>The current attribute.</returns>
public Attribute GetAttribute ()
{
return Driver?.GetAttribute () ?? Attribute.Default;
}
public Attribute GetAttribute () { return Driver?.GetAttribute () ?? Attribute.Default; }

#endregion Attribute
}

0 comments on commit 66485a0

Please sign in to comment.