ソースを参照

Refactor nullable checks

Jean-David Moisan 3 年 前
コミット
c29c93eeb9
7 ファイル変更20 行追加20 行削除
  1. 3 3
      Source/Button.cs
  2. 3 3
      Source/Component.cs
  3. 4 4
      Source/Dock.cs
  4. 3 3
      Source/Horizontal.cs
  5. 3 3
      Source/IMGUI.cs
  6. 1 1
      Source/Slider.cs
  7. 3 3
      Source/Vertical.cs

+ 3 - 3
Source/Button.cs

@@ -127,16 +127,16 @@ namespace Apos.Gui {
         public int NextIndex() => 0;
 
         public override IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : Child != null ? Child : this;
+            return Parent?.GetPrev(this) ?? Child ?? this;
         }
         public override IComponent GetNext() {
-            return Child != null ? Child : Parent != null ? Parent.GetNext(this) : this;
+            return Child ?? Parent?.GetNext(this) ?? this;
         }
         public virtual IComponent GetPrev(IComponent c) {
             return this;
         }
         public virtual IComponent GetNext(IComponent c) {
-            return Parent != null ? Parent.GetNext(this) : this;
+            return Parent?.GetNext(this) ?? this;
         }
 
         public virtual void SendToTop(IComponent c) {

+ 3 - 3
Source/Component.cs

@@ -31,7 +31,7 @@ namespace Apos.Gui {
         public virtual IParent? Parent { get; set; }
 
         public virtual RectangleF Clip {
-            get => _clip != null ? _clip.Value : Bounds;
+            get => _clip ?? Bounds;
             set {
                 _clip = value;
             }
@@ -48,14 +48,14 @@ namespace Apos.Gui {
         /// Otherwise, it will return itself.
         /// </summary>
         public virtual IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : this;
+            return Parent?.GetPrev(this) ?? this;
         }
         /// <summary>
         /// If this component has a parent, it will ask the parent to return this component's next neighbor.
         /// Otherwise, it will return itself.
         /// </summary>
         public virtual IComponent GetNext() {
-            return Parent != null ? Parent.GetNext(this) : this;
+            return Parent?.GetNext(this) ?? this;
         }
         public virtual IComponent GetLast() {
             return this;

+ 4 - 4
Source/Dock.cs

@@ -70,19 +70,19 @@ namespace Apos.Gui {
         public int NextIndex() => 0;
 
         public override IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : Child != null ? Child.GetLast() : this;
+            return Parent?.GetPrev(this) ?? Child?.GetLast() ?? this;
         }
         public override IComponent GetNext() {
-            return Child != null ? Child : Parent != null ? Parent.GetNext(this) : this;
+            return Child ?? Parent?.GetNext(this) ?? this;
         }
         public virtual IComponent GetPrev(IComponent c) {
             return this;
         }
         public virtual IComponent GetNext(IComponent c) {
-            return Parent != null ? Parent.GetNext(this) : this;
+            return Parent?.GetNext(this) ?? this;
         }
         public virtual IComponent GetLast() {
-            return Child != null ? Child.GetLast() : this;
+            return Child?.GetLast() ?? this;
         }
 
         public virtual void SendToTop(IComponent c) {

+ 3 - 3
Source/Horizontal.cs

@@ -151,7 +151,7 @@ namespace Apos.Gui {
         /// Otherwise it will return itself.
         /// </summary>
         public override IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : _children.Count > 0 ? _children.Last().GetLast() : this;
+            return Parent?.GetPrev(this) ?? (_children.Count > 0 ? _children.Last().GetLast() : this);
         }
         /// <summary>
         /// If this component has children, it will return the first one.
@@ -159,7 +159,7 @@ namespace Apos.Gui {
         /// Otherwise, it will return itself.
         /// </summary>
         public override IComponent GetNext() {
-            return _children.Count > 0 ? _children.First() : Parent != null ? Parent.GetNext(this) : this;
+            return _children.Count > 0 ? _children.First() : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// If the child isn't the first one, it will return the child before it.
@@ -176,7 +176,7 @@ namespace Apos.Gui {
         /// </summary>
         public virtual IComponent GetNext(IComponent c) {
             int index = c.Index + 1;
-            return index < _children.Count ? _children[index] : Parent != null ? Parent.GetNext(this) : this;
+            return index < _children.Count ? _children[index] : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// Returns the last child in this component tree.

+ 3 - 3
Source/IMGUI.cs

@@ -290,7 +290,7 @@ namespace Apos.Gui {
         /// Otherwise it will return itself.
         /// </summary>
         public override IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : _children.Count > 0 ? _children.Last().GetLast() : this;
+            return Parent?.GetPrev(this) ?? (_children.Count > 0 ? _children.Last().GetLast() : this);
         }
         /// <summary>
         /// If this component has children, it will return the first one.
@@ -298,7 +298,7 @@ namespace Apos.Gui {
         /// Otherwise, it will return itself.
         /// </summary>
         public override IComponent GetNext() {
-            return _children.Count > 0 ? _children.First() : Parent != null ? Parent.GetNext(this) : this;
+            return _children.Count > 0 ? _children.First() : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// If the child isn't the first one, it will return the child before it.
@@ -315,7 +315,7 @@ namespace Apos.Gui {
         /// </summary>
         public virtual IComponent GetNext(IComponent c) {
             int index = c.Index + 1;
-            return index < _children.Count ? _children[index] : Parent != null ? Parent.GetNext(this) : this;
+            return index < _children.Count ? _children[index] : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// Returns the last child in this component tree.

+ 1 - 1
Source/Slider.cs

@@ -16,7 +16,7 @@ namespace Apos.Gui {
         public float Min { get; set; }
         public float Max { get; set; }
         public float? Step {
-            get => _step != null ? _step.Value : (Max - Min) / 100;
+            get => _step ?? (Max - Min) / 100f;
             set {
                 _step = value;
             }

+ 3 - 3
Source/Vertical.cs

@@ -151,7 +151,7 @@ namespace Apos.Gui {
         /// Otherwise it will return itself.
         /// </summary>
         public override IComponent GetPrev() {
-            return Parent != null ? Parent.GetPrev(this) : _children.Count > 0 ? _children.Last().GetLast() : this;
+            return Parent?.GetPrev(this) ?? (_children.Count > 0 ? _children.Last().GetLast() : this);
         }
         /// <summary>
         /// If this component has children, it will return the first one.
@@ -159,7 +159,7 @@ namespace Apos.Gui {
         /// Otherwise, it will return itself.
         /// </summary>
         public override IComponent GetNext() {
-            return _children.Count > 0 ? _children.First() : Parent != null ? Parent.GetNext(this) : this;
+            return _children.Count > 0 ? _children.First() : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// If the child isn't the first one, it will return the child before it.
@@ -176,7 +176,7 @@ namespace Apos.Gui {
         /// </summary>
         public virtual IComponent GetNext(IComponent c) {
             int index = c.Index + 1;
-            return index < _children.Count ? _children[index] : Parent != null ? Parent.GetNext(this) : this;
+            return index < _children.Count ? _children[index] : Parent?.GetNext(this) ?? this;
         }
         /// <summary>
         /// Returns the last child in this component tree.