From 3648352540dcef658e6195aa9f5bf84e29673607 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 30 Oct 2021 15:01:04 +0200 Subject: [PATCH] organized MLEM.Ui properties and fields slightly --- MLEM.Ui/Elements/Button.cs | 4 +- MLEM.Ui/Elements/Checkbox.cs | 4 +- MLEM.Ui/Elements/Dropdown.cs | 1 + MLEM.Ui/Elements/Element.cs | 87 ++++++++++++++------------------- MLEM.Ui/Elements/Image.cs | 5 +- MLEM.Ui/Elements/Panel.cs | 19 ++++--- MLEM.Ui/Elements/Paragraph.cs | 1 - MLEM.Ui/Elements/ProgressBar.cs | 4 +- MLEM.Ui/Elements/ScrollBar.cs | 22 +++++---- 9 files changed, 70 insertions(+), 77 deletions(-) diff --git a/MLEM.Ui/Elements/Button.cs b/MLEM.Ui/Elements/Button.cs index 1b2cf0e..ee7fdd5 100644 --- a/MLEM.Ui/Elements/Button.cs +++ b/MLEM.Ui/Elements/Button.cs @@ -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. /// public Tooltip Tooltip; - - private bool isDisabled; /// /// 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; + /// /// Creates a new button with the given settings /// diff --git a/MLEM.Ui/Elements/Checkbox.cs b/MLEM.Ui/Elements/Checkbox.cs index e214120..f837ebd 100644 --- a/MLEM.Ui/Elements/Checkbox.cs +++ b/MLEM.Ui/Elements/Checkbox.cs @@ -37,8 +37,6 @@ namespace MLEM.Ui.Elements { /// The width of the space between this checkbox and its /// public StyleProp TextOffsetX; - - private bool checced; /// /// Whether or not this checkbox is currently checked. /// @@ -56,6 +54,8 @@ namespace MLEM.Ui.Elements { /// public CheckStateChange OnCheckStateChange; + private bool checced; + /// /// Creates a new checkbox with the given settings /// diff --git a/MLEM.Ui/Elements/Dropdown.cs b/MLEM.Ui/Elements/Dropdown.cs index 7b85120..9fd32ca 100644 --- a/MLEM.Ui/Elements/Dropdown.cs +++ b/MLEM.Ui/Elements/Dropdown.cs @@ -13,6 +13,7 @@ namespace MLEM.Ui.Elements { /// The panel that this dropdown contains. It will be displayed upon pressing the dropdown button. /// public readonly Panel Panel; + /// /// This property stores whether the dropdown is currently opened or not /// diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index e3b79e0..4d9abf6 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -24,25 +24,6 @@ namespace MLEM.Ui.Elements { /// public static float Epsilon = 0.01F; - /// - /// A list of all of this element's direct children. - /// Use or to manipulate this list while calling all of the necessary callbacks. - /// - protected readonly IList Children; - private readonly List children = new List(); - /// - /// A sorted version of . The children are sorted by their . - /// - protected IList SortedChildren { - get { - this.UpdateSortedChildrenIfDirty(); - return this.sortedChildren; - } - } - private bool sortedChildrenDirty; - private IList sortedChildren; - - private UiSystem system; /// /// The ui system that this element is currently a part of /// @@ -60,10 +41,6 @@ namespace MLEM.Ui.Elements { /// public UiControls Controls; /// - /// The input handler that this element's use - /// - protected InputHandler Input => this.Controls.Input; - /// /// This element's parent element. /// If this element has no parent (it is the of a ui system), this value is null. /// @@ -77,8 +54,6 @@ namespace MLEM.Ui.Elements { /// The scale that this ui element renders with /// public float Scale => this.Root.ActualScale; - - private Anchor anchor; /// /// The that this element uses for positioning within its parent /// @@ -91,8 +66,6 @@ namespace MLEM.Ui.Elements { this.SetAreaDirty(); } } - - private Vector2 size; /// /// 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 , but with applied. /// public Vector2 ScaledSize => this.size * this.Scale; - - private Vector2 offset; /// /// This element's offset from its default position, which is dictated by its . /// 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 , but with applied. /// public Vector2 ScaledOffset => this.offset * this.Scale; - /// /// The padding that this element has. /// The padding is subtracted from the element's , and it is an area that the element does not extend into. This means that this element's resulting does not include this padding. @@ -147,8 +117,6 @@ namespace MLEM.Ui.Elements { /// The , but with applied. /// public Padding ScaledPadding => this.Padding * this.Scale; - - private Padding childPadding; /// /// The child padding that this element has. /// The child padding moves any added to this element inwards by the given amount in each direction. @@ -170,8 +138,6 @@ namespace MLEM.Ui.Elements { /// This element's current , but with applied. /// public RectangleF ChildPaddedArea => this.UnscrolledArea.Shrink(this.ScaledChildPadding); - - private RectangleF area; /// /// This element's area, without respecting its . /// 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; /// /// The of this element, but with applied. /// @@ -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. /// public RectangleF DisplayArea => this.Area.Shrink(this.ScaledPadding); - /// /// The offset that this element has as a result of scrolling. /// @@ -201,8 +165,6 @@ namespace MLEM.Ui.Elements { /// The , but with applied. /// public Vector2 ScaledScrollOffset => this.ScrollOffset * this.Scale; - - private bool isHidden; /// /// Set this property to true 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; /// /// The priority of this element as part of its 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(); } } - /// /// This element's transform matrix. /// Can easily be scaled using . @@ -244,7 +203,6 @@ namespace MLEM.Ui.Elements { /// Note that, when this is non-null, a new call is used for this element. /// public BeginDelegate BeginImpl; - /// /// Set this field to false to disallow the element from being selected. /// An unselectable element is skipped by automatic navigation and its callback will never be called. @@ -294,7 +252,6 @@ namespace MLEM.Ui.Elements { /// Note that, when is called, this alpha value is multiplied with the 's alpha value and passed down to this element's . /// public float DrawAlpha = 1; - /// /// Stores whether this element is currently being moused over or touched. /// @@ -303,6 +260,18 @@ namespace MLEM.Ui.Elements { /// Stores whether this element is its 's . /// public bool IsSelected { get; protected set; } + /// + /// A style property that contains the selection indicator that is displayed on this element if it is the + /// + public StyleProp SelectionIndicator; + /// + /// A style property that contains the sound effect that is played when this element's is called + /// + public StyleProp ActionSound; + /// + /// A style property that contains the sound effect that is played when this element's is called + /// + public StyleProp SecondActionSound; /// /// Event that is called after this element is drawn, but before its children are drawn @@ -347,7 +316,6 @@ namespace MLEM.Ui.Elements { /// /// Event that is called when text input is made. /// When an element uses this event, it should call 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 uses an on-screen keyboard, this event is never called. /// @@ -396,17 +364,36 @@ namespace MLEM.Ui.Elements { public GenericCallback OnDisposed; /// - /// A style property that contains the selection indicator that is displayed on this element if it is the + /// A list of all of this element's direct children. + /// Use or to manipulate this list while calling all of the necessary callbacks. /// - public StyleProp SelectionIndicator; + protected readonly IList Children; /// - /// A style property that contains the sound effect that is played when this element's is called + /// A sorted version of . The children are sorted by their . /// - public StyleProp ActionSound; + protected IList SortedChildren { + get { + this.UpdateSortedChildrenIfDirty(); + return this.sortedChildren; + } + } /// - /// A style property that contains the sound effect that is played when this element's is called + /// The input handler that this element's use /// - public StyleProp SecondActionSound; + protected InputHandler Input => this.Controls.Input; + + private readonly List children = new List(); + private bool sortedChildrenDirty; + private IList 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; /// /// Creates a new element with the given anchor and size and sets up some default event reactions. diff --git a/MLEM.Ui/Elements/Image.cs b/MLEM.Ui/Elements/Image.cs index 3bf6cd5..c1c0812 100644 --- a/MLEM.Ui/Elements/Image.cs +++ b/MLEM.Ui/Elements/Image.cs @@ -16,7 +16,6 @@ namespace MLEM.Ui.Elements { /// The color to render the image at /// public StyleProp Color; - private TextureRegion texture; /// /// A callback to retrieve the 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; /// /// Whether this image element's should be based on the size of the given. /// Note that, when scaling to the image's size, the is also taken into account. @@ -73,6 +71,9 @@ namespace MLEM.Ui.Elements { /// public float ImageRotation; + private bool scaleToImage; + private TextureRegion texture; + /// /// Creates a new image with the given settings /// diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 01d416f..2428fcd 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -17,6 +17,13 @@ namespace MLEM.Ui.Elements { /// public class Panel : Element { + /// + /// The scroll bar that this panel contains. + /// This is only nonnull if is true. + /// Note that some scroll bar styling is controlled by this panel, namely and . + /// + public readonly ScrollBar ScrollBar; + /// /// The texture that this panel should have, or null if it should be invisible. /// @@ -35,15 +42,11 @@ namespace MLEM.Ui.Elements { /// The size that the 's scroller should have, in pixels /// public StyleProp ScrollerSize; - /// - /// The scroll bar that this panel contains. - /// This is only nonnull if is true. - /// Note that some scroll bar styling is controlled by this panel, namely and . - /// - public readonly ScrollBar ScrollBar; - private readonly bool scrollOverflow; - private RenderTarget2D renderTarget; + private readonly List relevantChildren = new List(); + private readonly bool scrollOverflow; + + private RenderTarget2D renderTarget; private bool relevantChildrenDirty; /// diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index d23d3b6..adedcd0 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -25,7 +25,6 @@ namespace MLEM.Ui.Elements { /// The tokenized version of the /// public TokenizedString TokenizedText { get; private set; } - /// /// The color that the text will be rendered with /// diff --git a/MLEM.Ui/Elements/ProgressBar.cs b/MLEM.Ui/Elements/ProgressBar.cs index cf739ec..72daf76 100644 --- a/MLEM.Ui/Elements/ProgressBar.cs +++ b/MLEM.Ui/Elements/ProgressBar.cs @@ -34,7 +34,6 @@ namespace MLEM.Ui.Elements { /// The color that this progress bar's is rendered with. /// public StyleProp ProgressColor; - /// /// The direction that this progress bar goes in. /// Note that only directions are supported. @@ -44,7 +43,6 @@ namespace MLEM.Ui.Elements { /// The maximum value that this progress bar should be able to have. /// public float MaxValue; - private float currentValue; /// /// The current value that this progress bar has. /// This value is always between 0 and . @@ -54,6 +52,8 @@ namespace MLEM.Ui.Elements { set => this.currentValue = MathHelper.Clamp(value, 0, this.MaxValue); } + private float currentValue; + /// /// Creates a new progress bar with the given settings /// diff --git a/MLEM.Ui/Elements/ScrollBar.cs b/MLEM.Ui/Elements/ScrollBar.cs index 72778c7..e8d988d 100644 --- a/MLEM.Ui/Elements/ScrollBar.cs +++ b/MLEM.Ui/Elements/ScrollBar.cs @@ -17,6 +17,11 @@ namespace MLEM.Ui.Elements { /// public class ScrollBar : Element { + /// + /// Whether this scroll bar is horizontal + /// + public readonly bool Horizontal; + /// /// The background texture for this scroll bar /// @@ -33,7 +38,6 @@ namespace MLEM.Ui.Elements { /// The scroller's width and height /// public Vector2 ScrollerSize; - private float maxValue; /// /// 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; /// /// The current value of the scroll bar. /// This is between 0 and at all times. @@ -71,10 +73,6 @@ namespace MLEM.Ui.Elements { } } /// - /// Whether this scroll bar is horizontal - /// - public readonly bool Horizontal; - /// /// The amount added or removed from per single movement of the scroll wheel /// 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 /// public bool IsBeingScrolled => this.isMouseHeld || this.isDragging || this.isTouchHeld; - private bool isMouseHeld; - private bool isDragging; - private bool isTouchHeld; /// /// This field determines if this scroll bar should automatically be hidden from a if there aren't enough children to allow for scrolling. /// @@ -107,6 +102,13 @@ namespace MLEM.Ui.Elements { /// public StyleProp 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); }