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 NativeOptions::window_builder for more customization #3390

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

twop
Copy link
Contributor

@twop twop commented Sep 26, 2023

Closes #2747

  • this PR is my attempt to tap into winit options to style the window
  • I'm building an app that behaves akin to macOS spotlight, e.g. no standard controls to minimize or close the window

here is the snippet from my app code base

 let options = eframe::NativeOptions {
        resizable: true,
        always_on_top: true,
        run_and_return: true,
        window_builder: Some(Box::new(|builder| {
            #[cfg(target_os = "macos")]
            use winit::platform::macos::WindowBuilderExtMacOS;
            // code below allows for richer customization
            #[cfg(target_os = "macos")]
            return builder
                .with_fullsize_content_view(true)
                .with_titlebar_buttons_hidden(true)
                .with_title_hidden(true)
                .with_titlebar_transparent(true);

            builder
        })),
        ..Default::default()
    };

So that makes it possible to create completely custom look and feel
image

Happy to rework if needed, maintaining a fork is a pain ^_^

Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

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

Very good idea

crates/eframe/src/epi/mod.rs Outdated Show resolved Hide resolved
@@ -75,7 +75,7 @@ pub fn read_window_info(
pub fn window_builder<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
native_options: &epi::NativeOptions,
native_options: &mut epi::NativeOptions,
Copy link
Owner

@emilk emilk Sep 27, 2023

Choose a reason for hiding this comment

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

Adding mut everywhere is quite ugly.

This can be fixed by using Rc<dyn Fn(…)> as the callback type, instead of just Box. That will also allow cloning.

…but we won't get to use FnOnce, which is a shame

@emilk emilk added the eframe Relates to epi and eframe label Sep 27, 2023
@emilk emilk changed the title added a window builder hook for more customization Add NativeOptions::window_builder for more customization Sep 27, 2023
@emilk emilk merged commit 4986b35 into emilk:master Sep 27, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add hook to tap into window creation similar to EventLoopBuilder hook in eframe
2 participants