Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
The static ModalRoot and PopupRoot properties provide an InteractiveGue which serve as the root for any element which should appear on top of other elements. These properties have the following characteristics:
Automatically created by FormsUtilities.InitializeDefaults
Automatically resized to fit the entire screen, including if the GraphicalUiElement.CanvasHeight
and GraphicalUiElement.CanvasWidth
change.
Both Remains on top of all other elements for its given layer. ModalRoot appears on top of PopupRoot.
These properties can be used in custom code to place elements (such as custom popup and toast elements) above all other elements.
ModalRoot and PopupRoot are used internally by Gum Forms. For example PopupRoot is used to display the ListBox which appears when expanding a ComboBox.
Popups which are placed on the ModalRoot element are considered modal - they block the input of all other controls. This is useful if you would like to create a popup which must be clicked before any other elements receive input. If multiple elements are added to ModalRoot, only the last item (and its children) receive input events. This allows one popup to show another popup.
By contrast, elements added to the PopupRoot are not modal - other elements can receive input.
The ComboBox control normally places its expanded form ListBox on PopupRoot; however if the ComboBox is on a ModalRoot then its ListBox is also added to ModalRoot.
The following code can be used to display a popup to either ModalRoot or PopupRoot depending on the isModal
value.
The ScrollViewer control provides a container which can hold Gum objects (including other Gum Forms objects). The user can scroll the ScrollViewer with the mouse or ScrollBar.
By default the ScrollViewer's InnerPanel expands automatically in response to its children and stacks its children top-to-bottom. Of course, this behavior can be changed since the InnterPanel is a standard GraphicalUiElement.
The following code creates a ScrollViewer and adds ColoredRectangleRuntimes to the ScrollViewer.
VerticalScrollBarVisibility controls the visibility of the vertical scroll bar, specifically in regards to the number of items in the ScrollViewer. The available values are:
Auto - the ScrollBar displays only if needed based on the size of the inner panel
Hidden - the ScrollBar remains invisible even if the contents of the inner panel exceed the size of its container
Visible - the ScrollBar always displays
The default is Auto which means that the scroll bar only displays if necessary.
The IsFocused property gets or sets whether a component has focus. For example a TextBox will have its IsFocused set to true if the caret is visible and if it is taking input from the keyboard.
IsFocused can be directly assigned to give focus to an object. For example the following code gives a TextBoxInstance focus:
If you are setting focus on a TextBox in response to a click event, you may need to also clear the Cursor's input. For example, the following would set focus on TextBoxInstance when ButtonInstance is clicked:
The ListBox control provides a scrollable list of ListBoxItems for displaying and selecting from a list.
The following code adds items to a ListBox when a button is clicked. When an item is added, ScrollIntoView
is called so the item is shown.
ListBox items can be selected. The ListBox class provides a number of ways to work with the selection.
Selection can be set by index:
Item can also be selected by the reference itself, assuming the referenced item is part of the list box:
Whenever the selection changes, the SelectionChanged event is raised:
The VisualTemplate lets you customize the type of ListBoxItem created for the ListBox. The following code shows how to assign a VisualTemplate to a runtime object named CustomListBoxItemRuntime:
The VisualTemplate class can optionally pass a parameter representing the item in the list box. This can be used to create different types of items based on the object added. For example the following code would compare the passed object as an integer to whether it is greater than 100 and returns a different item depending on this result:
Note that the code above uses the item to decide which type of list box item to create. If your list box item needs to react to changes on the item, you can also pass the item in the constructor to your list box. This allows for additional initialization based on the item. You can also hold on to the reference of the item to react to changes that may happen on the item, or to push changes to the item.
In other words, you are free to use the item for your game's needs; however, keep in mind that UpdateToObject will be called after your ListBoxItem is constructed. For more information on how to customize UpdateToObject, see the section below.
By default the ListBox calls ToString on each item. This is usually okay if you are dealing with primitive types. For example, the following code adds sequential integers to a ListBox:
Often you may want to add a list of items which should not use their ToString method. For example you may have a list of IDs which represent weapons in a dictionary. The display can be customized by inheriting from ListBoxItem as shown in the following code:
The Slider control provides a way for the user to change a value by dragging the slider thumb.
The following code creates a Slider which allows the user to select a value between 0 and 30, inclusive. The IsSnapToTickEnabled
property results in the value being snapped to the TickFrequency
value. In this case, the value is used to force whole numbers.
The TextBox control allows users to enter a string. It supports highlighting, copy/paste, selection with mouse and keyboard, and CTRL key for performing operations on entire words.
The following code creates a TextBox.
Selection can be performed programmatically or by the user using the cursor.
The SelectionLength
property can be used to determine if any text is selected. The following code shows how to output the selected characters:
The SelectionStart
and SelectionLength
proerties can be modified to change the visual selection. For example, the following selects the first 5 letters:
The entire text can be selected as shown in the following code:
Selection can also be performed by the user. Double-clicking the text box selects all text.
A push+drag with the mouse selects the text between the start and the current location of the drag.
Holding down the shift key and pressing the arrow keys adjusts the selection.
The TextWrapping property can be used to set whether the TextBox wraps text. By default this value is set to TextWrapping.NoWrap
which means the text does not wrap, but instead extends horizontally.
If TextWrapping is set to `TextWrapping.Wrap, then text wraps to multiple lines. Note that usually this is combined with a taller text box so that multiple lines display properly.
The PasswordBox control is a TextBox-like control which can be used for entering passwords. It uses a SecureString
rather than regular string
and hides the entered characters by using the *
key for each character typed. For more information see the SecureString documentation: https://learn.microsoft.com/en-us/dotnet/api/system.security.securestring?view=net-8.0
The following code adds a password box.