mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 01:39:23 +01:00
made dropdowns only have high priority when opened and fixed panels sometimes ignoring priority
This commit is contained in:
parent
89f957f8b6
commit
4888bb0fd7
3 changed files with 45 additions and 32 deletions
|
@ -6,15 +6,19 @@ namespace MLEM.Ui.Elements {
|
|||
public readonly Panel Panel;
|
||||
public bool IsOpen {
|
||||
get => !this.Panel.IsHidden;
|
||||
set => this.Panel.IsHidden = !value;
|
||||
set {
|
||||
this.Panel.IsHidden = !value;
|
||||
this.OnOpenedOrClosed?.Invoke(this);
|
||||
}
|
||||
}
|
||||
public GenericCallback OnOpenedOrClosed;
|
||||
|
||||
public Dropdown(Anchor anchor, Vector2 size, string text = null, string tooltipText = null, float tooltipWidth = 50) : base(anchor, size, text, tooltipText, tooltipWidth) {
|
||||
this.Panel = this.AddChild(new Panel(Anchor.TopCenter, size, Vector2.Zero, true) {
|
||||
IsHidden = true
|
||||
});
|
||||
this.OnAreaUpdated += e => this.Panel.PositionOffset = new Vector2(0, e.Area.Height / this.Scale);
|
||||
this.Priority = 10000;
|
||||
this.OnOpenedOrClosed += e => this.Priority = this.IsOpen ? 10000 : 0;
|
||||
this.OnPressed += e => this.IsOpen = !this.IsOpen;
|
||||
}
|
||||
|
||||
|
|
|
@ -189,24 +189,27 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
|
||||
public void SetAreaDirty() {
|
||||
this.areaDirty = true;
|
||||
if (this.Anchor >= Anchor.AutoLeft && this.Parent != null)
|
||||
this.Parent.SetAreaDirty();
|
||||
}
|
||||
|
||||
public void SetSortedChildrenDirty() {
|
||||
this.sortedChildrenDirty = true;
|
||||
}
|
||||
|
||||
public void UpdateSortedChildrenIfDirty() {
|
||||
if (this.sortedChildrenDirty) {
|
||||
this.sortedChildrenDirty = false;
|
||||
if (this.sortedChildrenDirty)
|
||||
this.ForceUpdateSortedChildren();
|
||||
}
|
||||
|
||||
this.sortedChildren.Clear();
|
||||
this.sortedChildren.AddRange(this.Children);
|
||||
this.sortedChildren.Sort((e1, e2) => e1.Priority.CompareTo(e2.Priority));
|
||||
}
|
||||
public virtual void ForceUpdateSortedChildren() {
|
||||
this.sortedChildrenDirty = false;
|
||||
|
||||
this.sortedChildren.Clear();
|
||||
this.sortedChildren.AddRange(this.Children);
|
||||
this.sortedChildren.Sort((e1, e2) => e1.Priority.CompareTo(e2.Priority));
|
||||
}
|
||||
|
||||
public void SetAreaDirty() {
|
||||
this.areaDirty = true;
|
||||
if (this.Anchor >= Anchor.AutoLeft && this.Parent != null)
|
||||
this.Parent.SetAreaDirty();
|
||||
}
|
||||
|
||||
public void UpdateAreaIfDirty() {
|
||||
|
|
|
@ -97,30 +97,36 @@ namespace MLEM.Ui.Elements {
|
|||
this.relevantChildrenDirty = true;
|
||||
}
|
||||
|
||||
public override void Update(GameTime time) {
|
||||
base.Update(time);
|
||||
if (this.relevantChildrenDirty) {
|
||||
this.relevantChildrenDirty = false;
|
||||
public override void ForceUpdateSortedChildren() {
|
||||
base.ForceUpdateSortedChildren();
|
||||
if (this.scrollOverflow)
|
||||
this.relevantChildrenDirty = true;
|
||||
}
|
||||
|
||||
var visible = this.GetRenderTargetArea();
|
||||
this.relevantChildren.Clear();
|
||||
foreach (var child in this.SortedChildren) {
|
||||
if (child.Area.Intersects(visible)) {
|
||||
this.relevantChildren.Add(child);
|
||||
} else {
|
||||
foreach (var c in child.GetChildren(regardGrandchildren: true)) {
|
||||
if (c.Area.Intersects(visible)) {
|
||||
this.relevantChildren.Add(child);
|
||||
break;
|
||||
protected override List<Element> GetRelevantChildren() {
|
||||
var relevant = base.GetRelevantChildren();
|
||||
if (this.scrollOverflow) {
|
||||
if (this.relevantChildrenDirty) {
|
||||
this.relevantChildrenDirty = false;
|
||||
|
||||
var visible = this.GetRenderTargetArea();
|
||||
this.relevantChildren.Clear();
|
||||
foreach (var child in this.SortedChildren) {
|
||||
if (child.Area.Intersects(visible)) {
|
||||
this.relevantChildren.Add(child);
|
||||
} else {
|
||||
foreach (var c in child.GetChildren(regardGrandchildren: true)) {
|
||||
if (c.Area.Intersects(visible)) {
|
||||
this.relevantChildren.Add(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
relevant = this.relevantChildren;
|
||||
}
|
||||
}
|
||||
|
||||
protected override List<Element> GetRelevantChildren() {
|
||||
return this.scrollOverflow ? this.relevantChildren : base.GetRelevantChildren();
|
||||
return relevant;
|
||||
}
|
||||
|
||||
public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) {
|
||||
|
|
Loading…
Reference in a new issue