diff --git a/CHANGELOG.md b/CHANGELOG.md
index 56b8ff6..8f00791 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -57,6 +57,7 @@ Additions
- Added ScrollBar.MouseDragScrolling
- Added Panel.ScrollToElement
- Added ElementHelper.MakeGrid
+- Added Element.AutoHideCondition and Button.AutoDisableCondition
Improvements
- Allow elements to auto-adjust their size even when their children are aligned oddly
diff --git a/MLEM.Ui/Elements/Button.cs b/MLEM.Ui/Elements/Button.cs
index 5293b2d..3bb46ed 100644
--- a/MLEM.Ui/Elements/Button.cs
+++ b/MLEM.Ui/Elements/Button.cs
@@ -1,3 +1,4 @@
+using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Graphics;
@@ -51,8 +52,16 @@ namespace MLEM.Ui.Elements {
///
/// Set this property to true to mark the button as disabled.
/// A disabled button cannot be moused over, selected or pressed.
+ /// If this value changes often, consider using to set it automatically.
///
- public virtual bool IsDisabled { get; set; }
+ public virtual bool IsDisabled {
+ get {
+ if (this.AutoDisableCondition != null)
+ this.IsDisabled = this.AutoDisableCondition(this);
+ return this.isDisabled;
+ }
+ set => this.isDisabled = value;
+ }
///
/// Whether this button's should be truncated if it exceeds this button's width.
/// Defaults to false.
@@ -69,12 +78,18 @@ namespace MLEM.Ui.Elements {
/// If this is true, will be able to return true even if is true.
///
public bool CanSelectDisabled;
+ ///
+ /// An optional function that can be used to set automatically based on a user-defined condition. This removes the need to disable a button based on a condition in or manually.
+ ///
+ public Func