mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +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 ScrollBar.MouseDragScrolling
|
||||||
- Added Panel.ScrollToElement
|
- Added Panel.ScrollToElement
|
||||||
- Added ElementHelper.MakeGrid
|
- Added ElementHelper.MakeGrid
|
||||||
|
- Added Element.AutoHideCondition and Button.AutoDisableCondition
|
||||||
|
|
||||||
Improvements
|
Improvements
|
||||||
- Allow elements to auto-adjust their size even when their children are aligned oddly
|
- 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;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using MLEM.Graphics;
|
using MLEM.Graphics;
|
||||||
|
@ -51,8 +52,16 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set this property to true to mark the button as disabled.
|
/// Set this property to true to mark the button as disabled.
|
||||||
/// A disabled button cannot be moused over, selected or pressed.
|
/// 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>
|
/// </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>
|
/// <summary>
|
||||||
/// Whether this button's <see cref="Text"/> should be truncated if it exceeds this button's width.
|
/// Whether this button's <see cref="Text"/> should be truncated if it exceeds this button's width.
|
||||||
/// Defaults to false.
|
/// 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.
|
/// If this is true, <see cref="CanBeSelected"/> will be able to return true even if <see cref="IsDisabled"/> is true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool CanSelectDisabled;
|
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 />
|
/// <inheritdoc />
|
||||||
public override bool CanBeSelected => base.CanBeSelected && (this.CanSelectDisabled || !this.IsDisabled);
|
public override bool CanBeSelected => base.CanBeSelected && (this.CanSelectDisabled || !this.IsDisabled);
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||||
|
|
||||||
|
private bool isDisabled;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new button with the given settings
|
/// Creates a new button with the given settings
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -172,9 +172,15 @@ namespace MLEM.Ui.Elements {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set this property to <c>true</c> to cause this element to be hidden.
|
/// 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.
|
/// 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>
|
/// </summary>
|
||||||
public virtual bool IsHidden {
|
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 {
|
set {
|
||||||
if (this.isHidden == value)
|
if (this.isHidden == value)
|
||||||
return;
|
return;
|
||||||
|
@ -430,6 +436,10 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Obsolete("OnDisposed will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")]
|
[Obsolete("OnDisposed will be removed in a future update. To unregister custom event handlers, use OnRemovedFromUi instead.")]
|
||||||
public GenericCallback OnDisposed;
|
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>
|
/// <summary>
|
||||||
/// A list of all of this element's direct children.
|
/// A list of all of this element's direct children.
|
||||||
|
|
Loading…
Reference in a new issue