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

Create a Reusable on_click Event Handler #867

Open
namse opened this issue Jun 22, 2024 · 0 comments
Open

Create a Reusable on_click Event Handler #867

namse opened this issue Jun 22, 2024 · 0 comments
Labels
namui This issue is for namui engine

Comments

@namse
Copy link
Contributor

namse commented Jun 22, 2024

We frequently use on_click event handlers in our code, so it would be beneficial to create a reusable function to simplify this process. Instead of writing the following code each time:

.attach_event(|event| {
    if let Event::MouseUp { event } = event {
        if event.is_local_xy_in()
            && event.button == Some(MouseButton::Left)
        {
            on_select_team(&team.id);
        }
    }
});

We should be able to write it in a more concise manner like this:

.on_click(|_event: MouseEvent| {
    on_select_team(&team.id);
});

This would make the code cleaner and more maintainable.

@namse namse added the namui This issue is for namui engine label Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
namui This issue is for namui engine
Projects
None yet
Development

No branches or pull requests

1 participant