Table of Contents

Class View

Namespace
BSGameLib.UI
Assembly
BSGameLib.UI.dll

A View represents a logical "page" of UI within a UIRoot. Contains layout + controls, manages focus within itself.

public class View : DrawableComponent, IUpdateable, IEquatable<IUpdateable>, IDrawable, IIdentifiable<Guid>, IEquatable<IDrawable>, IDisposable
Inheritance
View
Implements
Inherited Members

Constructors

View(ILogger, IContentManager, ITextureModelLoader, IRenderSurface, ITextRenderer, IRenderContextFactory)

Creates a view. The view is empty until it is built.

public View(ILogger logger, IContentManager content, ITextureModelLoader textureModelLoader, IRenderSurface renderSurface, ITextRenderer textRenderer, IRenderContextFactory renderContextFactory)

Parameters

logger ILogger
content IContentManager
textureModelLoader ITextureModelLoader
renderSurface IRenderSurface
textRenderer ITextRenderer
renderContextFactory IRenderContextFactory

Exceptions

ArgumentNullException

renderSurface or textRenderer is null.

Properties

DataContext

The object the view's bindings read from and write to: usually its view-model.

public IDataContext DataContext { get; set; }

Property Value

IDataContext

Decorations

Marks pinned to the view's edges. They are drawn over the controls and take no space in the layout.

public List<Decoration> Decorations { get; }

Property Value

List<Decoration>

DefaultButton

Button activated by Enter when nothing else claims the key - a form's submit.

public Button DefaultButton { get; }

Property Value

Button

Remarks

Resolved rather than stored, because a view can hold more than one form. A tabbed screen is built as several groups in the same place with only one of them visible, and each wants its own submit; this was a single slot that whichever button was created last won, so the hidden tab's submit was the view's default and Enter ran its command. On Odyssey's login screen that meant pressing Enter on the direct-connect tab signing in with the registry instead, while clicking the button worked -- which is exactly how it was found.

A group that is hidden or switched off is skipped, so the answer follows whichever form is actually in front of the player. Null when none of them is.

FocusableControls

The controls that can take focus, in the order Tab moves through them.

public List<InteractiveControl> FocusableControls { get; }

Property Value

List<InteractiveControl>

Id

The view's id. Each view gets a new one.

public string Id { get; }

Property Value

string

InitialFocus

Where focus lands when this view opens, if it declares one: the first control marked IsInitialFocus that is visible and enabled. Null means "the first focusable control in the tree", which BSGameLib.UI.UIRoot falls back to.

public InteractiveControl InitialFocus { get; }

Property Value

InteractiveControl

Remarks

A set resolved by visibility, exactly like DefaultButton and for the same reason: a tabbed screen is several groups in one place with one showing, and each tab wants its own first field. A single slot would hand focus to a field on a hidden tab.

IsInitialized

Whether the view has been initialized. See Initialize().

public bool IsInitialized { get; }

Property Value

bool

RootLayout

The layout that holds every control in the view.

public LayoutControl RootLayout { get; }

Property Value

LayoutControl

Scope

What the view resolves its pictures and words against besides the game's own, or null.

public ViewScope Scope { get; }

Property Value

ViewScope

UIScale

The scale this view was built at: every size, position, spacing and font size it declared was multiplied by this as its controls were created. Controls multiply their own built-in pixel constants by it too, through Scaled(float). See UIScaleSettings.

public float UIScale { get; }

Property Value

float

Methods

Dispose()

Unsubscribes from the data context, then disposes the controls.

public void Dispose()

Draw(IGameTime)

Draws the view's controls and decorations, in a render pass of their own.

public override sealed void Draw(IGameTime gameTime)

Parameters

gameTime IGameTime

Exceptions

InvalidOperationException

The view has no render context factory.

GetControl(Guid)

Returns the control with the GUID id, searched through the whole layout. Null when none has it.

public UIElement GetControl(Guid id)

Parameters

id Guid

Returns

UIElement

GetControl(string)

Returns the control with the id id, searched through the whole layout. Null when none has it.

public UIElement GetControl(string id)

Parameters

id string

Returns

UIElement

HoverKeyAt(Vector2)

The HoverKey of the innermost element under point that has one, in the view's own space, rows of a list included; null when there is none.

public string HoverKeyAt(Vector2 point)

Parameters

point Vector2

Returns

string

Initialize()

Prepares the view for use: works out which controls can take focus. Runs once; later calls do nothing.

public void Initialize()

InvalidateFocusables()

Tells the view its focusable controls need working out again - a repeater built or threw away rows, or scrolled a different set of them into view.

public void InvalidateFocusables()

LoadContent()

Initializes the view if it is not yet initialized, loads its controls and applies its bindings.

public override void LoadContent()

Scaled(float)

A pixel measurement at this view's scale.

public float Scaled(float pixels)

Parameters

pixels float

Returns

float

Update(IGameTime)

Sizes the root layout to the view, then updates the controls.

public override void Update(IGameTime gameTime)

Parameters

gameTime IGameTime