Skip to content

Class FloatingElement

Definition

Namespace: StardewUI.Layout
Assembly: StardewUI.dll

Provides independent layout for an IView relative to its parent.

public class FloatingElement : IEquatable<StardewUI.Layout.FloatingElement>

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.

public FloatingElement(StardewUI.IView view, StardewUI.Layout.FloatingPosition position);
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.

public StardewUI.Layout.FloatingPosition Position { get; }
Property Value

FloatingPosition


View

The view to display within this element.

public StardewUI.IView View { get; }
Property Value

IView


Methods

AsViewChild()

Creates a ViewChild with the floating element's view and current position.

public StardewUI.ViewChild AsViewChild();
Returns

ViewChild

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.

public void Draw(StardewUI.Graphics.ISpriteBatch spriteBatch);
Parameters

spriteBatch   ISpriteBatch
Sprite batch to hold the drawing output.


Equals(FloatingElement)

public bool Equals(StardewUI.Layout.FloatingElement other);
Parameters

other   FloatingElement

Returns

Boolean


Equals(Object)

public override bool Equals(System.Object obj);
Parameters

obj   Object

Returns

Boolean


GetHashCode()

public override int GetHashCode();
Returns

Int32


MeasureAndPosition(IView, bool)

Measures the view's content and repositions the entire floating element if necessary.

public void MeasureAndPosition(StardewUI.IView parentView, bool wasParentDirty);
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).