Here is an example using text buttons, a stack box and a canvas. Note that there are a number of bugs in the current release so this will not work properly until the next public release.
using { /Verse.org/Simulation }
using { /EpicGames.com/Temporary/SpatialMath }
using { /EpicGames.com/Temporary/UI }
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
hello_world_device := class(creative_device):
@editable
MyButton:button_device = button_device{}
var Canvas:?canvas = false
OnBegin<override>()<suspends>:void=
MyButton.InteractedWithEvent.Subscribe(HandleInteractedWithEvent)
HandleInteractedWithEvent(Player:player):void=
Print("Button Interacted With!")
if (PlayerUI := GetPlayerUI[Player]):
if (TmpCanvas := Canvas?):
Print("Removing Canvas")
PlayerUI.RemoveWidget(TmpCanvas)
set Canvas = false
else:
Print("Create New Canvas")
NewCanvas := MakeCanvas()
# Add the canvas and set input mode to UI (ie mouse controls cursor and not game)
PlayerUI.AddWidget(NewCanvas, player_ui_slot{ InputMode := ui_input_mode.UI })
set Canvas = option{NewCanvas}
MakeCanvas():canvas=
NewButtonA:button_loud=button_loud{ DefaultText := "New Button A" }
NewButtonB:button_regular=button_regular{ DefaultText := "New Button B" }
NewButtonC:button_quiet=button_quiet{ DefaultText := "New Button C" }
NewButtonA.OnClick.Subscribe(OnButtonClickedA)
NewButtonB.OnClick.Subscribe(OnButtonClickedB)
NewButtonC.OnClick.Subscribe(OnButtonClickedC)
NewCanvas := canvas:
Slots := array:
canvas_slot:
Anchors := anchors{ Maximum:= vector2{X:=1.0, Y:=1.0} }
Offsets := margin{ Top:=100.0, Left:=100.0, Right:=100.0, Bottom := 100.0 }
Widget := stack_box:
Orientation := orientation.Vertical
Slots := array:
stack_box_slot:
Widget := NewButtonA
stack_box_slot:
Widget := NewButtonB
stack_box_slot:
Widget := NewButtonC
return NewCanvas
OnButtonClickedA(Message:widget_message):void=
Print("ButtonA Clicked")
if (Button := text_button_base[Message.Source]):
Button.SetText("Message Received A")
# Test remove the whole canvas in response to a click
if (TmpPlayerUI := GetPlayerUI[Message.Player], TmpCanvas := Canvas?):
TmpPlayerUI.RemoveWidget(TmpCanvas)
set Canvas = false
OnButtonClickedB(Message:widget_message):void=
Print("ButtonB Clicked")
if (Button := text_button_base[Message.Source]):
Button.SetText("Message Received B")
OnButtonClickedC(Message:widget_message):void=
Print("ButtonC Clicked")
if (Button := text_button_base[Message.Source]):
Button.SetText("Message Received C")
# Test removing single widget in response to a click
if (TmpPlayerUI := GetPlayerUI[Message.Player]):
TmpPlayerUI.RemoveWidget(Message.Source)