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 hook to tap into window creation similar to EventLoopBuilder hook in eframe #2747

Closed
twop opened this issue Feb 18, 2023 · 3 comments · Fixed by #3390
Closed

Add hook to tap into window creation similar to EventLoopBuilder hook in eframe #2747

twop opened this issue Feb 18, 2023 · 3 comments · Fixed by #3390
Labels
feature New feature or request

Comments

@twop
Copy link
Contributor

twop commented Feb 18, 2023

Problem

I would love to customize appearance beyond what is available in eframe::NativeOptions (example below is on macOS).

Specifically I would love to achieve this look (top window, code snippet is taken from winit):
image

It is a combination of these winit settings:

    let event_loop = EventLoop::new();

    let window_1 = WindowBuilder::new()
        .with_titlebar_buttons_hidden(true)
        .with_title_hidden(true)
        .with_titlebar_transparent(true)
        .build(&event_loop);

Note that these methods are specific to macOS (defined in WindowBuilderExtMacOS).
The closest that eframe provides today is

 eframe::NativeOptions {
        fullsize_content: true,
        decorated: false
}

But it removes the ability to resize and "roundness" of the window.

Desired solution

I would love to to tap into WindowBuilder with a hook similar to EventLoopBuilder.
Something like that

let options = eframe::NativeOptions {
    // proposed API for window builder
    window_builder: Some(Box::new(|builder| {
        #[cfg(target_os = "macos")]
        {
            use winit::platform::macos::WindowBuilderExtMacOS;
            builder
                .with_titlebar_buttons_hidden(true)
                .with_title_hidden(true)
                .with_titlebar_transparent(true)
        }
    })),

    // existing hook for event loop
    event_loop_builder: Some(Box::new(|builder| {
        #[cfg(target_os = "macos")]
        {
            use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
            builder.with_activation_policy(ActivationPolicy::Accessory);
        }
    })),

    ..Default::default()
};

Alternative

Mimic winit window builder API in eframe::NativeOptions. It feels less desirable to me because

  1. There is already a precedent for EventLoop hook
  2. It seems that eframe::NativeOptions is mostly 1:1 to winit options, thus it feels repetitive.
  3. With little code in eframe this provides access to a lot of features, AND it is future proof, e.g. when winit adds features eframe gets these features for "free".

Happy to contribute the code

@twop twop added the feature New feature or request label Feb 18, 2023
@twop
Copy link
Contributor Author

twop commented Apr 28, 2023

I have a fork when it is implemented https://github.com/twop/egui/tree/focus-and-window-builder
Here is the gist:

image

and here is the usage of it

image

Should I submit a PR?

@bates64
Copy link

bates64 commented May 9, 2023

Should I submit a PR?

Placing my hat in the ring for this - yes!

This would be a breaking change because NativeOptions isn't marked exhaustive, the PR should probably mark it as such to make it non-breaking to add new options in the future.

@twop
Copy link
Contributor Author

twop commented Sep 26, 2023

created a PR just in case #3390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants