Events and Input
Panel Events & Input
Events
Panels can listen for events, here's the current list:
Event | Description |
---|---|
onclick | Called when left clicking on a panel |
onmiddleclick | Called when middle clicking on a panel |
onrightclick | Called when right clicking on a panel |
onmousedown | Called when any mouse button is pressed this frame |
onmouseup | Called when any mouse button is released this frame |
ondoubleclick | Called when a panel is double clicked on |
onmousemove | Called every frame where your mouse is moving inside of a panel |
onmouseover | Called when your mouse enters the bounds of a panel |
onmouseout | Called when your mouse exits the bounds of a panel |
onfocus | Called when the panel comes into focus |
onblur | Called when the panel loses focus |
onback | Called when you click the Back button on your mouse |
onforward | Called when you click the Forward button on your mouse |
onescape | Called when the escape key is pressed, also Blur() if focused |
Warning: You may have to disable pointer events on overlapping transparent GUI elements for events to trigger!
Bug: There's no guarantee that onmouseover and onmouseout events will be triggered in the correct order; if that matters to you then you're better off not relying on it.
Usage
Or you can use these events in .razor files
Assume in the above example that there is a function OnClick
in the razor class. You can learn more about this usage here https://wiki.facepunch.com/sbox/ui-razor#events
Class Overrides
All panels have these available virtual methods for you to override, if you choose not to use events.
Adding a text entry
This is an example of the usage of the Add.TextEntry(string name)
.
Source: base gamemode - /code/UI/Chat.cs