1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-07 15:23:37 +02:00

made CanSelectContent be set automatically by the root through adding more events

This commit is contained in:
Ellpeck 2019-12-08 21:49:15 +01:00
parent 7118e323b3
commit 8d3afcf276
4 changed files with 21 additions and 3 deletions

View file

@ -140,7 +140,7 @@ namespace Demos {
root.AddChild(new RadioButton(Anchor.AutoLeft, new Vector2(1, 10), "Radio button 2!") {PositionOffset = new Vector2(0, 1)});
var tooltip = new Tooltip(50, "This is a test tooltip to see the window bounding") {IsHidden = true};
this.UiSystem.Add("TestTooltip", tooltip).CanSelectContent = false;
this.UiSystem.Add("TestTooltip", tooltip);
root.AddChild(new VerticalSpace(3));
root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Toggle Test Tooltip") {
OnPressed = element => tooltip.IsHidden = !tooltip.IsHidden

View file

@ -163,6 +163,8 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => {
e.Root = this.Root;
e.System = this.System;
if (this.Root != null)
this.Root.OnElementAdded(e);
});
this.SetSortedChildrenDirty();
this.SetAreaDirty();
@ -175,6 +177,8 @@ namespace MLEM.Ui.Elements {
element.AndChildren(e => {
e.Root = null;
e.System = null;
if (this.Root != null)
this.Root.OnElementRemoved(e);
});
this.SetSortedChildrenDirty();
this.SetAreaDirty();

View file

@ -16,7 +16,7 @@ namespace MLEM.Ui.Elements {
this.CanBeSelected = false;
if (elementToHover != null) {
elementToHover.OnMouseEnter += element => element.System.Add(element.GetType().Name + "Tooltip", this).CanSelectContent = false;
elementToHover.OnMouseEnter += element => element.System.Add(element.GetType().Name + "Tooltip", this);
elementToHover.OnMouseExit += element => {
if (this.System != null)
this.System.Remove(element.GetType().Name + "Tooltip");

View file

@ -139,6 +139,7 @@ namespace MLEM.Ui {
root.Element.AndChildren(e => {
e.Root = root;
e.System = this;
root.OnElementAdded(e);
e.SetAreaDirty();
});
this.OnRootAdded?.Invoke(root);
@ -160,6 +161,7 @@ namespace MLEM.Ui {
root.Element.AndChildren(e => {
e.Root = null;
e.System = null;
root.OnElementRemoved(e);
e.SetAreaDirty();
});
this.OnRootRemoved?.Invoke(root);
@ -204,17 +206,29 @@ namespace MLEM.Ui {
}
}
public float ActualScale => this.System.GlobalScale * this.Scale;
public bool CanSelectContent = true;
public Matrix Transform = Matrix.Identity;
public Matrix InvTransform => Matrix.Invert(this.Transform);
public Element SelectedElement { get; private set; }
public bool CanSelectContent { get; private set; }
public Element.GenericCallback OnElementAdded;
public Element.GenericCallback OnElementRemoved;
public RootElement(string name, Element element, UiSystem system) {
this.Name = name;
this.Element = element;
this.System = system;
this.OnElementAdded += e => {
if (e.CanBeSelected)
this.CanSelectContent = true;
};
this.OnElementRemoved += e => {
if (e.CanBeSelected && !this.Element.GetChildren(regardGrandchildren: true).Any(c => c.CanBeSelected))
this.CanSelectContent = false;
};
}
public void SelectElement(Element element) {