mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
clean the element helper methods up a bit
This commit is contained in:
parent
034aeec1e3
commit
a5f6e83321
1 changed files with 5 additions and 15 deletions
|
@ -331,9 +331,7 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
public Element GetLowestChild(Func<Element, bool> condition = null) {
|
||||
Element lowest = null;
|
||||
// the lowest child is expected to be towards the back, so search is usually faster if done backwards
|
||||
for (var i = this.Children.Count - 1; i >= 0; i--) {
|
||||
var child = this.Children[i];
|
||||
foreach (var child in this.Children) {
|
||||
if (condition != null && !condition(child))
|
||||
continue;
|
||||
if (child.Anchor > Anchor.TopRight && child.Anchor < Anchor.AutoLeft)
|
||||
|
@ -384,18 +382,6 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Element> GetChildren(Func<Element, bool> condition = null, bool regardGrandchildren = false, bool ignoreFalseGrandchildren = false) {
|
||||
foreach (var child in this.Children) {
|
||||
var applies = condition == null || condition(child);
|
||||
if (applies)
|
||||
yield return child;
|
||||
if (regardGrandchildren && (!ignoreFalseGrandchildren || applies)) {
|
||||
foreach (var cc in child.GetChildren(condition, true, ignoreFalseGrandchildren))
|
||||
yield return cc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<T> GetChildren<T>(Func<T, bool> condition = null, bool regardGrandchildren = false, bool ignoreFalseGrandchildren = false) where T : Element {
|
||||
foreach (var child in this.Children) {
|
||||
var applies = child is T t && (condition == null || condition(t));
|
||||
|
@ -408,6 +394,10 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<Element> GetChildren(Func<Element, bool> condition = null, bool regardGrandchildren = false, bool ignoreFalseGrandchildren = false) {
|
||||
return this.GetChildren<Element>(condition, regardGrandchildren, ignoreFalseGrandchildren);
|
||||
}
|
||||
|
||||
public IEnumerable<Element> GetParentTree() {
|
||||
if (this.Parent == null)
|
||||
yield break;
|
||||
|
|
Loading…
Reference in a new issue