Custom Widgets
Creating a custom widget
You can define custom HTML widgets by creating a C# script like so:
// file: MyCustomWidget.cs
[ExternalHTML("UI/testWidget.html")]
public class ButtonWidget : UIWidget
{
}and creating an HTML file that represents the layout of your widget
// file: UI/testWidget.html
<div>
<text>Hello From C#</text>
</div>Using your custom widgets
After building your assembly, you should now be able to use them normally in your other html files. By default, the class name of the C# object is the name you should use in the HTML.
Be careful with recursion!
// UI/MainHUD.html
<div class="root" stylesheet="test.css">
<ButtonWidget></ButtonWidget>
<div class="panel">
<text class="text">Welcome to Nuake Engine</text>
<text class="text">This is a demo project showcasing</text>
<text class="text2">Nuake UI!</text>
</div>
</div>Events
Each UIWidget has a regular set of events that allows you to change the behavior of your widgets.
You can override the following events:public override void OnClick() {}
public override void OnTick() {}
Fetching other nodes
From a custom widget, you can access other DOM nodes. You can use
FindNodeByID<NodeType>("ID"); to fetch a node with a specific ID.
NodeType should be a type that inherits from Node. That includes your custom widgets.
Setting the Text of a TextNode
This is how you would change the text of a text element dynamically:
[ExternalHTML("UI/testWidget.html")]
public class ButtonWidget : UIWidget
{
private TextNode TimerLbl;
private float Timer = 0.0f;
public override void OnInit()
{
TimerLbl = FindChildByID<TextNode>("timer_lbl");
}
public override void OnTick(float dt)
{
Timer += dt;
TimerLbl.Text = Timer.ToString();
}
}This would create a timer by change the text value of a text node. Here is the corresponding Widget HTML
<div>
<text id="timer_lbl"> place_holder_time </text>
</div>