thyme icon indicating copy to clipboard operation
thyme copied to clipboard

fix floating point layout issues

Open Grokmoo opened this issue 4 years ago • 3 comments

  • [ ] Widgets can sometimes be laid out at half pixel increments causing layout problems.

  • [ ] Font rendering can happen at half pixels causing bad looking text on non-hidpi displays.

  • [x] On a hidpi display, images using a scale_factor of 1 can show seams in some situations.

Grokmoo avatar Sep 29 '20 04:09 Grokmoo

I’ve gotten rid of the seams by rounding up/down the coordinates for ImageFill::Repeat in image.rs, starting at line 181:

                    }, ImageFill::Repeat => {
                        let size = [
                            f32::ceil(base_size[0] * params.scale),
                            f32::ceil(base_size[1] * params.scale),
                        ];
                        let mut y = params.pos[1];
                        loop {
                            let mut x = params.pos[0];
                            loop {
                                let pos = [
                                    f32::floor(x * params.scale),
                                    f32::floor(y * params.scale),
                                ];
                                self.draw_simple(
                                    draw_list,
                                    tex_coords,
                                    pos,
                                    size,
                                    clip,
                                );

                                x += base_size[0];
                                if x >= params.size[0] + params.pos[0] { break; }
                            }

                            y += base_size[1];
                            if y >= params.size[1] + params.pos[1] { break; }
                        }
                    }

Also, the 1-pixel borders in my theme improve by adding the following at the beginning of each of draw_simple(), draw_composed_horizontal(), draw_composed_vertical(), and draw_composed():

        let pos:  [f32; 2] = [f32::round( pos[0]), f32::round( pos[1])];
        let size: [f32; 2] = [f32::round(size[0]), f32::round(size[1])];

AlbertoGP avatar Oct 05 '20 21:10 AlbertoGP

Thanks, that is helpful. I would like to try to apply it in a more general way. Will spend some time on it soon.

Grokmoo avatar Oct 06 '20 04:10 Grokmoo

The Repeating seams is due to border sampling as noted in 38a94913aa7794e4640326eb794e1f6816936521. Should be fixed in the pixels theme.

Grokmoo avatar Oct 10 '20 00:10 Grokmoo