Table of Contents

Class Panel

Namespace
MLEM.Ui.Elements
Assembly
MLEM.Ui.dll

A panel element to be used inside of a UiSystem. The panel is a complex element that displays a box as a background to all of its child elements. Additionally, a panel can be set to scroll overflowing elements on construction, which causes all elements that don't fit into the panel to be hidden until scrolled to using a ScrollBar.

public class Panel : Element, IGenericDataHolder
Inheritance
Panel
Implements
Derived
Inherited Members
Extension Methods

Constructors

Panel(Anchor, Vector2, Vector2, bool, bool, bool)

Creates a new panel with the given settings.

public Panel(Anchor anchor, Vector2 size, Vector2 positionOffset, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, bool autoHideScrollbar = true)

Parameters

anchor Anchor

The panel's anchor

size Vector2

The panel's default size

positionOffset Vector2

The panel's offset from its anchor point

setHeightBasedOnChildren bool

Whether the panel should automatically calculate its height based on its children's size

scrollOverflow bool

Whether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers

autoHideScrollbar bool

Whether the scroll bar should be hidden automatically if the panel does not contain enough children to allow for scrolling. This only has an effect if scrollOverflow is true.

Panel(Anchor, Vector2, bool, bool, bool)

Creates a new panel with the given settings.

public Panel(Anchor anchor, Vector2 size, bool setHeightBasedOnChildren = false, bool scrollOverflow = false, bool autoHideScrollbar = true)

Parameters

anchor Anchor

The panel's anchor

size Vector2

The panel's default size

setHeightBasedOnChildren bool

Whether the panel should automatically calculate its height based on its children's size

scrollOverflow bool

Whether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers

autoHideScrollbar bool

Whether the scroll bar should be hidden automatically if the panel does not contain enough children to allow for scrolling. This only has an effect if scrollOverflow is true.

Fields

DrawColor

The color that this panel's Texture should be drawn with. If this style property has no value, Microsoft.Xna.Framework.Color.White is used.

public StyleProp<Color> DrawColor

Field Value

StyleProp<Color>

ScrollBar

The scroll bar that this panel contains. This is only nonnull if scrolling overflow was enabled in the constructor. Note that some scroll bar styling is controlled by this panel, namely StepPerScroll and ScrollerSize.

public readonly ScrollBar ScrollBar

Field Value

ScrollBar

ScrollerSize

The size that the ScrollBar's scroller should have, in pixels. The scroller size's height specified here is the minimum height, otherwise, it is automatically calculated based on panel content.

public StyleProp<Vector2> ScrollerSize

Field Value

StyleProp<Vector2>

StepPerScroll

The amount that the scrollable area is moved per single movement of the scroll wheel This value is passed to the ScrollBar's StepPerScroll

public StyleProp<float> StepPerScroll

Field Value

StyleProp<float>

Texture

The texture that this panel should have, or null if it should be invisible.

public StyleProp<NinePatch> Texture

Field Value

StyleProp<NinePatch>

Properties

ScrollBarOffset

The amount of pixels of room there should be between the ScrollBar and the rest of the content

public StyleProp<float> ScrollBarOffset { get; set; }

Property Value

StyleProp<float>

Methods

AddChild<T>(T, int)

Adds a child to this element.

public override T AddChild<T>(T element, int index = -1) where T : Element

Parameters

element T

The child element to add

index int

The index to add the child at, or -1 to add it to the end of the Children list

Returns

T

This element, for chaining

Type Parameters

T

The type of child to add

Draw(GameTime, SpriteBatch, float, SpriteBatchContext)

Draws this element and all of its children. Override this method to draw the content of custom elements. Note that, when this is called, SpriteBatch.Begin has already been called with custom Transform etc. applied.

public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context)

Parameters

time GameTime

The game's time

batch SpriteBatch

The sprite batch to use for drawing

alpha float

The alpha to draw this element and its children with

context SpriteBatchContext

The sprite batch context to use for drawing

ForceUpdateArea()

Forces this element's Area to be updated if it is not IsHidden. This method also updates all of this element's Children's areas.

public override void ForceUpdateArea()

ForceUpdateSortedChildren()

Forces an update of the SortedChildren list.

public override void ForceUpdateSortedChildren()

GetElementUnderPos(Vector2)

Returns the element under the given position, searching the current element and all of its GetRelevantChildren().

public override Element GetElementUnderPos(Vector2 position)

Parameters

position Vector2

The position to query

Returns

Element

The element under the position, or null if no such element exists

GetRelevantChildren()

Returns a subset of Children that are currently relevant in terms of drawing and input querying. A Panel only returns elements that are currently in view here.

protected override IList<Element> GetRelevantChildren()

Returns

IList<Element>

This element's relevant children

InitStyle(UiStyle)

Initializes this element's StyleProp<T> instances using the ui system's UiStyle.

protected override void InitStyle(UiStyle style)

Parameters

style UiStyle

The new style

OnChildAreaDirty(Element, bool)

A method that gets called by this element's Children or any of its grandchildren when their SetAreaDirty() methods get called. Note that the element's area might already be dirty, which will not stop this method from being called.

protected override void OnChildAreaDirty(Element child, bool grandchild)

Parameters

child Element

The child whose area is being set dirty.

grandchild bool

Whether the child is a grandchild of this element, rather than a direct child.

RemoveChild(Element)

Removes the given child from this element.

public override void RemoveChild(Element element)

Parameters

element Element

The child element to remove

RemoveChildren(Func<Element, bool>)

Removes all children from this element that match the given condition.

public override void RemoveChildren(Func<Element, bool> condition = null)

Parameters

condition Func<Element, bool>

The condition that determines if a child should be removed

RemovedFromUi()

Called when this element is removed from a UiSystem and RootElement. This method is called in RemoveChild(Element) and Remove(string).

protected override void RemovedFromUi()

ScrollSetup()

Prepares the panel for auto-scrolling, creating the render target and setting up the scroll bar's maximum value.

protected virtual void ScrollSetup()

ScrollToBottom()

Scrolls this panel's ScrollBar to the bottom, causing the bottom of this panel to be shown.

public void ScrollToBottom()

ScrollToElement(Element)

Scrolls this panel's ScrollBar to the given Element in such a way that its center is positioned in the center of this panel.

public void ScrollToElement(Element element)

Parameters

element Element

The element to scroll to.

ScrollToElement(float)

Scrolls this panel's ScrollBar to the given elementY coordinate in such a way that the coordinate is positioned in the center of this panel.

public void ScrollToElement(float elementY)

Parameters

elementY float

The y coordinate to scroll to, which should have this element's Scale applied.

ScrollToTop()

Scrolls this panel's ScrollBar to the top, causing the top of this panel to be shown.

public void ScrollToTop()

SetAreaAndUpdateChildren(RectangleF)

Sets this element's Area to the given RectangleF and invokes the OnElementAreaUpdated event. This method also updates all of this element's Children's areas. Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all.

public override void SetAreaAndUpdateChildren(RectangleF area)

Parameters

area RectangleF
See Also