diff --git a/RueI/RueI/Display.cs b/RueI/RueI/Display.cs index a34b081..d51e271 100644 --- a/RueI/RueI/Display.cs +++ b/RueI/RueI/Display.cs @@ -2,6 +2,7 @@ { using MEC; using RueI.Extensions; + using RueI.Interfaces; /// /// Represents a that hides elements based on an active screen. @@ -39,7 +40,8 @@ public ScreenDisplay(ReferenceHub hub, T defaultScreen) /// /// Represents a display attached to a . /// - public class Display : DisplayBase + /// + public class Display : DisplayBase, IElementContainer { /// /// Gets the ratelimit used for displaying hints. diff --git a/RueI/RueI/Extensions/ElementHelpers.cs b/RueI/RueI/Extensions/ElementHelpers.cs index aa046d5..7a54f8f 100644 --- a/RueI/RueI/Extensions/ElementHelpers.cs +++ b/RueI/RueI/Extensions/ElementHelpers.cs @@ -1,28 +1,37 @@ -namespace RueI.Extensions +namespace RueI.Extensions; + +using RueI.Interfaces; + +/// +/// Provides extensions and helpers for working with elements. +/// +public static class ElementHelpers { /// - /// Provides extensions and helpers for working with elements. + /// Adds an to a . /// - public static class ElementHelpers - { - /// - /// Gets the functional (un-scaled) position of an element. - /// - /// The element to get the position for. - /// The un-scaled position.. - public static float GetFunctionalPosition(this IElement element) => Ruetility.ScaledPositionToFunctional(element.Position); + /// The element to add. + /// The to add to. + /// A reference to this element. + public static IElement AddTo(this IElement element, IElementContainer container) => element.AddTo(container.Elements); - /// - /// Calculates the offset for two hints. - /// - /// The first hint's vertical position. - /// The first hint's total line-height, excluding the vertical position. - /// The second hint's vertical position. - /// A float indicating the new offset. - public static float CalculateOffset(float hintOnePos, float hintOneTotalLines, float hintTwoPos) - { - float calc = (hintOnePos + (2 * hintOneTotalLines)) - hintTwoPos; - return calc / -2; - } + /// + /// Gets the functional (un-scaled) position of an element. + /// + /// The element to get the position for. + /// The un-scaled position.. + public static float GetFunctionalPosition(this IElement element) => Ruetility.ScaledPositionToFunctional(element.Position); + + /// + /// Calculates the offset for two hints. + /// + /// The first hint's vertical position. + /// The first hint's total line-height, excluding the vertical position. + /// The second hint's vertical position. + /// A float indicating the new offset. + public static float CalculateOffset(float hintOnePos, float hintOneTotalLines, float hintTwoPos) + { + float calc = (hintOnePos + (2 * hintOneTotalLines)) - hintTwoPos; + return calc / -2; } } \ No newline at end of file diff --git a/RueI/RueI/Extensions/UniversalExtensions.cs b/RueI/RueI/Extensions/UniversalExtensions.cs index bf4da89..0d40166 100644 --- a/RueI/RueI/Extensions/UniversalExtensions.cs +++ b/RueI/RueI/Extensions/UniversalExtensions.cs @@ -13,9 +13,12 @@ public static class UniversalExtensions /// The type of this instance and the collection to add to. /// The instance to add. /// The collection to add the elements to. - public static void AddTo(this T item, ICollection collection) + /// A reference to . + public static T AddTo(this T item, ICollection collection) + where T : class { collection.Add(item); + return item; } } } diff --git a/RueI/RueI/Interfaces/IElementContainer.cs b/RueI/RueI/Interfaces/IElementContainer.cs new file mode 100644 index 0000000..6b8f595 --- /dev/null +++ b/RueI/RueI/Interfaces/IElementContainer.cs @@ -0,0 +1,13 @@ +namespace RueI.Interfaces +{ + /// + /// Defines a container for multiple elements. + /// + public interface IElementContainer + { + /// + /// Gets the elements of this . + /// + public List Elements { get; } + } +} diff --git a/RueI/RueI/Parsing/Parser.cs b/RueI/RueI/Parsing/Parser.cs index 097e17a..c95f5de 100644 --- a/RueI/RueI/Parsing/Parser.cs +++ b/RueI/RueI/Parsing/Parser.cs @@ -1,4 +1,4 @@ -namespace RueI +namespace RueI { using System.Collections.Generic; using System.Collections.ObjectModel; @@ -12,7 +12,7 @@ namespace RueI /// /// Helps parse the content of elements. /// - /// + /// public class Parser { /// @@ -74,22 +74,23 @@ public ParsedData Parse(string text) void FailTagMatch() // not a tag, unload buffer { - AddCharacter(context, '<') + AddCharacter(context, '<'); + this.AvoidMatch(context); foreach (char ch in tagBuffer.ToString()) { AddCharacter(context, ch); } - if (delimiter != null) + foreach (char ch in paramBuffer.ToString()) { - AddCharacter(context, delimiter.Value); - delimiter = null; + AddCharacter(context, ch); } - foreach (char ch in paramBuffer.ToString()) + if (delimiter != null) { - AddCharacter(context, ch); + AddCharacter(context, delimiter.Value); + delimiter = null; } tagBuffer.Clear(); @@ -104,11 +105,6 @@ void FailTagMatch() // not a tag, unload buffer { if (ch == '<') { - if (currentState != ParserState.CollectingTags) - { - FailTagMatch(); - } - currentState = ParserState.DescendingTag; continue; // do NOT add as a character } @@ -187,8 +183,7 @@ void FailTagMatch() // not a tag, unload buffer delimiter = null; currentState = ParserState.CollectingTags; tagBufferSize = 0; - } - else + } else { FailTagMatch(); } diff --git a/RueI/RueI/Parsing/docs.xml b/RueI/RueI/Parsing/docs.xml deleted file mode 100644 index ea75812..0000000 --- a/RueI/RueI/Parsing/docs.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - Hello world - - - This example demonstrates creating and using a . - - Parser builder = new ParserBuilder() - .ImportFrom(Constants.DefaultParser) - .Build(); - - builder.Parse("hello world!") - - - - - \ No newline at end of file diff --git a/RueI/docs.xml b/RueI/docs.xml new file mode 100644 index 0000000..d68b570 --- /dev/null +++ b/RueI/docs.xml @@ -0,0 +1,33 @@ + + + + + + This example demonstrates creating and using a . + + Display display = new(referenceHub); // Create a new display from a + + SetElement helloElem = new(300, zIndex: 10, "hello").AddTo(display); + SetElement worldElem = new(250, zIndex: 10, "world").AddTo(display); + display.Add(helloElem, worldElem); + + display.Update(); // Update the display + + + + + + + + This example demonstrates creating and using a . + + Parser builder = new ParserBuilder() + .ImportFrom(Constants.DefaultParser) + .Build(); + + builder.Parse("hello world!") + + + + + \ No newline at end of file