forked from space-wizards/RobustToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/space-wizards/RobustToolbox…
… into swap-positions-method
Showing
299 changed files
with
6,876 additions
and
2,942 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
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,58 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.CSharp.Testing; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.CodeAnalysis.Testing.Verifiers; | ||
using NUnit.Framework; | ||
using VerifyCS = | ||
Microsoft.CodeAnalysis.CSharp.Testing.NUnit.AnalyzerVerifier<Robust.Analyzers.DependencyAssignAnalyzer>; | ||
|
||
namespace Robust.Analyzers.Tests; | ||
|
||
[Parallelizable(ParallelScope.All | ParallelScope.Fixtures)] | ||
[TestFixture] | ||
public sealed class DependencyAssignAnalyzerTest | ||
{ | ||
private static Task Verifier(string code, params DiagnosticResult[] expected) | ||
{ | ||
var test = new CSharpAnalyzerTest<DependencyAssignAnalyzer, NUnitVerifier>() | ||
{ | ||
TestState = | ||
{ | ||
Sources = { code } | ||
}, | ||
}; | ||
|
||
TestHelper.AddEmbeddedSources( | ||
test.TestState, | ||
"Robust.Shared.IoC.DependencyAttribute.cs" | ||
); | ||
|
||
// ExpectedDiagnostics cannot be set, so we need to AddRange here... | ||
test.TestState.ExpectedDiagnostics.AddRange(expected); | ||
|
||
return test.RunAsync(); | ||
} | ||
|
||
[Test] | ||
public async Task Test() | ||
{ | ||
const string code = """ | ||
using Robust.Shared.IoC; | ||
public sealed class Foo | ||
{ | ||
[Dependency] | ||
private object? Field; | ||
public Foo() | ||
{ | ||
Field = "A"; | ||
} | ||
} | ||
"""; | ||
|
||
await Verifier(code, | ||
// /0/Test0.cs(10,9): warning RA0025: Tried to assign to [Dependency] field 'Field'. Remove [Dependency] or inject it via field injection instead. | ||
VerifyCS.Diagnostic().WithSpan(10, 9, 10, 20).WithArguments("Field")); | ||
} | ||
} |
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,22 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Robust.Analyzers.Tests; | ||
|
||
public static class TestHelper | ||
{ | ||
public static void AddEmbeddedSources(SolutionState state, params string[] embeddedFiles) | ||
{ | ||
AddEmbeddedSources(state, (IEnumerable<string>) embeddedFiles); | ||
} | ||
|
||
public static void AddEmbeddedSources(SolutionState state, IEnumerable<string> embeddedFiles) | ||
{ | ||
foreach (var fileName in embeddedFiles) | ||
{ | ||
using var stream = typeof(AccessAnalyzer_Test).Assembly.GetManifestResourceStream(fileName)!; | ||
state.Sources.Add((fileName, SourceText.From(stream))); | ||
} | ||
} | ||
} |
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,61 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.Operations; | ||
using Robust.Roslyn.Shared; | ||
|
||
namespace Robust.Analyzers; | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public sealed class DependencyAssignAnalyzer : DiagnosticAnalyzer | ||
{ | ||
private const string DependencyAttributeType = "Robust.Shared.IoC.DependencyAttribute"; | ||
|
||
private static readonly DiagnosticDescriptor Rule = new ( | ||
Diagnostics.IdDependencyFieldAssigned, | ||
"Assignment to dependency field", | ||
"Tried to assign to [Dependency] field '{0}'. Remove [Dependency] or inject it via field injection instead.", | ||
"Usage", | ||
DiagnosticSeverity.Warning, | ||
true); | ||
|
||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(Rule); | ||
|
||
public override void Initialize(AnalysisContext context) | ||
{ | ||
context.EnableConcurrentExecution(); | ||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None); | ||
context.RegisterOperationAction(CheckAssignment, OperationKind.SimpleAssignment); | ||
} | ||
|
||
private static void CheckAssignment(OperationAnalysisContext context) | ||
{ | ||
if (context.Operation is not ISimpleAssignmentOperation assignment) | ||
return; | ||
|
||
if (assignment.Target is not IFieldReferenceOperation fieldRef) | ||
return; | ||
|
||
var field = fieldRef.Field; | ||
var attributes = field.GetAttributes(); | ||
if (attributes.Length == 0) | ||
return; | ||
|
||
var depAttribute = context.Compilation.GetTypeByMetadataName(DependencyAttributeType); | ||
if (!HasAttribute(attributes, depAttribute)) | ||
return; | ||
|
||
context.ReportDiagnostic(Diagnostic.Create(Rule, assignment.Syntax.GetLocation(), field.Name)); | ||
} | ||
|
||
private static bool HasAttribute(ImmutableArray<AttributeData> attributes, ISymbol symbol) | ||
{ | ||
foreach (var attribute in attributes) | ||
{ | ||
if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, symbol)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
83 changes: 83 additions & 0 deletions
83
Robust.Benchmarks/Collections/ValueListEnumerationBenchmarks.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,83 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BenchmarkDotNet.Attributes; | ||
using Robust.Shared.Analyzers; | ||
using Robust.Shared.Collections; | ||
|
||
namespace Robust.Benchmarks.Collections; | ||
|
||
[Virtual] | ||
public class ValueListEnumerationBenchmarks | ||
{ | ||
[Params(4, 16, 64)] | ||
public int N { get; set; } | ||
|
||
private sealed class Data(int i) | ||
{ | ||
public readonly int I = i; | ||
} | ||
|
||
private ValueList<Data> _valueList; | ||
private Data[] _array = default!; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
var list = new List<Data>(N); | ||
for (var i = 0; i < N; i++) | ||
{ | ||
list.Add(new(i)); | ||
} | ||
|
||
_array = list.ToArray(); | ||
_valueList = new(list.ToArray()); | ||
} | ||
|
||
[Benchmark] | ||
public int ValueList() | ||
{ | ||
var total = 0; | ||
foreach (var ev in _valueList) | ||
{ | ||
total += ev.I; | ||
} | ||
|
||
return total; | ||
} | ||
|
||
[Benchmark] | ||
public int ValueListSpan() | ||
{ | ||
var total = 0; | ||
foreach (var ev in _valueList.Span) | ||
{ | ||
total += ev.I; | ||
} | ||
|
||
return total; | ||
} | ||
|
||
[Benchmark] | ||
public int Array() | ||
{ | ||
var total = 0; | ||
foreach (var ev in _array) | ||
{ | ||
total += ev.I; | ||
} | ||
|
||
return total; | ||
} | ||
|
||
[Benchmark] | ||
public int Span() | ||
{ | ||
var total = 0; | ||
foreach (var ev in _array.AsSpan()) | ||
{ | ||
total += ev.I; | ||
} | ||
|
||
return total; | ||
} | ||
} |
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
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
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
82 changes: 3 additions & 79 deletions
82
Robust.Client/GameObjects/EntitySystems/UserInterfaceSystem.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 |
---|---|---|
@@ -1,84 +1,8 @@ | ||
using Robust.Client.Player; | ||
using Robust.Shared.GameObjects; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Reflection; | ||
using System; | ||
using UserInterfaceComponent = Robust.Shared.GameObjects.UserInterfaceComponent; | ||
|
||
namespace Robust.Client.GameObjects | ||
{ | ||
public sealed class UserInterfaceSystem : SharedUserInterfaceSystem | ||
{ | ||
[Dependency] private readonly IDynamicTypeFactory _dynamicTypeFactory = default!; | ||
[Dependency] private readonly IPlayerManager _playerManager = default!; | ||
[Dependency] private readonly IReflectionManager _reflectionManager = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeNetworkEvent<BoundUIWrapMessage>(MessageReceived); | ||
} | ||
|
||
private void MessageReceived(BoundUIWrapMessage ev) | ||
{ | ||
var uid = GetEntity(ev.Entity); | ||
|
||
if (!TryComp<UserInterfaceComponent>(uid, out var cmp)) | ||
return; | ||
|
||
var uiKey = ev.UiKey; | ||
var message = ev.Message; | ||
message.Session = _playerManager.LocalSession!; | ||
message.Entity = GetNetEntity(uid); | ||
message.UiKey = uiKey; | ||
|
||
// Raise as object so the correct type is used. | ||
RaiseLocalEvent(uid, (object)message, true); | ||
|
||
switch (message) | ||
{ | ||
case OpenBoundInterfaceMessage _: | ||
TryOpenUi(uid, uiKey, cmp); | ||
break; | ||
|
||
case CloseBoundInterfaceMessage _: | ||
TryCloseUi(message.Session, uid, uiKey, remoteCall: true, uiComp: cmp); | ||
break; | ||
namespace Robust.Client.GameObjects; | ||
|
||
default: | ||
if (cmp.OpenInterfaces.TryGetValue(uiKey, out var bui)) | ||
bui.InternalReceiveMessage(message); | ||
|
||
break; | ||
} | ||
} | ||
|
||
private bool TryOpenUi(EntityUid uid, Enum uiKey, UserInterfaceComponent? uiComp = null) | ||
{ | ||
if (!Resolve(uid, ref uiComp)) | ||
return false; | ||
|
||
if (uiComp.OpenInterfaces.ContainsKey(uiKey)) | ||
return false; | ||
|
||
var data = uiComp.MappedInterfaceData[uiKey]; | ||
|
||
// TODO: This type should be cached, but I'm too lazy. | ||
var type = _reflectionManager.LooseGetType(data.ClientType); | ||
var boundInterface = | ||
(BoundUserInterface) _dynamicTypeFactory.CreateInstance(type, new object[] {uid, uiKey}); | ||
|
||
boundInterface.Open(); | ||
uiComp.OpenInterfaces[uiKey] = boundInterface; | ||
|
||
if (_playerManager.LocalSession is { } playerSession) | ||
{ | ||
uiComp.Interfaces[uiKey]._subscribedSessions.Add(playerSession); | ||
RaiseLocalEvent(uid, new BoundUIOpenedEvent(uiKey, uid, playerSession), true); | ||
} | ||
public sealed class UserInterfaceSystem : SharedUserInterfaceSystem | ||
{ | ||
|
||
return 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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
varying highp vec2 UV; | ||
varying highp vec2 UV2; | ||
varying highp vec2 Pos; | ||
varying highp vec4 VtxModulate; | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
varying highp vec2 UV; | ||
varying highp vec2 UV2; | ||
|
||
uniform sampler2D lightMap; | ||
|
||
|
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
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
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
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
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,132 @@ | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Robust.Client.UserInterface; | ||
|
||
public partial class Control | ||
{ | ||
private LayoutStyleProperties _layoutStyleOverride; | ||
private LayoutStyleProperties _layoutStyleSheet; | ||
|
||
private void UpdateLayoutStyleProperties() | ||
{ | ||
var propertiesSet = LayoutStyleProperties.None; | ||
|
||
// Assumed most controls will have little or no style properties, | ||
// so iterating once is less expensive overall then checking 10+ properties. | ||
// C# switch statements are compiled efficiently anyways. | ||
foreach (var (key, value) in _styleProperties) | ||
{ | ||
switch (key) | ||
{ | ||
case nameof(SizeFlagsStretchRatio): | ||
UpdateField(ref _sizeFlagsStretchRatio, value, LayoutStyleProperties.StretchRatio); | ||
break; | ||
case nameof(MinWidth): | ||
UpdateField(ref _minWidth, value, LayoutStyleProperties.MinWidth); | ||
break; | ||
case nameof(MinHeight): | ||
UpdateField(ref _minHeight, value, LayoutStyleProperties.MinHeight); | ||
break; | ||
case nameof(SetWidth): | ||
UpdateField(ref _setWidth, value, LayoutStyleProperties.SetWidth); | ||
break; | ||
case nameof(SetHeight): | ||
UpdateField(ref _setHeight, value, LayoutStyleProperties.SetHeight); | ||
break; | ||
case nameof(MaxWidth): | ||
UpdateField(ref _maxWidth, value, LayoutStyleProperties.MaxWidth); | ||
break; | ||
case nameof(MaxHeight): | ||
UpdateField(ref _maxHeight, value, LayoutStyleProperties.MaxHeight); | ||
break; | ||
case nameof(HorizontalExpand): | ||
UpdateField(ref _horizontalExpand, value, LayoutStyleProperties.HorizontalExpand); | ||
break; | ||
case nameof(VerticalExpand): | ||
UpdateField(ref _verticalExpand, value, LayoutStyleProperties.VerticalExpand); | ||
break; | ||
case nameof(HorizontalAlignment): | ||
UpdateField(ref _horizontalAlignment, value, LayoutStyleProperties.HorizontalAlignment); | ||
break; | ||
case nameof(VerticalAlignment): | ||
UpdateField(ref _verticalAlignment, value, LayoutStyleProperties.VerticalAlignment); | ||
break; | ||
case nameof(Margin): | ||
UpdateField(ref _margin, value, LayoutStyleProperties.Margin); | ||
break; | ||
} | ||
} | ||
|
||
// Reset cleared properties back to defaults. | ||
var toClear = _layoutStyleSheet & ~propertiesSet; | ||
if (toClear != 0) | ||
{ | ||
ClearField(ref _sizeFlagsStretchRatio, DefaultStretchRatio, LayoutStyleProperties.StretchRatio); | ||
ClearField(ref _minWidth, 0, LayoutStyleProperties.MinWidth); | ||
ClearField(ref _minHeight, 0, LayoutStyleProperties.MinHeight); | ||
ClearField(ref _setWidth, DefaultSetSize, LayoutStyleProperties.SetWidth); | ||
ClearField(ref _setHeight, DefaultSetSize, LayoutStyleProperties.SetHeight); | ||
ClearField(ref _maxWidth, DefaultMaxSize, LayoutStyleProperties.MaxWidth); | ||
ClearField(ref _maxHeight, DefaultMaxSize, LayoutStyleProperties.MaxHeight); | ||
ClearField(ref _horizontalExpand, false, LayoutStyleProperties.HorizontalExpand); | ||
ClearField(ref _verticalExpand, false, LayoutStyleProperties.VerticalExpand); | ||
ClearField(ref _horizontalAlignment, DefaultHAlignment, LayoutStyleProperties.HorizontalAlignment); | ||
ClearField(ref _verticalAlignment, DefaultVAlignment, LayoutStyleProperties.VerticalAlignment); | ||
ClearField(ref _margin, default, LayoutStyleProperties.Margin); | ||
} | ||
|
||
_layoutStyleSheet = propertiesSet; | ||
|
||
return; | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
void UpdateField<T>(ref T field, object value, LayoutStyleProperties flag) | ||
{ | ||
if ((_layoutStyleOverride & flag) != 0) | ||
return; | ||
|
||
// TODO: Probably need better error handling... | ||
if (value is not T valueCast) | ||
return; | ||
|
||
field = valueCast; | ||
propertiesSet |= flag; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
void ClearField<T>(ref T field, T defaultValue, LayoutStyleProperties flag) | ||
{ | ||
if ((toClear & flag) == 0) | ||
return; | ||
|
||
field = defaultValue; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
private void SetLayoutStyleProp(LayoutStyleProperties flag) | ||
{ | ||
_layoutStyleOverride |= flag; | ||
} | ||
|
||
[Flags] | ||
private enum LayoutStyleProperties : short | ||
{ | ||
// @formatter:off | ||
None = 0, | ||
Margin = 1 << 0, | ||
MinWidth = 1 << 1, | ||
MinHeight = 1 << 2, | ||
SetWidth = 1 << 3, | ||
SetHeight = 1 << 4, | ||
MaxWidth = 1 << 5, | ||
MaxHeight = 1 << 6, | ||
StretchRatio = 1 << 7, | ||
HorizontalExpand = 1 << 8, | ||
VerticalExpand = 1 << 9, | ||
HorizontalAlignment = 1 << 10, | ||
VerticalAlignment = 1 << 11, | ||
// @formatter:on | ||
} | ||
} |
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
Oops, something went wrong.