1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 01:09:23 +01:00

organized MLEM.Ui properties and fields slightly

This commit is contained in:
Ell 2021-10-30 15:01:04 +02:00
parent 1c48a69371
commit 3648352540
9 changed files with 70 additions and 77 deletions

View file

@ -46,8 +46,6 @@ namespace MLEM.Ui.Elements {
/// Note that this is only nonnull by default if the constructor was passed a nonnull tooltip text.
/// </summary>
public Tooltip Tooltip;
private bool isDisabled;
/// <summary>
/// Set this property to true to mark the button as disabled.
/// A disabled button cannot be moused over, selected or pressed.
@ -72,6 +70,8 @@ namespace MLEM.Ui.Elements {
}
}
private bool isDisabled;
/// <summary>
/// Creates a new button with the given settings
/// </summary>

View file

@ -37,8 +37,6 @@ namespace MLEM.Ui.Elements {
/// The width of the space between this checkbox and its <see cref="Label"/>
/// </summary>
public StyleProp<float> TextOffsetX;
private bool checced;
/// <summary>
/// Whether or not this checkbox is currently checked.
/// </summary>
@ -56,6 +54,8 @@ namespace MLEM.Ui.Elements {
/// </summary>
public CheckStateChange OnCheckStateChange;
private bool checced;
/// <summary>
/// Creates a new checkbox with the given settings
/// </summary>

View file

@ -13,6 +13,7 @@ namespace MLEM.Ui.Elements {
/// The panel that this dropdown contains. It will be displayed upon pressing the dropdown button.
/// </summary>
public readonly Panel Panel;
/// <summary>
/// This property stores whether the dropdown is currently opened or not
/// </summary>

View file

@ -24,25 +24,6 @@ namespace MLEM.Ui.Elements {
/// </summary>
public static float Epsilon = 0.01F;
/// <summary>
/// A list of all of this element's direct children.
/// Use <see cref="AddChild{T}"/> or <see cref="RemoveChild"/> to manipulate this list while calling all of the necessary callbacks.
/// </summary>
protected readonly IList<Element> Children;
private readonly List<Element> children = new List<Element>();
/// <summary>
/// A sorted version of <see cref="Children"/>. The children are sorted by their <see cref="Priority"/>.
/// </summary>
protected IList<Element> SortedChildren {
get {
this.UpdateSortedChildrenIfDirty();
return this.sortedChildren;
}
}
private bool sortedChildrenDirty;
private IList<Element> sortedChildren;
private UiSystem system;
/// <summary>
/// The ui system that this element is currently a part of
/// </summary>
@ -60,10 +41,6 @@ namespace MLEM.Ui.Elements {
/// </summary>
public UiControls Controls;
/// <summary>
/// The input handler that this element's <see cref="Controls"/> use
/// </summary>
protected InputHandler Input => this.Controls.Input;
/// <summary>
/// This element's parent element.
/// If this element has no parent (it is the <see cref="RootElement"/> of a ui system), this value is <c>null</c>.
/// </summary>
@ -77,8 +54,6 @@ namespace MLEM.Ui.Elements {
/// The scale that this ui element renders with
/// </summary>
public float Scale => this.Root.ActualScale;
private Anchor anchor;
/// <summary>
/// The <see cref="Anchor"/> that this element uses for positioning within its parent
/// </summary>
@ -91,8 +66,6 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty();
}
}
private Vector2 size;
/// <summary>
/// The size of this element, where X represents the width and Y represents the height.
/// If the x or y value of the size is between 0 and 1, the size will be seen as a percentage of its parent's size rather than as an absolute value.
@ -118,8 +91,6 @@ namespace MLEM.Ui.Elements {
/// The <see cref="Size"/>, but with <see cref="Scale"/> applied.
/// </summary>
public Vector2 ScaledSize => this.size * this.Scale;
private Vector2 offset;
/// <summary>
/// This element's offset from its default position, which is dictated by its <see cref="Anchor"/>.
/// Note that, depending on the side that the element is anchored to, this offset moves it in a different direction.
@ -137,7 +108,6 @@ namespace MLEM.Ui.Elements {
/// The <see cref="PositionOffset"/>, but with <see cref="Scale"/> applied.
/// </summary>
public Vector2 ScaledOffset => this.offset * this.Scale;
/// <summary>
/// The padding that this element has.
/// The padding is subtracted from the element's <see cref="Size"/>, and it is an area that the element does not extend into. This means that this element's resulting <see cref="DisplayArea"/> does not include this padding.
@ -147,8 +117,6 @@ namespace MLEM.Ui.Elements {
/// The <see cref="Padding"/>, but with <see cref="Scale"/> applied.
/// </summary>
public Padding ScaledPadding => this.Padding * this.Scale;
private Padding childPadding;
/// <summary>
/// The child padding that this element has.
/// The child padding moves any <see cref="Children"/> added to this element inwards by the given amount in each direction.
@ -170,8 +138,6 @@ namespace MLEM.Ui.Elements {
/// This element's current <see cref="Area"/>, but with <see cref="ScaledChildPadding"/> applied.
/// </summary>
public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding);
private RectangleF area;
/// <summary>
/// This element's area, without respecting its <see cref="ScrollOffset"/>.
/// This area is updated automatically to fit this element's sizing and positioning properties.
@ -182,7 +148,6 @@ namespace MLEM.Ui.Elements {
return this.area;
}
}
private bool areaDirty;
/// <summary>
/// The <see cref="UnscrolledArea"/> of this element, but with <see cref="ScaledScrollOffset"/> applied.
/// </summary>
@ -192,7 +157,6 @@ namespace MLEM.Ui.Elements {
/// This is the property that should be used for drawing this element, as well as mouse input handling and culling.
/// </summary>
public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding);
/// <summary>
/// The offset that this element has as a result of <see cref="Panel"/> scrolling.
/// </summary>
@ -201,8 +165,6 @@ namespace MLEM.Ui.Elements {
/// The <see cref="ScrollOffset"/>, but with <see cref="Scale"/> applied.
/// </summary>
public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale;
private bool isHidden;
/// <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.
@ -216,8 +178,6 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty();
}
}
private int priority;
/// <summary>
/// The priority of this element as part of its <see cref="Parent"/> element.
/// A higher priority means the element will be drawn first and, if auto-anchoring is used, anchored higher up within its parent.
@ -232,7 +192,6 @@ namespace MLEM.Ui.Elements {
this.Parent.SetSortedChildrenDirty();
}
}
/// <summary>
/// This element's transform matrix.
/// Can easily be scaled using <see cref="ScaleTransform"/>.
@ -244,7 +203,6 @@ namespace MLEM.Ui.Elements {
/// Note that, when this is non-null, a new <see cref="SpriteBatch.Begin"/> call is used for this element.
/// </summary>
public BeginDelegate BeginImpl;
/// <summary>
/// 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.
@ -294,7 +252,6 @@ namespace MLEM.Ui.Elements {
/// 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;
/// <summary>
/// Stores whether this element is currently being moused over or touched.
/// </summary>
@ -303,6 +260,18 @@ namespace MLEM.Ui.Elements {
/// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>.
/// </summary>
public bool IsSelected { get; protected set; }
/// <summary>
/// A style property that contains the selection indicator that is displayed on this element if it is the <see cref="RootElement.SelectedElement"/>
/// </summary>
public StyleProp<NinePatch> SelectionIndicator;
/// <summary>
/// A style property that contains the sound effect that is played when this element's <see cref="OnPressed"/> is called
/// </summary>
public StyleProp<SoundEffectInfo> ActionSound;
/// <summary>
/// A style property that contains the sound effect that is played when this element's <see cref="OnSecondaryPressed"/> is called
/// </summary>
public StyleProp<SoundEffectInfo> SecondActionSound;
/// <summary>
/// Event that is called after this element is drawn, but before its children are drawn
@ -347,7 +316,6 @@ namespace MLEM.Ui.Elements {
/// <summary>
/// Event that is called when text input is made.
/// When an element uses this event, it should call <see cref="MlemPlatform.EnsureExists"/> on construction to ensure that the MLEM platform is initialized.
///
/// Note that this event is called for every element, even if it is not selected.
/// Also note that if the active <see cref="MlemPlatform"/> uses an on-screen keyboard, this event is never called.
/// </summary>
@ -396,17 +364,36 @@ namespace MLEM.Ui.Elements {
public GenericCallback OnDisposed;
/// <summary>
/// A style property that contains the selection indicator that is displayed on this element if it is the <see cref="RootElement.SelectedElement"/>
/// A list of all of this element's direct children.
/// Use <see cref="AddChild{T}"/> or <see cref="RemoveChild"/> to manipulate this list while calling all of the necessary callbacks.
/// </summary>
public StyleProp<NinePatch> SelectionIndicator;
protected readonly IList<Element> Children;
/// <summary>
/// A style property that contains the sound effect that is played when this element's <see cref="OnPressed"/> is called
/// A sorted version of <see cref="Children"/>. The children are sorted by their <see cref="Priority"/>.
/// </summary>
public StyleProp<SoundEffectInfo> ActionSound;
protected IList<Element> SortedChildren {
get {
this.UpdateSortedChildrenIfDirty();
return this.sortedChildren;
}
}
/// <summary>
/// A style property that contains the sound effect that is played when this element's <see cref="OnSecondaryPressed"/> is called
/// The input handler that this element's <see cref="Controls"/> use
/// </summary>
public StyleProp<SoundEffectInfo> SecondActionSound;
protected InputHandler Input => this.Controls.Input;
private readonly List<Element> children = new List<Element>();
private bool sortedChildrenDirty;
private IList<Element> sortedChildren;
private UiSystem system;
private Anchor anchor;
private Vector2 size;
private Vector2 offset;
private Padding childPadding;
private RectangleF area;
private bool areaDirty;
private bool isHidden;
private int priority;
/// <summary>
/// Creates a new element with the given anchor and size and sets up some default event reactions.

View file

@ -16,7 +16,6 @@ namespace MLEM.Ui.Elements {
/// The color to render the image at
/// </summary>
public StyleProp<Color> Color;
private TextureRegion texture;
/// <summary>
/// A callback to retrieve the <see cref="TextureRegion"/> that this image should render.
/// This can be used if the image changes frequently.
@ -40,7 +39,6 @@ namespace MLEM.Ui.Elements {
}
}
}
private bool scaleToImage;
/// <summary>
/// Whether this image element's <see cref="Element.Size"/> should be based on the size of the <see cref="TextureRegion"/> given.
/// Note that, when scaling to the image's size, the <see cref="Element.Scale"/> is also taken into account.
@ -73,6 +71,9 @@ namespace MLEM.Ui.Elements {
/// </summary>
public float ImageRotation;
private bool scaleToImage;
private TextureRegion texture;
/// <summary>
/// Creates a new image with the given settings
/// </summary>

View file

@ -17,6 +17,13 @@ namespace MLEM.Ui.Elements {
/// </summary>
public class Panel : Element {
/// <summary>
/// The scroll bar that this panel contains.
/// This is only nonnull if <see cref="scrollOverflow"/> is true.
/// Note that some scroll bar styling is controlled by this panel, namely <see cref="StepPerScroll"/> and <see cref="ScrollerSize"/>.
/// </summary>
public readonly ScrollBar ScrollBar;
/// <summary>
/// The texture that this panel should have, or null if it should be invisible.
/// </summary>
@ -35,15 +42,11 @@ namespace MLEM.Ui.Elements {
/// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels
/// </summary>
public StyleProp<Vector2> ScrollerSize;
/// <summary>
/// The scroll bar that this panel contains.
/// This is only nonnull if <see cref="scrollOverflow"/> is true.
/// Note that some scroll bar styling is controlled by this panel, namely <see cref="StepPerScroll"/> and <see cref="ScrollerSize"/>.
/// </summary>
public readonly ScrollBar ScrollBar;
private readonly bool scrollOverflow;
private RenderTarget2D renderTarget;
private readonly List<Element> relevantChildren = new List<Element>();
private readonly bool scrollOverflow;
private RenderTarget2D renderTarget;
private bool relevantChildrenDirty;
/// <summary>

View file

@ -25,7 +25,6 @@ namespace MLEM.Ui.Elements {
/// The tokenized version of the <see cref="Text"/>
/// </summary>
public TokenizedString TokenizedText { get; private set; }
/// <summary>
/// The color that the text will be rendered with
/// </summary>

View file

@ -34,7 +34,6 @@ namespace MLEM.Ui.Elements {
/// The color that this progress bar's <see cref="ProgressTexture"/> is rendered with.
/// </summary>
public StyleProp<Color> ProgressColor;
/// <summary>
/// The direction that this progress bar goes in.
/// Note that only <see cref="Direction2Helper.Adjacent"/> directions are supported.
@ -44,7 +43,6 @@ namespace MLEM.Ui.Elements {
/// The maximum value that this progress bar should be able to have.
/// </summary>
public float MaxValue;
private float currentValue;
/// <summary>
/// The current value that this progress bar has.
/// This value is always between 0 and <see cref="MaxValue"/>.
@ -54,6 +52,8 @@ namespace MLEM.Ui.Elements {
set => this.currentValue = MathHelper.Clamp(value, 0, this.MaxValue);
}
private float currentValue;
/// <summary>
/// Creates a new progress bar with the given settings
/// </summary>

View file

@ -17,6 +17,11 @@ namespace MLEM.Ui.Elements {
/// </summary>
public class ScrollBar : Element {
/// <summary>
/// Whether this scroll bar is horizontal
/// </summary>
public readonly bool Horizontal;
/// <summary>
/// The background texture for this scroll bar
/// </summary>
@ -33,7 +38,6 @@ namespace MLEM.Ui.Elements {
/// The scroller's width and height
/// </summary>
public Vector2 ScrollerSize;
private float maxValue;
/// <summary>
/// The max value that this scroll bar should be able to scroll to.
/// Note that the maximum value does not change the height of the scroll bar.
@ -52,8 +56,6 @@ namespace MLEM.Ui.Elements {
}
}
}
private float scrollAdded;
private float currValue;
/// <summary>
/// The current value of the scroll bar.
/// This is between 0 and <see cref="MaxValue"/> at all times.
@ -71,10 +73,6 @@ namespace MLEM.Ui.Elements {
}
}
/// <summary>
/// Whether this scroll bar is horizontal
/// </summary>
public readonly bool Horizontal;
/// <summary>
/// The amount added or removed from <see cref="CurrentValue"/> per single movement of the scroll wheel
/// </summary>
public float StepPerScroll = 1;
@ -90,9 +88,6 @@ namespace MLEM.Ui.Elements {
/// This property is true while the user scrolls on the scroll bar using the mouse or touch input
/// </summary>
public bool IsBeingScrolled => this.isMouseHeld || this.isDragging || this.isTouchHeld;
private bool isMouseHeld;
private bool isDragging;
private bool isTouchHeld;
/// <summary>
/// This field determines if this scroll bar should automatically be hidden from a <see cref="Panel"/> if there aren't enough children to allow for scrolling.
/// </summary>
@ -107,6 +102,13 @@ namespace MLEM.Ui.Elements {
/// </summary>
public StyleProp<float> SmoothScrollFactor;
private bool isMouseHeld;
private bool isDragging;
private bool isTouchHeld;
private float maxValue;
private float scrollAdded;
private float currValue;
static ScrollBar() {
InputHandler.EnableGestures(GestureType.HorizontalDrag, GestureType.VerticalDrag);
}