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
loggerILoggercontentIContentManagertextureModelLoaderITextureModelLoaderrenderSurfaceIRenderSurfacetextRendererITextRendererrenderContextFactoryIRenderContextFactory
Exceptions
- ArgumentNullException
renderSurfaceortextRendereris 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
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
DefaultButton
Button activated by Enter when nothing else claims the key - a form's submit.
public Button DefaultButton { get; }
Property Value
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
Id
The view's id. Each view gets a new one.
public string Id { get; }
Property Value
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
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
RootLayout
The layout that holds every control in the view.
public LayoutControl RootLayout { get; }
Property Value
Scope
What the view resolves its pictures and words against besides the game's own, or null.
public ViewScope Scope { get; }
Property Value
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
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
gameTimeIGameTime
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
idGuid
Returns
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
idstring
Returns
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
pointVector2
Returns
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
pixelsfloat
Returns
Update(IGameTime)
Sizes the root layout to the view, then updates the controls.
public override void Update(IGameTime gameTime)
Parameters
gameTimeIGameTime