From ef677ae441ee7c9ebc648083ef6f5a8be2210ca9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 18 Aug 2019 18:32:34 +0200 Subject: [PATCH] added some useful querying functions --- Demos/UiDemo.cs | 14 ++++++++++++++ MLEM.Ui/Elements/Element.cs | 27 +++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index badb355..65e7ff9 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using Coroutine; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -132,6 +133,19 @@ namespace Demos { var slider = new Slider(Anchor.AutoLeft, new Vector2(1, 10), 5, 1); root.AddChild(new Paragraph(Anchor.AutoLeft, 1, paragraph => "Slider is at " + (slider.CurrentValue * 100).Floor() + "%") {PositionOffset = new Vector2(0, 1)}); root.AddChild(slider); + + // Below are some querying examples that help you find certain elements easily + + var textFields = root.GetChildren(); + Console.WriteLine($"The root has {textFields.Count()} text fields"); + + var paragraphs = root.GetChildren(); + var totalParagraphs = root.GetChildren(regardChildrensChildren: true); + Console.WriteLine($"The root has {paragraphs.Count()} paragraphs, but there are {totalParagraphs.Count()} when regarding children's children"); + + var autoWidthChildren = root.GetChildren(e => e.Size.X == 1); + var autoWidthButtons = root.GetChildren