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

Add the possibility to register global input handlers #175

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

miroiu
Copy link
Owner

@miroiu miroiu commented Dec 12, 2024

📝 Description of the Change

Adds the possibility to register global input handlers via InputProcessor.Shared<T>. Once the desired input handlers are registered, an instance of the shared handler must be added to the InputProcessor instance of a UI element.

Example:

static MainWindow()
{
    // register a handler factory in a static context
    InputProcessor.Shared<Connector>.RegisterHandlerFactory(elem => new ConnectorState.Connecting(elem));

    // removes the handler factory for the specified handler type
    InputProcessor.Shared<Connector>.RemoveHandlerFactory<ConnectorState.Connecting>();
}

public Connector()
{
    // use shared handlers for this connector
    InputProcessor.AddSharedHandlers(this);
}

The handlers are only constructed once per element, when creating an instance of the shared class (e.g. new InputProcessor.Shared<Connector>(this) or using the InputProcessor.AddSharedHandlers extension method).

Important

Calling InputProcessor.Shared.RegisterHandlerFactory will not add new handlers to existing shared instances.

Methods:

  • RegisterHandlerFactory
  • RemoveHandlerFactory
  • ClearHandlerFactories

Related #146

🐛 Possible Drawbacks

None.

@miroiu miroiu merged commit c8da71c into master Dec 13, 2024
4 checks passed
@miroiu miroiu deleted the feature/146-global-input-handlers branch December 13, 2024 18:04
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.

1 participant