mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-26 02:09:24 +01:00
Added Element.AutoHideCondition and Button.AutoDisableCondition
This commit is contained in:
parent
b41341d01e
commit
d5d3297271
3 changed files with 28 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
/// <summary>
|
||||
/// 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 <see cref="AutoDisableCondition"/> to set it automatically.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Whether this button's <see cref="Text"/> 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, <see cref="CanBeSelected"/> will be able to return true even if <see cref="IsDisabled"/> is true.
|
||||
/// </summary>
|
||||
public bool CanSelectDisabled;
|
||||
/// <summary>
|
||||
/// An optional function that can be used to set <see cref="IsDisabled"/> automatically based on a user-defined condition. This removes the need to disable a button based on a condition in <see cref="Element.OnUpdated"/> or manually.
|
||||
/// </summary>
|
||||
public Func<Button, bool> AutoDisableCondition;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanBeSelected => base.CanBeSelected && (this.CanSelectDisabled || !this.IsDisabled);
|
||||
/// <inheritdoc />
|
||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||
|
||||
private bool isDisabled;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new button with the given settings
|
||||
/// </summary>
|
||||
|
|
|
@ -172,9 +172,15 @@ namespace MLEM.Ui.Elements {
|
|||
/// <summary>
|
||||
/// Set this property to <c>true</c> to cause this element to be hidden.
|
||||
/// Hidden elements don't receive input events, aren't rendered and don't factor into auto-anchoring.
|
||||
/// If this value changes often, consider using <see cref="AutoHideCondition"/> to set it automatically.
|
||||
/// </summary>
|
||||
public virtual bool IsHidden {
|
||||
get => this.isHidden;
|
||||
get {
|
||||
// instead of just returning, we set IsHidden here because we might have to set our area dirty
|
||||
if (this.AutoHideCondition != null)
|
||||
this.IsHidden = this.AutoHideCondition(this);
|
||||
return this.isHidden;
|
||||
}
|
||||
set {
|
||||
if (this.isHidden == value)
|
||||
return;
|
||||
|
@ -430,6 +436,10 @@ namespace MLEM.Ui.Elements {
|
|||
/// </summary>
|
||||
[Obsolete("OnDisposed will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")]
|
||||
public GenericCallback OnDisposed;
|
||||
/// <summary>
|
||||
/// An optional function that can be used to set <see cref="IsHidden"/> automatically based on a user-defined condition. This removes the need to hide an element based on a condition in <see cref="Element.OnUpdated"/> or manually.
|
||||
/// </summary>
|
||||
public Func<Element, bool> AutoHideCondition;
|
||||
|
||||
/// <summary>
|
||||
/// A list of all of this element's direct children.
|
||||
|
|
Loading…
Reference in a new issue