Class ComboBox
A drop-down list: a box that shows the chosen option and opens to a list of the options to pick from.
public class ComboBox : InteractiveControl, IUpdateable, IEquatable<IUpdateable>, IDrawable, IIdentifiable<Guid>, IEquatable<IDrawable>, IDisposable
- Inheritance
-
ComboBox
- Implements
- Inherited Members
Constructors
ComboBox(ILogger, View, string, Vector2, Vector2)
Creates a combo box with the id controlId, at location
and of size in pixels.
public ComboBox(ILogger logger, View view, string controlId, Vector2 location, Vector2 size)
Parameters
Properties
ArrowColor
The colour the arrow is drawn in now. It is ArrowHoverColor while the pointer is on the box and ArrowNormalColor otherwise.
public Color ArrowColor { get; }
Property Value
ArrowHoverColor
The arrow's colour while the pointer is on the box.
public Color ArrowHoverColor { get; set; }
Property Value
ArrowNormalColor
The arrow's colour while the pointer is not on the box.
public Color ArrowNormalColor { get; set; }
Property Value
Bounds
The closed box, together with the open list when it is showing, so that clicks and hovers in the list reach the box.
public override Rectangle Bounds { get; }
Property Value
Color
The tint applied to the closed box's texture. White leaves it as it is.
public Color Color { get; set; }
Property Value
DownArrowTexture
The texture of the arrow at the right of the closed box.
public ITexture DownArrowTexture { get; set; }
Property Value
DropDownBorderColor
A flat colour for the border around the open list, or null for none.
public Color? DropDownBorderColor { get; set; }
Property Value
DropDownFillColor
A flat colour behind the open list, or null for none.
public Color? DropDownFillColor { get; set; }
Property Value
DropDownTexture
The background of the open list. Its size follows the number of options.
public ITexture DropDownTexture { get; set; }
Property Value
DropDownTextureReference
Optional source for the dropdown list's background, from the view model's Parts/DropDown. Held as a reference rather than an already-baked texture so it can be re-baked at the list's real size whenever the item count changes - see BSGameLib.UI.Controls.ComboBox.DropdownSize. Defaults to the built-in boxed nine-patch.
public TextureReference DropDownTextureReference { get; set; }
Property Value
FocusedBorderColor
The box's border while the combobox has keyboard focus, or null to leave it as it is. A style's focused state supplies it, as for a text box, so tabbing onto a combobox shows.
public Color? FocusedBorderColor { get; set; }
Property Value
Font
The font the text is drawn in. Set by LoadContent().
public IFont Font { get; }
Property Value
FontColor
The colour of the text in the closed box, or null to keep the theme's colour.
public Color? FontColor { get; set; }
Property Value
FontFile
The font to draw the text in, or the name of a built-in font. Null for the built-in default.
public string FontFile { get; set; }
Property Value
IsOpen
Whether the list is open.
public bool IsOpen { get; }
Property Value
Label
The text shown beside the box.
public string Label { get; set; }
Property Value
MainTexture
The texture drawn for the closed box.
public ITexture MainTexture { get; set; }
Property Value
MaxDropdownHeight
Largest the open list may grow, in pixels. 0 lets it size to its contents, still capped by the room actually left below the control.
public float MaxDropdownHeight { get; set; }
Property Value
OptionsSource
The options as key and display text, for a list the view cannot spell out in its file -
one that depends on the screen, or on a server. Bindable one-way through
OptionsSource="{Binding X}"; setting it replaces every option and keeps the
selected key.
public IEnumerable<KeyValuePair<string, string>> OptionsSource { get; set; }
Property Value
RequiresRawKeyboard
True, so that the arrow keys and Enter reach the box while it has focus.
public override bool RequiresRawKeyboard { get; }
Property Value
SelectedItem
The display text of the selected option, or an empty string when none is selected.
public string SelectedItem { get; }
Property Value
SelectedKey
The key of the chosen option. Settable, and bindable two-way through
SelectedKey="{Binding X}": a choice made in the list is written back.
public string SelectedKey { get; set; }
Property Value
Remarks
A key with no option yet is kept rather than refused, so a view model can say what it wants selected before a list that arrives later - from a server response, say - has been filled in; it shows as soon as that option is added.
SelectionHoverColor
The background of the row under the pointer in the open list.
public Color SelectionHoverColor { get; set; }
Property Value
SelectionHoverFontColor
Text color for the row under the cursor. Unset leaves the row's normal color.
public Color? SelectionHoverFontColor { get; set; }
Property Value
Remarks
The model has carried a HoverFontColor all along but nothing ever drew with it, so a highlight bright enough to see was also bright enough to swallow the text on it.
SelectionSubTexture
The highlight drawn behind the row under the pointer in the open list.
public ITexture SelectionSubTexture { get; }
Property Value
SuppressesDefaultButton
True: Enter on the focused box opens the list or picks the highlighted row, so the view's default button does not also run.
public override bool SuppressesDefaultButton { get; }
Property Value
Methods
Add(string, string)
Adds an option with the key key and the text displayValue. Options are listed in the order they are added.
public void Add(string key, string displayValue)
Parameters
Exceptions
- ArgumentException
An option with the key
keyalready exists.
Clear()
Removes every option, and clears the selection and the scroll position.
public void Clear()
Dispose()
Unsubscribes the box's handlers, then disposes the control.
public override void Dispose()
Draw(IGameTime)
Draws the closed box, its text and arrow, and the open list when it is showing.
public override void Draw(IGameTime gameTime)
Parameters
gameTimeIGameTime
~ComboBox()
Unsubscribes the handlers the box added to its own events.
protected ~ComboBox()
LoadContent()
Loads the font, and the built-in art for the parts the view does not style.
public override void LoadContent()
Update(IGameTime)
Advances the arrow's animation and the open list. Does nothing while the box is disabled.
public override void Update(IGameTime gameTime)
Parameters
gameTimeIGameTime
Events
SelectedIndexChanged
Raised when SelectedKey changes.
public event EventHandler SelectedIndexChanged