s&box

UI Layout Binding

To enable interaction between code and layout, we enable binding.

Variables

Create a property on your component's code.

public string MyVariable { get; set; }

Bind it to any property by adding @ before the property name.

<text @text="MyVariable"></text>

The property will be updated when your variable changes.

The properties are polled at regular intervals. If the value is different we update the value. This is our comprimise between performance and ease of use.

Elements

You can create a reference to an element.

public Label GameTitle { get; set; }
<text @ref="GameTitle"></text>

This variable will be available immediately after the layout is loaded.

LoadLayout( "/ui/mainmenu/mainmenu.htm" ); GameTitle.Text = "s&box"; GameTitle.Class.Add( "game_title" );

Events

You can call events from elements

<button class="option" onclick="PlayGame()">Play Game</button>
public void PlayGame() { // Do stuff }

The method is called on the panel which loaded the layout.

Panel Events

Similar to events, you can wire up Panel Events that don't need any code. In this example clicking on the Options button toggles the game_title class on it.

<button class="option" onclick="this.ClassToggle( 'game_title' )">Options</button>

You can also target this towards other panels by name

<button name="MyPanel">Watch me</button> <button onclick="MyPanel.ClassToggle( 'hidden' )">Click Me</button>

Special Events

Adding .console to the event name will run the string as a console command when the event triggers.

<button onclick.console="map de_dust">Play Game</button>

Page Links


Special Pages


Wikis

?

Render Time: 62ms

DB GetPage 49
Generate Html 1
SaveChanges (1) 9
Render Body 0
Render Sidebar 0