PistonDevelopers / conrod

An easy-to-use, 2D GUI library written entirely in Rust.
Other
3.35k stars 296 forks source link

Scrissor rect should be clamped #1447

Open andraantariksa opened 2 years ago

andraantariksa commented 2 years ago

I was following this example, but I always encounter an error about invalid scissor. I just found out the problem was the rect was overflowing the surface bound. I guess the example need to be updated so no one will stumble upon my same exact problem.

https://github.com/PistonDevelopers/conrod/blob/master/backends/conrod_wgpu/examples/all_winit_wgpu.rs#L247

more or less, it can be rewritten into

conrod_wgpu::RenderPassCommand::SetScissor {
    top_left: [x, y],
    dimensions: [w, h],
} => {
    render_pass.set_scissor_rect(x, y, w, h);
}

It should be clamped to the surface size

conrod_wgpu::RenderPassCommand::SetScissor {
    top_left: [x, y],
    dimensions: [mut w, mut h],
} => {
    if w + x > surface_config.surface.width { // Surface width
        w = surface_config.surface.width - x;
    }
    if h + y > surface_config.surface.height { // Surface height
        h = surface_config.surface.height - y;
    }
    render_pass.set_scissor_rect(x, y, w, h);
}