1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38:34 +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. /// Note that this is only nonnull by default if the constructor was passed a nonnull tooltip text.
/// </summary> /// </summary>
public Tooltip Tooltip; public Tooltip Tooltip;
private bool isDisabled;
/// <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.
@ -72,6 +70,8 @@ namespace MLEM.Ui.Elements {
} }
} }
private bool isDisabled;
/// <summary> /// <summary>
/// Creates a new button with the given settings /// Creates a new button with the given settings
/// </summary> /// </summary>

View file

@ -37,8 +37,6 @@ namespace MLEM.Ui.Elements {
/// The width of the space between this checkbox and its <see cref="Label"/> /// The width of the space between this checkbox and its <see cref="Label"/>
/// </summary> /// </summary>
public StyleProp<float> TextOffsetX; public StyleProp<float> TextOffsetX;
private bool checced;
/// <summary> /// <summary>
/// Whether or not this checkbox is currently checked. /// Whether or not this checkbox is currently checked.
/// </summary> /// </summary>
@ -56,6 +54,8 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public CheckStateChange OnCheckStateChange; public CheckStateChange OnCheckStateChange;
private bool checced;
/// <summary> /// <summary>
/// Creates a new checkbox with the given settings /// Creates a new checkbox with the given settings
/// </summary> /// </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. /// The panel that this dropdown contains. It will be displayed upon pressing the dropdown button.
/// </summary> /// </summary>
public readonly Panel Panel; public readonly Panel Panel;
/// <summary> /// <summary>
/// This property stores whether the dropdown is currently opened or not /// This property stores whether the dropdown is currently opened or not
/// </summary> /// </summary>

View file

@ -24,25 +24,6 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public static float Epsilon = 0.01F; 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> /// <summary>
/// The ui system that this element is currently a part of /// The ui system that this element is currently a part of
/// </summary> /// </summary>
@ -60,10 +41,6 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public UiControls Controls; public UiControls Controls;
/// <summary> /// <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. /// 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>. /// If this element has no parent (it is the <see cref="RootElement"/> of a ui system), this value is <c>null</c>.
/// </summary> /// </summary>
@ -77,8 +54,6 @@ namespace MLEM.Ui.Elements {
/// The scale that this ui element renders with /// The scale that this ui element renders with
/// </summary> /// </summary>
public float Scale => this.Root.ActualScale; public float Scale => this.Root.ActualScale;
private Anchor anchor;
/// <summary> /// <summary>
/// The <see cref="Anchor"/> that this element uses for positioning within its parent /// The <see cref="Anchor"/> that this element uses for positioning within its parent
/// </summary> /// </summary>
@ -91,8 +66,6 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty(); this.SetAreaDirty();
} }
} }
private Vector2 size;
/// <summary> /// <summary>
/// The size of this element, where X represents the width and Y represents the height. /// 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. /// 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. /// The <see cref="Size"/>, but with <see cref="Scale"/> applied.
/// </summary> /// </summary>
public Vector2 ScaledSize => this.size * this.Scale; public Vector2 ScaledSize => this.size * this.Scale;
private Vector2 offset;
/// <summary> /// <summary>
/// This element's offset from its default position, which is dictated by its <see cref="Anchor"/>. /// 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. /// 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. /// The <see cref="PositionOffset"/>, but with <see cref="Scale"/> applied.
/// </summary> /// </summary>
public Vector2 ScaledOffset => this.offset * this.Scale; public Vector2 ScaledOffset => this.offset * this.Scale;
/// <summary> /// <summary>
/// The padding that this element has. /// 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. /// 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. /// The <see cref="Padding"/>, but with <see cref="Scale"/> applied.
/// </summary> /// </summary>
public Padding ScaledPadding => this.Padding * this.Scale; public Padding ScaledPadding => this.Padding * this.Scale;
private Padding childPadding;
/// <summary> /// <summary>
/// The child padding that this element has. /// 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. /// 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. /// This element's current <see cref="Area"/>, but with <see cref="ScaledChildPadding"/> applied.
/// </summary> /// </summary>
public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding); public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding);
private RectangleF area;
/// <summary> /// <summary>
/// This element's area, without respecting its <see cref="ScrollOffset"/>. /// This element's area, without respecting its <see cref="ScrollOffset"/>.
/// This area is updated automatically to fit this element's sizing and positioning properties. /// 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; return this.area;
} }
} }
private bool areaDirty;
/// <summary> /// <summary>
/// The <see cref="UnscrolledArea"/> of this element, but with <see cref="ScaledScrollOffset"/> applied. /// The <see cref="UnscrolledArea"/> of this element, but with <see cref="ScaledScrollOffset"/> applied.
/// </summary> /// </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. /// This is the property that should be used for drawing this element, as well as mouse input handling and culling.
/// </summary> /// </summary>
public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding); public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding);
/// <summary> /// <summary>
/// The offset that this element has as a result of <see cref="Panel"/> scrolling. /// The offset that this element has as a result of <see cref="Panel"/> scrolling.
/// </summary> /// </summary>
@ -201,8 +165,6 @@ namespace MLEM.Ui.Elements {
/// The <see cref="ScrollOffset"/>, but with <see cref="Scale"/> applied. /// The <see cref="ScrollOffset"/>, but with <see cref="Scale"/> applied.
/// </summary> /// </summary>
public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale; public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale;
private bool isHidden;
/// <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.
@ -216,8 +178,6 @@ namespace MLEM.Ui.Elements {
this.SetAreaDirty(); this.SetAreaDirty();
} }
} }
private int priority;
/// <summary> /// <summary>
/// The priority of this element as part of its <see cref="Parent"/> element. /// 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. /// 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(); this.Parent.SetSortedChildrenDirty();
} }
} }
/// <summary> /// <summary>
/// This element's transform matrix. /// This element's transform matrix.
/// Can easily be scaled using <see cref="ScaleTransform"/>. /// 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. /// Note that, when this is non-null, a new <see cref="SpriteBatch.Begin"/> call is used for this element.
/// </summary> /// </summary>
public BeginDelegate BeginImpl; public BeginDelegate BeginImpl;
/// <summary> /// <summary>
/// Set this field to false to disallow the element from being selected. /// 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. /// 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"/>. /// 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> /// </summary>
public float DrawAlpha = 1; public float DrawAlpha = 1;
/// <summary> /// <summary>
/// Stores whether this element is currently being moused over or touched. /// Stores whether this element is currently being moused over or touched.
/// </summary> /// </summary>
@ -303,6 +260,18 @@ namespace MLEM.Ui.Elements {
/// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>. /// Stores whether this element is its <see cref="Root"/>'s <see cref="RootElement.SelectedElement"/>.
/// </summary> /// </summary>
public bool IsSelected { get; protected set; } 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> /// <summary>
/// Event that is called after this element is drawn, but before its children are drawn /// Event that is called after this element is drawn, but before its children are drawn
@ -347,7 +316,6 @@ namespace MLEM.Ui.Elements {
/// <summary> /// <summary>
/// Event that is called when text input is made. /// 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. /// 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. /// 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. /// Also note that if the active <see cref="MlemPlatform"/> uses an on-screen keyboard, this event is never called.
/// </summary> /// </summary>
@ -396,17 +364,36 @@ namespace MLEM.Ui.Elements {
public GenericCallback OnDisposed; public GenericCallback OnDisposed;
/// <summary> /// <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> /// </summary>
public StyleProp<NinePatch> SelectionIndicator; protected readonly IList<Element> Children;
/// <summary> /// <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> /// </summary>
public StyleProp<SoundEffectInfo> ActionSound; protected IList<Element> SortedChildren {
get {
this.UpdateSortedChildrenIfDirty();
return this.sortedChildren;
}
}
/// <summary> /// <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> /// </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> /// <summary>
/// Creates a new element with the given anchor and size and sets up some default event reactions. /// 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 /// The color to render the image at
/// </summary> /// </summary>
public StyleProp<Color> Color; public StyleProp<Color> Color;
private TextureRegion texture;
/// <summary> /// <summary>
/// A callback to retrieve the <see cref="TextureRegion"/> that this image should render. /// A callback to retrieve the <see cref="TextureRegion"/> that this image should render.
/// This can be used if the image changes frequently. /// This can be used if the image changes frequently.
@ -40,7 +39,6 @@ namespace MLEM.Ui.Elements {
} }
} }
} }
private bool scaleToImage;
/// <summary> /// <summary>
/// Whether this image element's <see cref="Element.Size"/> should be based on the size of the <see cref="TextureRegion"/> given. /// 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. /// 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> /// </summary>
public float ImageRotation; public float ImageRotation;
private bool scaleToImage;
private TextureRegion texture;
/// <summary> /// <summary>
/// Creates a new image with the given settings /// Creates a new image with the given settings
/// </summary> /// </summary>

View file

@ -17,6 +17,13 @@ namespace MLEM.Ui.Elements {
/// </summary> /// </summary>
public class Panel : Element { 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> /// <summary>
/// The texture that this panel should have, or null if it should be invisible. /// The texture that this panel should have, or null if it should be invisible.
/// </summary> /// </summary>
@ -35,15 +42,11 @@ namespace MLEM.Ui.Elements {
/// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels /// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels
/// </summary> /// </summary>
public StyleProp<Vector2> ScrollerSize; 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 List<Element> relevantChildren = new List<Element>();
private readonly bool scrollOverflow;
private RenderTarget2D renderTarget;
private bool relevantChildrenDirty; private bool relevantChildrenDirty;
/// <summary> /// <summary>

View file

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

View file

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

View file

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