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

Widgets centered on first frame #655

Closed
bvssvni opened this issue Dec 22, 2015 · 7 comments · Fixed by #656
Closed

Widgets centered on first frame #655

bvssvni opened this issue Dec 22, 2015 · 7 comments · Fixed by #656
Labels

Comments

@bvssvni
Copy link
Member

bvssvni commented Dec 22, 2015

In Turbine, when starting the application the widgets seems to be centered at the first frame, and then corrected at later frames.

Code:

        if !capture_cursor {
            use conrod::*;

            ui.handle_event(&e);
            e.update(|_| ui.set_widgets(|ui| {
                Button::new()
                    .color(color::blue())
                    .top_left()
                    .w_h(60.0, 30.0)
                    .label("refresh")
                    .react(|| {})
                    .set(REFRESH, ui);
            }));
            e.draw_2d(|c, g| {
                ui.draw(c, g);
            });
        }
@bvssvni bvssvni added the bug label Dec 22, 2015
@bvssvni
Copy link
Member Author

bvssvni commented Dec 22, 2015

I tested with rendering 20 buttons, and the effect was more visible.

Believe I saw this once in one of the Conrod examples, but the effect is harder to notice here since the window is appearing in the same moment. In Turbine, you notice it when pressing C after the window has loaded.

@bvssvni
Copy link
Member Author

bvssvni commented Dec 22, 2015

Printing out rectangle and color in draw_from_container:

        primitive::shape::framed_rectangle::KIND => {
            if let Some(framed_rectangle) = container.unique_widget_state::<::FramedRectangle>() {
                let frame = framed_rectangle.style.get_frame(theme);
                if frame > 0.0 {
                    let frame_color = framed_rectangle.style.get_frame_color(theme);
                    let frame_rect = container.rect;
                    draw_rectangle(context, graphics, frame_rect, frame_color);
                }
                let color = framed_rectangle.style.get_color(theme);
                let rect = container.rect.pad(frame);

                static mut i: u32 = 0;
                println!("{:?}", rect);
                println!("{:?}", color);
                unsafe { i += 1; if i > 5 { panic!(""); } }
                draw_rectangle(context, graphics, rect, color);
            }
        },

Getting:

Rect { x: Range { start: 0, end: 0 }, y: Range { start: 0, end: 0 } }
Rgba(0, 0, 0, 0)
Rect { x: Range { start: 1, end: 59 }, y: Range { start: -29, end: -1 } }
Rgba(0.28509036, 0.41999847, 0.66608846, 1)
Rect { x: Range { start: -512, end: 512 }, y: Range { start: -384, end: 384 } }
Rgba(0, 0, 0, 0)
Rect { x: Range { start: -511, end: -453 }, y: Range { start: 355, end: 383 } }
Rgba(0.20392157, 0.39607844, 0.6431373, 1)
Rect { x: Range { start: -512, end: 512 }, y: Range { start: -384, end: 384 } }
Rgba(0, 0, 0, 0)
Rect { x: Range { start: -511, end: -453 }, y: Range { start: 355, end: 383 } }
Rgba(0.20392157, 0.39607844, 0.6431373, 1)
thread '<main>' panicked at '', /Users/sven/rust/conrod/./src/backend/graphics.rs:206

@bvssvni
Copy link
Member Author

bvssvni commented Dec 22, 2015

This draws one blue rectangle on top of a black rectangle. I printed out first context.transform to see if the matrix was wrong, but it was the same. Seems to be the rectangle that is calculated wrong first time.

@mitchmindtree
Copy link
Contributor

Hmmm strange! Thanks for the details, will have a look into it now.

@bvssvni
Copy link
Member Author

bvssvni commented Dec 26, 2015

Tested with cargo run --example hello_world in Turbine. Still the same problem.

@bvssvni bvssvni reopened this Dec 26, 2015
@mitchmindtree
Copy link
Contributor

I did test a few times and thought it was no longer occurring, however after testing again a few times I did just notice it.

My hypothesis:

The way turbine currently captures the cursor is by only passing any events to conrod when the cursor is not captured by turbine - this means that conrod doesn't get any window size information until the first time conrod gets a draw event while the cursor isn't captured by turbine. This results in the Button being placed on a Window of size (0.0, 0.0) for the first frame that the Ui is drawn (and thus, placed in the centre of the screen). This isn't technically a bug in conrod as it is designed to be passed all events on all occurrences, but it shows that this behaviour is non-obvious and it highlights the importance of addressing #613 so that there is a proper API for external capturing of input.

In the mean-time, this could be fixed by only blocking mouse events (rather than all events) from conrod while turbine captures the mouse, rather than blocking all events as is currently the case. i.e. something like

if !(capture_cursor && e.is_mouse_event()) {
    ui.handle_event(e);
}

I'll leave this open for you to close once you can confirm that this fixes the issue on your end.

@bvssvni
Copy link
Member Author

bvssvni commented Dec 27, 2015

I'm sending just the render events, since the other events that Conrod handles should be ignored when not active. See PistonDevelopers/turbine#42

@bvssvni bvssvni closed this as completed Dec 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants