mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-25 05:58:35 +01:00
Compare commits
2 commits
cd32372994
...
f166c3d256
Author | SHA1 | Date | |
---|---|---|---|
f166c3d256 | |||
2c90ca9b89 |
5 changed files with 33 additions and 30 deletions
|
@ -54,6 +54,8 @@ Fixes
|
|||
- Fixed paragraph links having incorrect hover locations when using special text alignments
|
||||
- Fixed the graphics device's viewport being ignored for mouse and touch queries
|
||||
- Fixed auto-navigating panels not scrolling to the center of elements properly
|
||||
- Fixed UiControls allowing for non-selectable or non-mouseable elements to be marked as selected or moused
|
||||
- Fixed buttons and checkboxes changing their CanBeSelected and CanBePressed values when being disabled
|
||||
|
||||
Removals
|
||||
- Marked StyleProp equality members as obsolete
|
||||
|
|
|
@ -51,14 +51,7 @@ 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.
|
||||
/// </summary>
|
||||
public bool IsDisabled {
|
||||
get => this.isDisabled;
|
||||
set {
|
||||
this.isDisabled = value;
|
||||
this.CanBePressed = !value;
|
||||
this.CanBeSelected = !value;
|
||||
}
|
||||
}
|
||||
public virtual bool IsDisabled { get; set; }
|
||||
/// <summary>
|
||||
/// Whether this button's <see cref="Text"/> should be truncated if it exceeds this button's width.
|
||||
/// Defaults to false.
|
||||
|
@ -71,7 +64,10 @@ namespace MLEM.Ui.Elements {
|
|||
}
|
||||
}
|
||||
|
||||
private bool isDisabled;
|
||||
/// <inheritdoc />
|
||||
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
|
||||
/// <inheritdoc />
|
||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new button with the given settings
|
||||
|
|
|
@ -62,21 +62,18 @@ namespace MLEM.Ui.Elements {
|
|||
/// Set this property to true to mark the checkbox as disabled.
|
||||
/// A disabled checkbox cannot be moused over, selected or toggled.
|
||||
/// </summary>
|
||||
public bool IsDisabled {
|
||||
get => this.isDisabled;
|
||||
set {
|
||||
this.isDisabled = value;
|
||||
this.CanBePressed = !value;
|
||||
this.CanBeSelected = !value;
|
||||
}
|
||||
}
|
||||
public virtual bool IsDisabled { get; set; }
|
||||
/// <summary>
|
||||
/// An event that is invoked when this checkbox's <see cref="Checked"/> property changes
|
||||
/// </summary>
|
||||
public CheckStateChange OnCheckStateChange;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanBeSelected => base.CanBeSelected && !this.IsDisabled;
|
||||
/// <inheritdoc />
|
||||
public override bool CanBePressed => base.CanBePressed && !this.IsDisabled;
|
||||
|
||||
private bool isChecked;
|
||||
private bool isDisabled;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new checkbox with the given settings
|
||||
|
|
|
@ -191,51 +191,51 @@ namespace MLEM.Ui.Elements {
|
|||
/// Set this field to false to disallow the element from being selected.
|
||||
/// An unselectable element is skipped by automatic navigation and its <see cref="OnSelected"/> callback will never be called.
|
||||
/// </summary>
|
||||
public bool CanBeSelected = true;
|
||||
public virtual bool CanBeSelected { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Set this field to false to disallow the element from reacting to being moused over.
|
||||
/// </summary>
|
||||
public bool CanBeMoused = true;
|
||||
public virtual bool CanBeMoused { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Set this field to false to disallow this element's <see cref="OnPressed"/> and <see cref="OnSecondaryPressed"/> events to be called.
|
||||
/// </summary>
|
||||
public bool CanBePressed = true;
|
||||
public virtual bool CanBePressed { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Set this field to false to cause auto-anchored siblings to ignore this element as a possible anchor point.
|
||||
/// </summary>
|
||||
public bool CanAutoAnchorsAttach = true;
|
||||
public virtual bool CanAutoAnchorsAttach { get; set; } = true;
|
||||
/// <summary>
|
||||
/// Set this field to true to cause this element's width to be automatically calculated based on the area that its <see cref="Children"/> take up.
|
||||
/// To use this element's <see cref="Size"/>'s X coordinate as a minimum or maximum width rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true.
|
||||
/// </summary>
|
||||
public bool SetWidthBasedOnChildren;
|
||||
public virtual bool SetWidthBasedOnChildren { get; set; }
|
||||
/// <summary>
|
||||
/// Set this field to true to cause this element's height to be automatically calculated based on the area that its <see cref="Children"/> take up.
|
||||
/// To use this element's <see cref="Size"/>'s Y coordinate as a minimum or maximum height rather than ignoring it, set <see cref="TreatSizeAsMinimum"/> or <see cref="TreatSizeAsMaximum"/> to true.
|
||||
/// </summary>
|
||||
public bool SetHeightBasedOnChildren;
|
||||
public virtual bool SetHeightBasedOnChildren { get; set; }
|
||||
/// <summary>
|
||||
/// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled, the resulting width or height will always be greather than or equal to this element's <see cref="Size"/>.
|
||||
/// For example, if an element's <see cref="Size"/>'s Y coordinate is set to 20, but there is only one child with a height of 10 in it, the element's height would be shrunk to 10 if this value was false, but would remain at 20 if it was true.
|
||||
/// Note that this value only has an effect if <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled.
|
||||
/// </summary>
|
||||
public bool TreatSizeAsMinimum;
|
||||
public virtual bool TreatSizeAsMinimum { get; set; }
|
||||
/// <summary>
|
||||
/// If this field is set to true, and <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/>are enabled, the resulting width or height weill always be less than or equal to this element's <see cref="Size"/>.
|
||||
/// Note that this value only has an effect if <see cref="SetWidthBasedOnChildren"/> or <see cref="SetHeightBasedOnChildren"/> are enabled.
|
||||
/// </summary>
|
||||
public bool TreatSizeAsMaximum;
|
||||
public virtual bool TreatSizeAsMaximum { get; set; }
|
||||
/// <summary>
|
||||
/// Set this field to true to cause this element's final display area to never exceed that of its <see cref="Parent"/>.
|
||||
/// If the resulting area is too large, the size of this element is shrunk to fit the target area.
|
||||
/// This can be useful if an element should fill the remaining area of a parent exactly.
|
||||
/// </summary>
|
||||
public bool PreventParentSpill;
|
||||
public virtual bool PreventParentSpill { get; set; }
|
||||
/// <summary>
|
||||
/// The transparency (alpha value) that this element is rendered with.
|
||||
/// Note that, when <see cref="Draw"/> is called, this alpha value is multiplied with the <see cref="Parent"/>'s alpha value and passed down to this element's <see cref="Children"/>.
|
||||
/// </summary>
|
||||
public float DrawAlpha = 1;
|
||||
public virtual float DrawAlpha { get; set; } = 1;
|
||||
/// <summary>
|
||||
/// Stores whether this element is currently being moused over or touched.
|
||||
/// </summary>
|
||||
|
|
|
@ -259,7 +259,9 @@ namespace MLEM.Ui {
|
|||
/// <param name="element">The element to select, or null to deselect the selected element.</param>
|
||||
/// <param name="autoNav">Whether automatic navigation should be forced on</param>
|
||||
public void SelectElement(RootElement root, Element element, bool? autoNav = null) {
|
||||
if (root == null)
|
||||
if (root == null || !root.CanSelectContent)
|
||||
return;
|
||||
if (element != null && !element.CanBeSelected)
|
||||
return;
|
||||
var selected = this.GetSelectedElement(root);
|
||||
if (selected == element)
|
||||
|
@ -284,6 +286,8 @@ namespace MLEM.Ui {
|
|||
/// </summary>
|
||||
/// <param name="element">The element to set as moused</param>
|
||||
public void SetMousedElement(Element element) {
|
||||
if (element != null && !element.CanBeMoused)
|
||||
return;
|
||||
if (element != this.MousedElement) {
|
||||
if (this.MousedElement != null)
|
||||
this.System.InvokeOnElementMouseExit(this.MousedElement);
|
||||
|
@ -299,6 +303,8 @@ namespace MLEM.Ui {
|
|||
/// </summary>
|
||||
/// <param name="element">The element to set as touched</param>
|
||||
public void SetTouchedElement(Element element) {
|
||||
if (element != null && !element.CanBeMoused)
|
||||
return;
|
||||
if (element != this.TouchedElement) {
|
||||
if (this.TouchedElement != null)
|
||||
this.System.InvokeOnElementTouchExit(this.TouchedElement);
|
||||
|
@ -316,9 +322,11 @@ namespace MLEM.Ui {
|
|||
/// <param name="root">The root element whose selected element to return</param>
|
||||
/// <returns>The given root's selected element, or null if the root doesn't exist, or if there is no selected element for that root.</returns>
|
||||
public Element GetSelectedElement(RootElement root) {
|
||||
if (root == null)
|
||||
if (root == null || !root.CanSelectContent)
|
||||
return null;
|
||||
this.selectedElements.TryGetValue(root.Name, out var element);
|
||||
if (element != null && !element.CanBeSelected)
|
||||
return null;
|
||||
return element;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue