Skip to content

Commit

Permalink
Add AddRange for NotifyingCollection, expose all elements under a Lay…
Browse files Browse the repository at this point in the history
…outRoot
  • Loading branch information
BadMagic100 committed May 23, 2022
1 parent 08c1960 commit 84e44c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions MagicUI/Behaviours/LayoutOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal class LayoutOrchestrator : MonoBehaviour

public bool shouldRenderDebugBounds = false;

public IEnumerable<ArrangableElement> Elements => elements.AsReadOnly();

/// <summary>
/// Registers an element in layout for arrangement and later lookup
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions MagicUI/Core/LayoutRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public class LayoutRoot
/// </summary>
public GameObject Canvas { get => rootCanvas; }

/// <summary>
/// A read-only collection of elements registered to this layout
/// </summary>
public IEnumerable<ArrangableElement> Elements => layoutOrchestrator.Elements;

/// <summary>
/// A predicate that determines whether the layout should be visible. By default (i.e. when there is no condition), the layout is
/// always visible.
Expand Down
13 changes: 13 additions & 0 deletions MagicUI/Core/NotifyingCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ public void Add(T item)
actionOnChange.Notify(owner);
}

/// <summary>
/// Convenience method to add several items at once
/// </summary>
/// <param name="items">The items to add to the collection</param>
public void AddRange(IEnumerable<T> items)
{
foreach (T item in items)
{
this.items.Add(item);
}
actionOnChange.Notify(owner);
}

/// <inheritdoc/>
public void Clear()
{
Expand Down
4 changes: 2 additions & 2 deletions MagicUI/Elements/GridLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ public class GridLayout : Layout
/// Definition of the number of rows, their sizes, and their types. By default this is empty. If the grid is measured
/// with empty row definitions, one will be added for you with a minimum height of 0px.
/// </summary>
public ICollection<GridDimension> RowDefinitions => rowDefs;
public NotifyingCollection<GridDimension> RowDefinitions => rowDefs;

private NotifyingCollection<GridDimension> colDefs;
/// <summary>
/// Definition of the number of columns, their sizes, and their types. By default this is empty. If the grid is measured
/// with empty column definitions, one will be added for you with a minimum height of 0px.
/// </summary>
public ICollection<GridDimension> ColumnDefinitions => colDefs;
public NotifyingCollection<GridDimension> ColumnDefinitions => colDefs;

private float minWidth = 0;
/// <summary>
Expand Down

0 comments on commit 84e44c8

Please sign in to comment.