Class FloatingElement
Definition
Namespace: StardewUI.Layout
Assembly: StardewUI.dll
Provides independent layout for an IView relative to its parent.
Inheritance
Object ⇦ FloatingElement
Implements
IEquatable<FloatingElement>
Remarks
Floating elements do not participate in the normal layout (Measure(Vector2)) of the view that owns them; they are excluded entirely from the flow, and then provided with their own measurement and position using the final bounds of the parent (i.e. those that result from its non-floating elements).
This is primarily useful for annotations, callouts, or elements that are intentionally drawn outside their logical container such as scrollbars or sidebars. Floating views can receive focus and clicks, but do not actually capture the cursor like an Overlay would, and therefore shouldn't be used for modal UI.
In general it is preferred to use standard layout controls like Lane over floating elements, but there are specific cases that justify floats, such as the aforementioned scrollbar which should display "outside" the container regardless of how nested the container itself is - i.e. the float must "break out" of the normal flow.
Members
Constructors
Name | Description |
---|---|
FloatingElement(IView, FloatingPosition) | Provides independent layout for an IView relative to its parent. |
Properties
Name | Description |
---|---|
Position | The element's defined position. |
View | The view to display within this element. |
Methods
Name | Description |
---|---|
AsViewChild() | Creates a ViewChild with the floating element's view and current position. |
Draw(ISpriteBatch) | Draws the element at its current position. |
Equals(FloatingElement) | |
Equals(Object) | (Overrides Object.Equals(Object) ) |
GetHashCode() | (Overrides Object.GetHashCode() ) |
MeasureAndPosition(IView, Boolean) | Measures the view's content and repositions the entire floating element if necessary. |
Details
Constructors
FloatingElement(IView, FloatingPosition)
Provides independent layout for an IView relative to its parent.
Parameters
view
IView
The floating view to display/interact with.
position
FloatingPosition
Specifies how to position the view
relative to the parent and its own measured size.
Remarks
Floating elements do not participate in the normal layout (Measure(Vector2)) of the view that owns them; they are excluded entirely from the flow, and then provided with their own measurement and position using the final bounds of the parent (i.e. those that result from its non-floating elements).
This is primarily useful for annotations, callouts, or elements that are intentionally drawn outside their logical container such as scrollbars or sidebars. Floating views can receive focus and clicks, but do not actually capture the cursor like an Overlay would, and therefore shouldn't be used for modal UI.
In general it is preferred to use standard layout controls like Lane over floating elements, but there are specific cases that justify floats, such as the aforementioned scrollbar which should display "outside" the container regardless of how nested the container itself is - i.e. the float must "break out" of the normal flow.
Properties
Position
The element's defined position.
Property Value
View
The view to display within this element.
Property Value
Methods
AsViewChild()
Creates a ViewChild with the floating element's view and current position.
Returns
The current element represented as a ViewChild.
Remarks
The result can generally be used as if it were any other non-floating element, e.g. for dispatching clicks, focus searches and other events.
Draw(ISpriteBatch)
Draws the element at its current position.
Parameters
spriteBatch
ISpriteBatch
Sprite batch to hold the drawing output.
Equals(FloatingElement)
Parameters
other
FloatingElement
Returns
Equals(Object)
Parameters
obj
Object
Returns
GetHashCode()
Returns
MeasureAndPosition(IView, bool)
Measures the view's content and repositions the entire floating element if necessary.
Parameters
parentView
IView
The view whose FloatingElements this element belongs to. Required for repositioning when the layout has changed.
wasParentDirty
Boolean
Whether this measurement is being done because the parent's layout already changed and therefore a reposition is always required (true
), or whether to reposition only if the floating element's internal layout has changed (false
).