Class Panel
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. If an element similar to a Group, but with scrolling content, is desired, a panel with its Texture set to null can be used.
public class Panel : Element, IGenericDataHolder, ILayoutItem
- 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
anchorAnchorThe panel's anchor
sizeVector2The panel's default size
positionOffsetVector2The panel's offset from its anchor point
setHeightBasedOnChildrenboolWhether the panel should automatically calculate its height based on its children's size
scrollOverflowboolWhether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers
autoHideScrollbarboolWhether 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
scrollOverflowis 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
anchorAnchorThe panel's anchor
sizeVector2The panel's default size
setHeightBasedOnChildrenboolWhether the panel should automatically calculate its height based on its children's size
scrollOverflowboolWhether this panel should automatically add a scroll bar to scroll towards elements that are beyond the area this panel covers
autoHideScrollbarboolWhether 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
scrollOverflowis 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
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
Texture
The texture that this panel should have. If this is set to null, this panel will not have a texture, but all of its content will still be visible.
public StyleProp<NinePatch> Texture
Field Value
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
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
elementTThe child element to add
indexintThe 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
TThe 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
timeGameTimeThe game's time
batchSpriteBatchThe sprite batch to use for drawing
alphafloatThe alpha to draw this element and its children with
contextSpriteBatchContextThe 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 through its call to this element's SetAreaAndUpdateChildren(RectangleF) method.
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
positionVector2The 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
InitStyle(UiStyle)
Initializes this element's StyleProp<T> instances using the ui system's UiStyle.
protected override void InitStyle(UiStyle style)
Parameters
styleUiStyleThe new style
IsVisible(Element)
Returns whether the given element is currently visible within this panel if it scrolls overflow.
This method will return true on any elements whose Area intersects this panel's render target area, regardless of whether it is a child or grandchild of this panel.
public bool IsVisible(Element element)
Parameters
elementElementThe element to query for visibility.
Returns
- bool
Whether the element is in this panel's visible area.
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
childElementThe child whose area is being set dirty.
grandchildboolWhether the
childis 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
elementElementThe 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
RemovedFromUi()
Called when this element is removed from a UiSystem and RootElement. This method is called in RemoveChild(Element) for a parent whose System is set, as well as 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
elementElementThe 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
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 by invoking ForceUpdateArea() on them. 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
areaRectangleF
- See Also
Update(GameTime)
Updates this element and all of its SortedChildren
public override void Update(GameTime time)
Parameters
timeGameTimeThe game's time