Class BindInputElement
- Namespace
- RichHudFramework.UI
- Assembly
- RichHudClient.dll
Attaches custom control-bind (key/combo) event handling to a UI element. Allows arbitrary IBind definitions to trigger NewPressed/PressedAndHeld/Released events on a specific UI node, optionally requiring input focus.
public class BindInputElement : HudNodeBase, IReadOnlyHudNode, IReadOnlyHudParent, IBindInput, IFocusableElement, IEnumerable<IBindEventProxy>, IEnumerable
- Inheritance
-
BindInputElement
- Implements
- Inherited Members
Examples
This example demonstrates how to use a BindInputElement to add keyboard scrolling to a SliderBar. Collection initializer syntax is used to map the LeftArrow and RightArrow directly to handler methods.
public static void CreateSlider(HudParentBase parent)
{
var slider = new SliderBar(parent)
{
Vertical = false,
Min = 0f, Max = 100f, Value = 50f
};
var input = new BindInputElement(slider)
{
// Declarative registration of binds and callbacks
CollectionInitializer =
{
// Format: { IBind, NewPressed, PressedAndHeld, Released (null) }
{ SharedBinds.LeftArrow, OnSliderLeftArrow, OnSliderLeftArrow },
{ SharedBinds.RightArrow, OnSliderRightArrow, OnSliderRightArrow }
}
};
}
private static void OnSliderLeftArrow(object sender, EventArgs e)
{
// The sender is the InputOwner (the SliderBar), not the BindInputElement
var slider = (SliderBar)sender;
slider.Value -= 1f;
}
private static void OnSliderRightArrow(object sender, EventArgs e)
{
var slider = (SliderBar)sender;
slider.Value += 1f;
}
Alternate Initialization
This demonstrates an alternative initialization pattern. Instead of using the collection initializer, the specific IBindEventProxy objects are retrieved using the class indexer. This approach is useful when adding binds dynamically after the object has been constructed or when more explicit syntax is desired.
var input = new BindInputElement(slider) { IsFocusRequired = false };
// Retrieve the event proxy for the Left Arrow bind
IBindEventProxy leftProxy = input[SharedBinds.LeftArrow];
// Subscribe to events
leftProxy.NewPressed += OnSliderLeftArrow;
leftProxy.PressedAndHeld += OnSliderLeftArrow;
// Retrieve and subscribe for the Right Arrow bind
IBindEventProxy rightProxy = input[SharedBinds.RightArrow];
rightProxy.NewPressed += OnSliderRightArrow;
rightProxy.PressedAndHeld += OnSliderRightArrow;
Remarks
BindInputElement functions as a specialized logic node that bridges IBind input with the UI system. Events triggered by this element (such as NewPressed or PressedAndHeld) will only fire if the parent UI node is currently Visible and has InputEnabled set to true. This ensures that keybinds do not trigger actions when the UI is hidden or disabled.
Constructors
BindInputElement(HudParentBase)
public BindInputElement(HudParentBase parent = null)
Parameters
parentHudParentBase
Properties
CollectionInitializer
Allows the addition of binds in conjunction with normal property initialization
public IBindInput CollectionInitializer { get; }
Property Value
FocusHandler
Element that owns this input, used for event callbacks
public IFocusHandler FocusHandler { get; protected set; }
Property Value
InputFilter
If set, the input groups indicated by the flags will be temporarily blocked until the BintInputElement is disabled.
public SeBlacklistModes InputFilter { get; set; }
Property Value
InputPredicate
If defined, bind events will only fire when the predicate returns true.
public Func<bool> InputPredicate { get; set; }
Property Value
IsFocusRequired
If true, bind events will only fire when the parent element has input focus. Default = false.
Only applies if the parent/InputOwner implements IFocusableElement.
public bool IsFocusRequired { get; set; }
Property Value
this[IBind]
Retrieves the event proxy (press/release events) for a specific bind on this UI element
public IBindEventProxy this[IBind bind] { get; }
Parameters
bindIBind
Property Value
Methods
Add(IBind, EventHandler, EventHandler, EventHandler)
Adds a bind (if not already present) and/or subscribes the provided event handlers. Multiple calls with the same bind are allowed and will stack handlers.
public void Add(IBind bind, EventHandler NewPressed = null, EventHandler PressedAndHeld = null, EventHandler Released = null)
Parameters
bindIBindNewPressedEventHandlerPressedAndHeldEventHandlerReleasedEventHandler
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<IBindEventProxy> GetEnumerator()
Returns
- IEnumerator<IBindEventProxy>
An enumerator that can be used to iterate through the collection.
GetHasBind(IBind)
Returns true if the given bind is actively used and handled by this element
public bool GetHasBind(IBind bind)
Parameters
bindIBind
Returns
Reset()
Removes all binds from the element
public void Reset()
Explicit Interface Implementations
IEnumerable.GetEnumerator()
Returns an enumerator that iterates through a collection.
IEnumerator IEnumerable.GetEnumerator()
Returns
- IEnumerator
An IEnumerator object that can be used to iterate through the collection.