Elements
Label
A text display element for showing read-only text content. Extends BaseElement functionality.
Constructor
new Label("Hello World");
new Label(); // Empty label
new Label(observable); // Bound to observableExamples
ReactiveProperty Binding
Labels display reactive text from ViewModel properties:
// Direct binding to ReactiveProperty
new Label().BindText(ViewModel.UserName);
// Constructor binding (preferred for simple cases)
new Label(ViewModel.WelcomeMessage);
// Transform the observable value
new Label().BindText(ViewModel.Count.Select(count => $"Items: {count}"));Conditional Styling
Use BindClassName to reactively apply styles:
new Label().BindText(ViewModel.StatusMessage)
.BindClassName("error", ViewModel.HasError)
.BindClassName("success", ViewModel.IsSuccess);
// Multiple conditional classes
new Label(ViewModel.PlayerName)
.BindClassName("online", ViewModel.IsOnline)
.BindClassName("moderator", ViewModel.IsModerator);Computed Values
Combine multiple ReactiveProperties for complex displays:
// Combine multiple observables
new Label().BindText(
ViewModel.Health.CombineLatest(ViewModel.MaxHealth)
.Select(values => $"Health: {values.First}/{values.Second}")
);
// Complex formatting
new Label().BindText(
ViewModel.Score.Select(score => $"Score: {score:N0} points")
);Properties
| Prop | Type | Default |
|---|---|---|
text? | string | "" |
disabled? | bool | false |
visible? | bool | true |
name? | string | "" |
pickingMode? | PickingMode | PickingMode.Position |
Methods
| Prop | Type | Default |
|---|---|---|
Text? | (string) => Label | - |
GetText? | () => string | - |
BindText? | (Observable<string>) => Label | - |
Disabled? | (bool = true) => Label | - |
GetDisabled? | () => bool | - |
BindDisabled? | (Observable<bool>) => Label | - |
Visible? | (bool) => Label | - |
GetVisible? | () => bool | - |
BindVisible? | (Observable<bool>) => Label | - |
ClassName? | (string, bool = true) => Label | - |
BindClassName? | (string, Observable<bool>) => Label | - |
StyleSheet? | (StyleSheet) => Label or (string) => Label | - |
Label extends BaseElement.