mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 12:58:33 +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) {
|
||||
if (this.sortedChildrenDirty)
|
||||
this.ForceUpdateSortedChildren();
|
||||
}
|
||||
|
||||
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,8 +97,15 @@ namespace MLEM.Ui.Elements {
|
|||
this.relevantChildrenDirty = true;
|
||||
}
|
||||
|
||||
public override void Update(GameTime time) {
|
||||
base.Update(time);
|
||||
public override void ForceUpdateSortedChildren() {
|
||||
base.ForceUpdateSortedChildren();
|
||||
if (this.scrollOverflow)
|
||||
this.relevantChildrenDirty = true;
|
||||
}
|
||||
|
||||
protected override List<Element> GetRelevantChildren() {
|
||||
var relevant = base.GetRelevantChildren();
|
||||
if (this.scrollOverflow) {
|
||||
if (this.relevantChildrenDirty) {
|
||||
this.relevantChildrenDirty = false;
|
||||
|
||||
|
@ -117,10 +124,9 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
}
|
||||
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