-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Work on scroll view component
- Loading branch information
Showing
13 changed files
with
398 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Oxide.Ext.UiFramework.Json; | ||
using Oxide.Ext.UiFramework.Pooling; | ||
|
||
namespace Oxide.Ext.UiFramework.Components | ||
{ | ||
public abstract class BasePoolableComponent : BasePoolable, IComponent | ||
{ | ||
public bool Enabled = true; | ||
|
||
public virtual void WriteComponent(JsonFrameworkWriter writer) | ||
{ | ||
writer.AddField(JsonDefaults.Common.EnabledName, Enabled, true); | ||
} | ||
|
||
protected override void EnterPool() | ||
{ | ||
Reset(); | ||
} | ||
|
||
public virtual void Reset() | ||
{ | ||
Enabled = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Oxide.Ext.UiFramework.Json; | ||
using Oxide.Ext.UiFramework.Offsets; | ||
using Oxide.Ext.UiFramework.Positions; | ||
|
||
namespace Oxide.Ext.UiFramework.Components; | ||
|
||
public abstract class RectTransformComponent : IComponent | ||
{ | ||
public UiPosition Position; | ||
public UiOffset Offset; | ||
|
||
public abstract void WriteComponent(JsonFrameworkWriter writer); | ||
|
||
public virtual void Reset() | ||
{ | ||
Position = default; | ||
Offset = default; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using Oxide.Ext.UiFramework.Json; | ||
using UnityEngine.UI; | ||
|
||
namespace Oxide.Ext.UiFramework.Components; | ||
|
||
public class ScrollViewComponent : IComponent | ||
{ | ||
private const string Type = "UnityEngine.UI.ScrollView"; | ||
|
||
public ScrollViewContentTransformComponent ContentTransform = new(); | ||
public bool Horizontal; | ||
public bool Vertical; | ||
public ScrollRect.MovementType MovementType = ScrollRect.MovementType.Clamped; | ||
public float Elasticity = JsonDefaults.ScrollView.Elasticity; | ||
public bool Inertia; | ||
public float DecelerationRate = JsonDefaults.ScrollView.DecelerationRate; | ||
public float ScrollSensitivity = JsonDefaults.ScrollView.ScrollSensitivity; | ||
public ScrollbarComponent HorizontalScrollbar; | ||
public ScrollbarComponent VerticalScrollbar; | ||
|
||
public void WriteComponent(JsonFrameworkWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.AddFieldRaw(JsonDefaults.Common.ComponentTypeName, Type); | ||
writer.AddField(JsonDefaults.ScrollView.Horizontal, Horizontal, false); | ||
writer.AddField(JsonDefaults.ScrollView.Vertical, Vertical, false); | ||
writer.AddField(JsonDefaults.ScrollView.MovementType, MovementType); | ||
writer.AddField(JsonDefaults.ScrollView.ElasticityName, Elasticity, JsonDefaults.ScrollView.Elasticity); | ||
writer.AddField(JsonDefaults.ScrollView.Inertia, Inertia, false); | ||
writer.AddField(JsonDefaults.ScrollView.DecelerationRateName, DecelerationRate, JsonDefaults.ScrollView.DecelerationRate); | ||
writer.AddField(JsonDefaults.ScrollView.ScrollSensitivityName, ScrollSensitivity, JsonDefaults.ScrollView.ScrollSensitivity); | ||
|
||
if (Horizontal) | ||
{ | ||
writer.AddComponent(JsonDefaults.ScrollView.HorizontalScrollbar, HorizontalScrollbar); | ||
} | ||
|
||
if (Vertical) | ||
{ | ||
writer.AddComponent(JsonDefaults.ScrollView.VerticalScrollbar, VerticalScrollbar); | ||
} | ||
|
||
if (ContentTransform != null) | ||
{ | ||
writer.AddComponent(JsonDefaults.ScrollView.ContentTransform, ContentTransform); | ||
} | ||
|
||
writer.WriteEndObject(); | ||
} | ||
|
||
public void Reset() | ||
{ | ||
ContentTransform.Reset(); | ||
Horizontal = false; | ||
Vertical = false; | ||
MovementType = ScrollRect.MovementType.Clamped; | ||
Elasticity = JsonDefaults.ScrollView.Elasticity; | ||
Inertia = false; | ||
DecelerationRate = JsonDefaults.ScrollView.DecelerationRate; | ||
ScrollSensitivity = JsonDefaults.ScrollView.ScrollSensitivity; | ||
HorizontalScrollbar = null; | ||
VerticalScrollbar = null; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Rust.UIFramework/Components/ScrollViewContentTransformComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Oxide.Ext.UiFramework.Json; | ||
using Oxide.Ext.UiFramework.Offsets; | ||
using Oxide.Ext.UiFramework.Positions; | ||
|
||
namespace Oxide.Ext.UiFramework.Components; | ||
|
||
public class ScrollViewContentTransformComponent : RectTransformComponent | ||
{ | ||
public ScrollViewContentTransformComponent() | ||
{ | ||
Position = new UiPosition(0, 0, 1, 1); | ||
Offset = new UiOffset(0, 0, 0, 0); | ||
} | ||
|
||
public override void WriteComponent(JsonFrameworkWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
writer.AddPosition(JsonDefaults.Position.AnchorMinName, Position.Min, JsonDefaults.ScrollView.Min); | ||
writer.AddPosition(JsonDefaults.Position.AnchorMaxName, Position.Max, JsonDefaults.ScrollView.AnchorMax); | ||
writer.AddOffset(JsonDefaults.Offset.OffsetMinName, Offset.Min, JsonDefaults.ScrollView.Min); | ||
writer.AddOffset(JsonDefaults.Offset.OffsetMaxName, Offset.Max, JsonDefaults.ScrollView.OffsetMax); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
public override void Reset() | ||
{ | ||
Position = new UiPosition(0, 0, 1, 1); | ||
Offset = new UiOffset(0, 0, 0, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Oxide.Ext.UiFramework.Colors; | ||
using Oxide.Ext.UiFramework.Json; | ||
|
||
namespace Oxide.Ext.UiFramework.Components; | ||
|
||
public class ScrollbarComponent : BasePoolableComponent | ||
{ | ||
public bool Invert; | ||
public bool AutoHide; | ||
public string HandleSprite; | ||
public string TrackSprite; | ||
public float Size = JsonDefaults.ScrollBar.Size; | ||
public UiColor HandleColor = JsonDefaults.ScrollBar.HandleColor; | ||
public UiColor HighlightColor = JsonDefaults.ScrollBar.HighlightColor; | ||
public UiColor PressedColor = JsonDefaults.ScrollBar.PressedColor; | ||
public UiColor TrackColor = JsonDefaults.ScrollBar.TrackColor; | ||
|
||
public override void WriteComponent(JsonFrameworkWriter writer) | ||
{ | ||
writer.WriteStartObject(); | ||
base.WriteComponent(writer); | ||
writer.AddField(JsonDefaults.ScrollBar.Invert, Invert, false); | ||
writer.AddField(JsonDefaults.ScrollBar.AutoHide, AutoHide, false); | ||
writer.AddField(JsonDefaults.ScrollBar.HandleSprite, HandleSprite, null); | ||
writer.AddField(JsonDefaults.ScrollBar.TrackSprite, TrackSprite, null); | ||
writer.AddField(JsonDefaults.ScrollBar.SizeName, Size, JsonDefaults.ScrollBar.Size); | ||
writer.AddField(JsonDefaults.ScrollBar.HandleColorName, HandleColor, JsonDefaults.ScrollBar.HandleColor); | ||
writer.AddField(JsonDefaults.ScrollBar.HighlightColorName, HighlightColor, JsonDefaults.ScrollBar.HighlightColor); | ||
writer.AddField(JsonDefaults.ScrollBar.PressedColorName, PressedColor, JsonDefaults.ScrollBar.PressedColor); | ||
writer.AddField(JsonDefaults.ScrollBar.TrackColorName, TrackColor, JsonDefaults.ScrollBar.TrackColor); | ||
writer.WriteEndObject(); | ||
} | ||
|
||
public override void Reset() | ||
{ | ||
base.Reset(); | ||
Invert = false; | ||
AutoHide = false; | ||
HandleSprite = null; | ||
TrackSprite = null; | ||
Size = JsonDefaults.ScrollBar.Size; | ||
HandleColor = JsonDefaults.ScrollBar.HandleColor; | ||
HighlightColor = JsonDefaults.ScrollBar.HighlightColor; | ||
PressedColor = JsonDefaults.ScrollBar.PressedColor; | ||
TrackColor = JsonDefaults.ScrollBar.TrackColor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.