mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
GL backend: Fix round corner clip radius
Rendering tests/cases/examples/rectangle_clip.60 shows a border radius for the clipped area that's not identical with the border radius of the inner edge of the rectangle stroke. It appears that the stroke's inner radius is not exactly the difference of the line (border) width but rather scaled by kappa.
This commit is contained in:
parent
0bb61cc1b3
commit
1ef1e79b93
1 changed files with 8 additions and 2 deletions
|
@ -46,6 +46,8 @@ type CanvasRc = Rc<RefCell<femtovg::Canvas<femtovg::renderer::OpenGl>>>;
|
||||||
pub const DEFAULT_FONT_SIZE: f32 = 12.;
|
pub const DEFAULT_FONT_SIZE: f32 = 12.;
|
||||||
pub const DEFAULT_FONT_WEIGHT: i32 = 400; // CSS normal
|
pub const DEFAULT_FONT_WEIGHT: i32 = 400; // CSS normal
|
||||||
|
|
||||||
|
const KAPPA90: f32 = 0.5522847493;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Debug)]
|
#[derive(PartialEq, Eq, Hash, Debug)]
|
||||||
enum ImageCacheKey {
|
enum ImageCacheKey {
|
||||||
Path(String),
|
Path(String),
|
||||||
|
@ -1075,8 +1077,12 @@ impl ItemRenderer for GLItemRenderer {
|
||||||
// adjust_rect_and_border_for_inner_drawing adjusts the rect so that for drawing it
|
// adjust_rect_and_border_for_inner_drawing adjusts the rect so that for drawing it
|
||||||
// would be entirely an *inner* border. However for clipping we want the rect that's
|
// would be entirely an *inner* border. However for clipping we want the rect that's
|
||||||
// entirely inside, hence the doubling of the width and consequently radius adjustment.
|
// entirely inside, hence the doubling of the width and consequently radius adjustment.
|
||||||
border_width *= self.scale_factor * 2.;
|
radius -= border_width * KAPPA90;
|
||||||
radius *= self.scale_factor * 0.75;
|
border_width *= 2.;
|
||||||
|
|
||||||
|
// Convert from logical to physical pixels
|
||||||
|
border_width *= self.scale_factor;
|
||||||
|
radius *= self.scale_factor;
|
||||||
clip_rect *= self.scale_factor;
|
clip_rect *= self.scale_factor;
|
||||||
|
|
||||||
adjust_rect_and_border_for_inner_drawing(&mut clip_rect, &mut border_width);
|
adjust_rect_and_border_for_inner_drawing(&mut clip_rect, &mut border_width);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue