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

Starting an app with WindowState::Maximized doesn't work quite right on macOS #1690

Closed
JarrettBillingsley opened this issue Apr 1, 2021 · 2 comments
Labels
bug does not behave the way it is supposed to shell/mac concerns the macOS backend

Comments

@JarrettBillingsley
Copy link
Contributor

I'm on macOS 10.15.5 and using the git version of Druid (post-0.7.0).

After posting a topic and repro on Zulip, we discovered that this code properly creates a maximized window on Windows, but not on macOS. The issue is that the window is maximized, but the widget layout is not. It still thinks the window is like 400x300 pixels or something. If I then resize the window, the layout corrects itself.

use druid::*;
use druid::widget::*;

#[derive(Clone, Data, Lens)]
struct AppState {}

impl Default for AppState {
    fn default() -> Self {
        Self {}
    }
}

fn build_ui() -> impl Widget<AppState> {
    Split::columns(Label::new("Split A"), Label::new("Split B"))
    .split_point(0.5)
    .draggable(true)
    .solid_bar(true)
    .min_size(250.0, 600.0)
}

fn main() -> Result<(), PlatformError> {
    AppLauncher::with_window(
        WindowDesc::new(build_ui())
        .set_window_state(WindowState::Maximized)
    )
    .launch(AppState::default())
}

Screenshot of what it looks like:

image

@josh-audio josh-audio added bug does not behave the way it is supposed to shell/mac concerns the macOS backend labels Apr 1, 2021
@JarrettBillingsley
Copy link
Contributor Author

The problem is here:

if let Some(window_state) = self.window_state {
handle.set_window_state(window_state);
}
if let Some(level) = self.level {
handle.set_level(level)
}
(*view_state).handler.connect(&handle.clone().into());
(*view_state).handler.scale(Scale::default());
(*view_state)
.handler
.size(Size::new(frame.size.width, frame.size.height));

On line 290, it correctly calls set_window_state which maximizes the window. But then on line 299, it calls size using frame.size which is now out of sync with the real window size.

I added the first two lines - and sorry if this is absolutely the wrong way to do it, I'm not at all familiar with how mac OS windowing works - and it worked. The first layout call now sees the correct maximized window size.

            // set_window_state above could have invalidated the frame size
            let frame = NSView::frame(content_view);

            (*view_state).handler.connect(&handle.clone().into());
            (*view_state).handler.scale(Scale::default());
            (*view_state)
                .handler
                .size(Size::new(frame.size.width, frame.size.height));

@cmyr
Copy link
Member

cmyr commented Apr 2, 2021

yep this looks good to me, feel free to PR if you want!

JarrettBillingsley added a commit to JarrettBillingsley/druid that referenced this issue Apr 2, 2021
@cmyr cmyr closed this as completed in a211ad1 Apr 2, 2021
richard-uk1 pushed a commit to richard-uk1/druid that referenced this issue Apr 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug does not behave the way it is supposed to shell/mac concerns the macOS backend
Projects
None yet
Development

No branches or pull requests

3 participants