Skip to content

Commit

Permalink
rtest
Browse files Browse the repository at this point in the history
  • Loading branch information
LolaLollipop committed Nov 16, 2023
1 parent d2f3b89 commit 78960c8
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 59 deletions.
4 changes: 3 additions & 1 deletion RueI/RueI/Display.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using MEC;
using RueI.Extensions;
using RueI.Interfaces;

/// <summary>
/// Represents a <see cref="Display"/> that hides elements based on an active screen.
Expand Down Expand Up @@ -39,7 +40,8 @@ public ScreenDisplay(ReferenceHub hub, T defaultScreen)
/// <summary>
/// Represents a display attached to a <see cref="DisplayCoordinator"/>.
/// </summary>
public class Display : DisplayBase
/// <include file='docs.xml' path='docs/members[@name="display"]/Display/*'/>
public class Display : DisplayBase, IElementContainer
{
/// <summary>
/// Gets the ratelimit used for displaying hints.
Expand Down
53 changes: 31 additions & 22 deletions RueI/RueI/Extensions/ElementHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
namespace RueI.Extensions
namespace RueI.Extensions;

using RueI.Interfaces;

/// <summary>
/// Provides extensions and helpers for working with elements.
/// </summary>
public static class ElementHelpers
{
/// <summary>
/// Provides extensions and helpers for working with elements.
/// Adds an <see cref="IElement"/> to a <see cref="IElementContainer"/>.
/// </summary>
public static class ElementHelpers
{
/// <summary>
/// Gets the functional (un-scaled) position of an element.
/// </summary>
/// <param name="element">The element to get the position for.</param>
/// <returns>The un-scaled position..</returns>
public static float GetFunctionalPosition(this IElement element) => Ruetility.ScaledPositionToFunctional(element.Position);
/// <param name="element">The element to add.</param>
/// <param name="container">The <see cref="IElementContainer"/> to add to.</param>
/// <returns>A reference to this element.</returns>
public static IElement AddTo(this IElement element, IElementContainer container) => element.AddTo(container.Elements);

/// <summary>
/// Calculates the offset for two hints.
/// </summary>
/// <param name="hintOnePos">The first hint's vertical position.</param>
/// <param name="hintOneTotalLines">The first hint's total line-height, excluding the vertical position.</param>
/// <param name="hintTwoPos">The second hint's vertical position.</param>
/// <returns>A float indicating the new offset.</returns>
public static float CalculateOffset(float hintOnePos, float hintOneTotalLines, float hintTwoPos)
{
float calc = (hintOnePos + (2 * hintOneTotalLines)) - hintTwoPos;
return calc / -2;
}
/// <summary>
/// Gets the functional (un-scaled) position of an element.
/// </summary>
/// <param name="element">The element to get the position for.</param>
/// <returns>The un-scaled position..</returns>
public static float GetFunctionalPosition(this IElement element) => Ruetility.ScaledPositionToFunctional(element.Position);

/// <summary>
/// Calculates the offset for two hints.
/// </summary>
/// <param name="hintOnePos">The first hint's vertical position.</param>
/// <param name="hintOneTotalLines">The first hint's total line-height, excluding the vertical position.</param>
/// <param name="hintTwoPos">The second hint's vertical position.</param>
/// <returns>A float indicating the new offset.</returns>
public static float CalculateOffset(float hintOnePos, float hintOneTotalLines, float hintTwoPos)
{
float calc = (hintOnePos + (2 * hintOneTotalLines)) - hintTwoPos;
return calc / -2;
}
}
5 changes: 4 additions & 1 deletion RueI/RueI/Extensions/UniversalExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public static class UniversalExtensions
/// <typeparam name="T">The type of this instance and the collection to add to.</typeparam>
/// <param name="item">The instance to add.</param>
/// <param name="collection">The collection to add the elements to.</param>
public static void AddTo<T>(this T item, ICollection<T> collection)
/// <returns>A reference to <paramref name="item"/>.</returns>
public static T AddTo<T>(this T item, ICollection<T> collection)
where T : class
{
collection.Add(item);
return item;
}
}
}
13 changes: 13 additions & 0 deletions RueI/RueI/Interfaces/IElementContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace RueI.Interfaces
{
/// <summary>
/// Defines a container for multiple elements.
/// </summary>
public interface IElementContainer
{
/// <summary>
/// Gets the elements of this <see cref="IElementContainer"/>.
/// </summary>
public List<IElement> Elements { get; }
}
}
25 changes: 10 additions & 15 deletions RueI/RueI/Parsing/Parser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace RueI
namespace RueI
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand All @@ -12,7 +12,7 @@ namespace RueI
/// <summary>
/// Helps parse the content of elements.
/// </summary>
/// <include file='./docs.xml' path='docs/members[@name="parser"]/Parser/*'/>
/// <include file='docs.xml' path='docs/members[@name="parser"]/Parser/*'/>
public class Parser
{
/// <summary>
Expand Down Expand Up @@ -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();
Expand All @@ -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
}
Expand Down Expand Up @@ -187,8 +183,7 @@ void FailTagMatch() // not a tag, unload buffer
delimiter = null;
currentState = ParserState.CollectingTags;
tagBufferSize = 0;
}
else
} else
{
FailTagMatch();
}
Expand Down
20 changes: 0 additions & 20 deletions RueI/RueI/Parsing/docs.xml

This file was deleted.

33 changes: 33 additions & 0 deletions RueI/docs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<docs>
<members name="display">
<Display>
<example>
This example demonstrates creating and using a <see cref="Display"/>.
<code>
Display display = new(referenceHub); // Create a new display from a <see cref="ReferenceHub"/>

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
</code>
</example>
</Display>
</members>
<members name="parser">
<Parser>
<example>
This example demonstrates creating and using a <see cref="ParserBuilder"/>.
<code>
Parser builder = new ParserBuilder()
.ImportFrom(Constants.DefaultParser)
.Build();

builder.Parse("hello world!")
</code>
</example>
</Parser>
</members>
</docs>

0 comments on commit 78960c8

Please sign in to comment.