mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
publicize some useful ui methods
This commit is contained in:
parent
3e7ddb8b1a
commit
64eefedac0
3 changed files with 16 additions and 16 deletions
|
@ -174,7 +174,7 @@ namespace MLEM.Ui.Elements {
|
|||
index = this.Children.Count;
|
||||
this.Children.Insert(index, element);
|
||||
element.Parent = this;
|
||||
element.Propagate(e => {
|
||||
element.AndChildren(e => {
|
||||
e.Root = this.Root;
|
||||
e.System = this.System;
|
||||
});
|
||||
|
@ -186,7 +186,7 @@ namespace MLEM.Ui.Elements {
|
|||
public void RemoveChild(Element element) {
|
||||
this.Children.Remove(element);
|
||||
element.Parent = null;
|
||||
element.Propagate(e => {
|
||||
element.AndChildren(e => {
|
||||
e.Root = null;
|
||||
e.System = null;
|
||||
});
|
||||
|
@ -454,6 +454,12 @@ namespace MLEM.Ui.Elements {
|
|||
return this.CanBeMoused && this.Area.Contains(position) ? this : null;
|
||||
}
|
||||
|
||||
public void AndChildren(Action<Element> action) {
|
||||
action(this);
|
||||
foreach (var child in this.Children)
|
||||
child.AndChildren(action);
|
||||
}
|
||||
|
||||
protected virtual void InitStyle(UiStyle style) {
|
||||
this.SelectionIndicator = style.SelectionIndicator;
|
||||
}
|
||||
|
@ -466,11 +472,5 @@ namespace MLEM.Ui.Elements {
|
|||
|
||||
public delegate void DrawCallback(Element element, GameTime time, SpriteBatch batch, float alpha, Point offset);
|
||||
|
||||
internal void Propagate(Action<Element> action) {
|
||||
action(this);
|
||||
foreach (var child in this.Children)
|
||||
child.Propagate(action);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace MLEM.Ui {
|
|||
if (mousedNow != null)
|
||||
mousedNow.OnMouseEnter?.Invoke(mousedNow);
|
||||
this.MousedElement = mousedNow;
|
||||
this.system.Propagate(e => e.OnMousedElementChanged?.Invoke(e, mousedNow));
|
||||
this.system.ApplyToAll(e => e.OnMousedElementChanged?.Invoke(e, mousedNow));
|
||||
}
|
||||
|
||||
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
|
||||
|
@ -91,7 +91,7 @@ namespace MLEM.Ui {
|
|||
element.OnSelected?.Invoke(element);
|
||||
this.SelectedElement = element;
|
||||
this.SelectedLastElementWithMouse = mouse;
|
||||
this.system.Propagate(e => e.OnSelectedElementChanged?.Invoke(e, element));
|
||||
this.system.ApplyToAll(e => e.OnSelectedElementChanged?.Invoke(e, element));
|
||||
}
|
||||
|
||||
public Element GetElementUnderPos(Point position) {
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace MLEM.Ui {
|
|||
set {
|
||||
this.style = value;
|
||||
foreach (var root in this.rootElements) {
|
||||
root.Element.Propagate(e => e.System = this);
|
||||
root.Element.AndChildren(e => e.System = this);
|
||||
root.Element.SetAreaDirty();
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ namespace MLEM.Ui {
|
|||
|
||||
window.AddTextInputListener((sender, key, character) => {
|
||||
foreach (var root in this.rootElements)
|
||||
root.Element.Propagate(e => e.OnTextInput?.Invoke(e, key, character));
|
||||
root.Element.AndChildren(e => e.OnTextInput?.Invoke(e, key, character));
|
||||
});
|
||||
|
||||
this.OnSelectedElementDrawn = (element, time, batch, alpha, offset) => {
|
||||
|
@ -116,7 +116,7 @@ namespace MLEM.Ui {
|
|||
if (index < 0 || index > this.rootElements.Count)
|
||||
index = this.rootElements.Count;
|
||||
this.rootElements.Insert(index, root);
|
||||
root.Element.Propagate(e => {
|
||||
root.Element.AndChildren(e => {
|
||||
e.Root = root;
|
||||
e.System = this;
|
||||
});
|
||||
|
@ -128,7 +128,7 @@ namespace MLEM.Ui {
|
|||
if (root == null)
|
||||
return;
|
||||
this.rootElements.Remove(root);
|
||||
root.Element.Propagate(e => {
|
||||
root.Element.AndChildren(e => {
|
||||
e.Root = null;
|
||||
e.System = null;
|
||||
});
|
||||
|
@ -148,9 +148,9 @@ namespace MLEM.Ui {
|
|||
yield return this.rootElements[i];
|
||||
}
|
||||
|
||||
internal void Propagate(Action<Element> action) {
|
||||
public void ApplyToAll(Action<Element> action) {
|
||||
foreach (var root in this.rootElements)
|
||||
root.Element.Propagate(action);
|
||||
root.Element.AndChildren(action);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue