Intent
The Intent type represents what should happen when a button in the user interface is clicked. The most common type of intent is the PressIntent, but you can also use them to navigate to a different Page, start a new Game, and many other things.
pub page fn owner.MyCoolPage() {
Content {
P { "Hello, world!" }
}
}
pub game fn World.Main() {
// fun game code goes here
}
pub fn DisplaySomeButtons([ui]) {
// Calling a page fn just returns an intent to navigate to that function
Button(MyCoolPage) { "Go to cool page" }
// Calling a game fn just returns an intent to enter the game
Button(Main) { "Play cool game" }
}
String Intents
If a String is used as an Intent, the String will be interpreted as a URL.
When clicked, the Button
will open a new tab with that URL.
Link("https://discord.gg/EJfzutBSz8") {
"Join our community on Discord! "
Icon("fab fa-discord")
}
Keycode Intents
If a Keycode is used as an Intent,
when clicked the Button
will simulate a press of that keycode.
The ButtonDown event will trigger when the button goes down,
and the ButtonUp event will trigger when the button goes up.
This can be a good way to provide alternative inputs for touchscreen users who do not have access to a keyboard or mouse:
with TouchscreenMode {
if TouchscreenMode {
BottomRightContent {
HStack {
Pip(KeySpacebar, borderRounding=true, backgroundColor=#bb00ff, shadow=0.5) {
Image(@shipFire.svg, height=6)
}
Pip(Click, borderRounding=true, backgroundColor=#ff8800, shadow=0.5) {
Image(@shipThrust.svg, height=6)
}
}
}
}
}