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

Allow closing animation to be displayed without showing egui::Window close button #4322

Open
Chaojimengnan opened this issue Apr 5, 2024 · 10 comments · May be fixed by #4323
Open

Allow closing animation to be displayed without showing egui::Window close button #4322

Chaojimengnan opened this issue Apr 5, 2024 · 10 comments · May be fixed by #4323

Comments

@Chaojimengnan
Copy link
Contributor

Chaojimengnan commented Apr 5, 2024

Is your feature request related to a problem? Please describe.

Normally we use if condition to control the opening and closing of windows directly, but in this case the window closing animation will not be shown, it will just close.

The closing animation is displayed properly only after we call egui::Window::open, but the window will have an additional close button. I would like to have control to not show this close button.

Describe the solution you'd like

Rename egui::Window::open to egui::Window::open_mut and add a new egui::Window::open that accepts non-mut reference.

In egui::Window::show_dyn the close button is shown or not depending on whether the reference is mut or non-mut

Describe alternatives you've considered

None

Additional context

None

@Chaojimengnan Chaojimengnan linked a pull request Apr 5, 2024 that will close this issue
@rustbasic
Copy link
Contributor

If you create it in the following form and change the is_open_window value, isn't this what you want?

            let mut is_open_window: bool = true;

            egui::Window::new("test")
            .open(&mut is_open_window)
            .show(ui.ctx(), |ui| {
                ui.label("test test test");
            });

Of course, this is an example, and is_open_window must maintain its value in an external variable or struct.

@Chaojimengnan
Copy link
Contributor Author

If you create it in the following form and change the is_open_window value, isn't this what you want?

            let mut is_open_window: bool = true;

            egui::Window::new("test")
            .open(&mut is_open_window)
            .show(ui.ctx(), |ui| {
                ui.label("test test test");
            });

Of course, this is an example, and is_open_window must maintain its value in an external variable or struct.

.open(&mut is_open_window) will show an extra close button in the window title bar, in my case I don't want the window to be able to be closed manually by the user.

@rustbasic
Copy link
Contributor

.open(&mut is_open_window) will show an extra close button in the window title bar, in my case I don't want the window to be able to be closed manually by the user.

If .open() is not set, the close button will not be created. Is this what you want?

             egui::Window::new("test")
             .show(ui.ctx(), |ui| {
                 ui.label("test test test");
             });

@Chaojimengnan
Copy link
Contributor Author

If .open() is not set, the close button will not be created. Is this what you want?

             egui::Window::new("test")
             .show(ui.ctx(), |ui| {
                 ui.label("test test test");
             });

Often we can just use the following code, as examples/confirm_exit does:

let mut is_open_window: bool = true;

if is_open_window {
    egui::Window::new("test")
    .show(ui.ctx(), |ui| {
        ui.label("test test test");
    });
}

But the above code will not show the window closing animation when the window is closed. So I would like to have a .open that doesn't create a close button in the window title bar.

@rustbasic
Copy link
Contributor

rustbasic commented Apr 7, 2024

But the above code will not show the window closing animation when the window is closed. So I would like to have a .open that doesn't create a close button in the window title bar.

I'm not sure what the difference is in closing animation.
However, I think it would be better to have a separate function to select close button.

Please apply #4334, and let us know the results.
I don't know if PR #4334 will be approved.

@Chaojimengnan
Copy link
Contributor Author

I'm not sure what the difference is in closing animation. However, I think it would be better to have a separate function to select close button.

Please apply #4334, and let us know the results. I don't know if PR #4334 will be approved.

Thanks for the PR, but I have one too, though it seems our PRs don't conflict.
I don't think the user should be allowed to control whether or not the close button is displayed, as it would conflict with .open.

@rustbasic
Copy link
Contributor

rustbasic commented Apr 7, 2024

Thanks for the PR, but I have one too, though it seems our PRs don't conflict. I don't think the user should be allowed to control whether or not the close button is displayed, as it would conflict with .open.

Because of 'clippy' and 'rust fmt', it is now complete.

This is can only turn on/off the close button,
It does not conflict with open() .

@Chaojimengnan
Copy link
Contributor Author

Because of 'clippy' and 'rust fmt', it is now complete.

This is can only turn on/off the close button, It does not conflict with open() .

Because open() requires a mut reference of type bool, and the close button is the only place where this mut reference is needed, if the user will not need the
close button, then the mut reference should not be passed into open(), but rather a value or immutable reference.

@rustbasic
Copy link
Contributor

#4334 turns on/off only the close button.
#4334 is does not conflict with open() .
The variables used in open() can be used the same as before.

@Chaojimengnan
Copy link
Contributor Author

Chaojimengnan commented Apr 8, 2024

#4334 turns on/off only the close button. #4334 is does not conflict with open() . The variables used in open() can be used the same as before.

Yes, but .open requires a mut reference to the variable, and the user will think that the variable might be changed by the window, but if the close button is turned off, the variable will never actually change, and you might want to note this in the closebutton documentation.

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 a pull request may close this issue.

2 participants