S&box Wiki

Revision Difference

UI-bindings#548181

<cat>UI.Intro</cat>⤶ <title>UI Bindings</title>⤶ ⤶ # Binding⤶ ⤶ It is possible to bind functions to change UI elements dynamically without having to recreate an entire UI.⤶ ⤶ # Enabling/Disabling Classes⤶ ⤶ By using the `BindClass` function you can switch a class on/off based on a function callback.⤶ ⤶ ```csharp⤶ someButton.BindClass("disabled", () => !IsEnabled());⤶ ```⤶ ⤶ # Changing Label Text⤶ ⤶ You can change label text by using the `BindSystem` directly.⤶ ⤶ ```csharp⤶ BindSystem.Build⤶ .Set(⤶ moneyLabel,⤶ null,⤶ delegate(int money)⤶ {⤶ moneyLabel.Text = $"Money: ${money}";⤶ }⤶ )⤶ .From(⤶ moneyLabel,⤶ () =>⤶ {⤶ return this.Player.Money;⤶ },⤶ null⤶ );⤶ ```