Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus Events #578

Merged
merged 5 commits into from
Jul 26, 2023
Merged

Focus Events #578

merged 5 commits into from
Jul 26, 2023

Conversation

hobnob
Copy link
Member

@hobnob hobnob commented Jul 19, 2023

This PR adds 4 new events to Indigo:

  • ApplicationGainedFocus
  • ApplicationLostFocus
  • CanvasGainedFocus
  • CanvasLostFocus

These new events close #513 and fire whenever the application or game canvas gain or lose focus. This can be useful for things like pausing a game whenever the user switches tabs, or taking an action if the user clicks off of the game canvas inside a web app

There's no point preventing the default from occurring here. Any web
app trying to listen to these events will just be frustrated by it
davesmith00000
davesmith00000 previously approved these changes Jul 20, 2023
Copy link
Member

@davesmith00000 davesmith00000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great - I've approved but please don't forget to add the package aliases to your new events. Same goes for your other PRs. 👍

target match {
case e: dom.Element if e.tagName == "WINDOW" => true
case _ => false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cute. 😄

of the application if the game is being run from inside a web application (such as
a Tyrian App or game site). In this scenario the `Canvas*` events will fire whenever
the canvas loses or gains focus from the user clicking around the external parts
of the site, and will also fire when the application loses or gains focus.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, just beware the docs are in flux...


/** The game canvas has lost focus
*/
case object CanvasLostFocus extends GlobalEvent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't forget to add aliases to the package.scala file to help people import these:

val FrameTick: shared.events.FrameTick.type = shared.events.FrameTick

@davesmith00000 davesmith00000 merged commit 91c75f3 into main Jul 26, 2023
@davesmith00000 davesmith00000 deleted the features/focusEvents branch July 26, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a blur and focus event
2 participants