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

Extra white line is rendered below menu bar on Windows #123

Closed
rhysd opened this issue Sep 15, 2023 · 1 comment · Fixed by #126
Closed

Extra white line is rendered below menu bar on Windows #123

rhysd opened this issue Sep 15, 2023 · 1 comment · Fixed by #126

Comments

@rhysd
Copy link
Contributor

rhysd commented Sep 15, 2023

Repro

At first, enable dark theme by visiting the system colors settings.

https://www.pcmag.com/how-to/how-to-enable-dark-mode-in-windows-10

Then save the following Rust code and run it.

use muda::{Menu, MenuEvent, PredefinedMenuItem, Submenu};
use wry::application::platform::windows::{EventLoopBuilderExtWindows, WindowExtWindows};
use wry::application::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoopBuilder},
    window::WindowBuilder,
};
use wry::webview::WebViewBuilder;

fn main() -> wry::Result<()> {
    let mut event_loop_builder = EventLoopBuilder::new();

    let menu_bar = Menu::new();

    {
        let menu_bar = menu_bar.clone();
        event_loop_builder.with_msg_hook(move |msg| {
            use windows_sys::Win32::UI::WindowsAndMessaging::{TranslateAcceleratorW, MSG};
            unsafe {
                let msg = msg as *const MSG;
                let translated = TranslateAcceleratorW((*msg).hwnd, menu_bar.haccel(), msg);
                translated == 1
            }
        });
    }

    let event_loop = event_loop_builder.build();

    let window = WindowBuilder::new()
        .with_title("Window 1")
        .build(&event_loop)
        .unwrap();

    let file_m = Submenu::new("&File", true);

    menu_bar.append(&file_m).unwrap();

    file_m
        .append_items(&[
            &PredefinedMenuItem::copy(None),
            &PredefinedMenuItem::cut(None),
            &PredefinedMenuItem::paste(None),
        ])
        .unwrap();

    menu_bar.init_for_hwnd(window.hwnd() as _).unwrap();

    let _webview = WebViewBuilder::new(window)?
        .with_html(
            r#"
            <html>
                <head>
                    <style>
                    html {
                        background-color: black;
                    }
                    </style>
                </head>
                <body></body>
            </html>
            "#,
        )?
        .build()?;

    let menu_channel = MenuEvent::receiver();

    event_loop.run(move |event, _, control_flow| {
        *control_flow = ControlFlow::Wait;

        if let Event::WindowEvent {
            event: WindowEvent::CloseRequested,
            ..
        } = event
        {
            *control_flow = ControlFlow::Exit;
        }

        if let Ok(event) = menu_channel.try_recv() {
            println!("{event:?}");
        }
    })
}

On my machine, the following window showed up:

image

The white line was rendered below the menu bar.

Expected behavior

No extra white line is rendered.

Environment

  • muda: f3b7d54
  • Rust: 1.72.0
  • OS: Windows 10

Note

When removing the menu bar, the white line was no longer rendered as follows.

image

@amrbashir amrbashir linked a pull request Sep 20, 2023 that will close this issue
@rhysd
Copy link
Contributor Author

rhysd commented Sep 21, 2023

Thank you for fixing this quickly.

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.

1 participant