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;
|
index = this.Children.Count;
|
||||||
this.Children.Insert(index, element);
|
this.Children.Insert(index, element);
|
||||||
element.Parent = this;
|
element.Parent = this;
|
||||||
element.Propagate(e => {
|
element.AndChildren(e => {
|
||||||
e.Root = this.Root;
|
e.Root = this.Root;
|
||||||
e.System = this.System;
|
e.System = this.System;
|
||||||
});
|
});
|
||||||
|
@ -186,7 +186,7 @@ namespace MLEM.Ui.Elements {
|
||||||
public void RemoveChild(Element element) {
|
public void RemoveChild(Element element) {
|
||||||
this.Children.Remove(element);
|
this.Children.Remove(element);
|
||||||
element.Parent = null;
|
element.Parent = null;
|
||||||
element.Propagate(e => {
|
element.AndChildren(e => {
|
||||||
e.Root = null;
|
e.Root = null;
|
||||||
e.System = null;
|
e.System = null;
|
||||||
});
|
});
|
||||||
|
@ -454,6 +454,12 @@ namespace MLEM.Ui.Elements {
|
||||||
return this.CanBeMoused && this.Area.Contains(position) ? this : null;
|
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) {
|
protected virtual void InitStyle(UiStyle style) {
|
||||||
this.SelectionIndicator = style.SelectionIndicator;
|
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);
|
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)
|
if (mousedNow != null)
|
||||||
mousedNow.OnMouseEnter?.Invoke(mousedNow);
|
mousedNow.OnMouseEnter?.Invoke(mousedNow);
|
||||||
this.MousedElement = 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)) {
|
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
|
||||||
|
@ -91,7 +91,7 @@ namespace MLEM.Ui {
|
||||||
element.OnSelected?.Invoke(element);
|
element.OnSelected?.Invoke(element);
|
||||||
this.SelectedElement = element;
|
this.SelectedElement = element;
|
||||||
this.SelectedLastElementWithMouse = mouse;
|
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) {
|
public Element GetElementUnderPos(Point position) {
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace MLEM.Ui {
|
||||||
set {
|
set {
|
||||||
this.style = value;
|
this.style = value;
|
||||||
foreach (var root in this.rootElements) {
|
foreach (var root in this.rootElements) {
|
||||||
root.Element.Propagate(e => e.System = this);
|
root.Element.AndChildren(e => e.System = this);
|
||||||
root.Element.SetAreaDirty();
|
root.Element.SetAreaDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ namespace MLEM.Ui {
|
||||||
|
|
||||||
window.AddTextInputListener((sender, key, character) => {
|
window.AddTextInputListener((sender, key, character) => {
|
||||||
foreach (var root in this.rootElements)
|
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) => {
|
this.OnSelectedElementDrawn = (element, time, batch, alpha, offset) => {
|
||||||
|
@ -116,7 +116,7 @@ namespace MLEM.Ui {
|
||||||
if (index < 0 || index > this.rootElements.Count)
|
if (index < 0 || index > this.rootElements.Count)
|
||||||
index = this.rootElements.Count;
|
index = this.rootElements.Count;
|
||||||
this.rootElements.Insert(index, root);
|
this.rootElements.Insert(index, root);
|
||||||
root.Element.Propagate(e => {
|
root.Element.AndChildren(e => {
|
||||||
e.Root = root;
|
e.Root = root;
|
||||||
e.System = this;
|
e.System = this;
|
||||||
});
|
});
|
||||||
|
@ -128,7 +128,7 @@ namespace MLEM.Ui {
|
||||||
if (root == null)
|
if (root == null)
|
||||||
return;
|
return;
|
||||||
this.rootElements.Remove(root);
|
this.rootElements.Remove(root);
|
||||||
root.Element.Propagate(e => {
|
root.Element.AndChildren(e => {
|
||||||
e.Root = null;
|
e.Root = null;
|
||||||
e.System = null;
|
e.System = null;
|
||||||
});
|
});
|
||||||
|
@ -148,9 +148,9 @@ namespace MLEM.Ui {
|
||||||
yield return this.rootElements[i];
|
yield return this.rootElements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Propagate(Action<Element> action) {
|
public void ApplyToAll(Action<Element> action) {
|
||||||
foreach (var root in this.rootElements)
|
foreach (var root in this.rootElements)
|
||||||
root.Element.Propagate(action);
|
root.Element.AndChildren(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue