The canvas component does a translation of visible_area().min() to place the drawn elements relative to the component position, however it does this after the canvas has been scaled with the scale factor, which means for scale factors != 1.0 the translation is incorrect. The translation amount should also take into account the scale factor, or happen before the scaling does.
|
context |
|
.canvas |
|
.scale((context.scale_factor as f32, context.scale_factor as f32)); |
|
context.canvas.translate((area.min_x(), area.min_y())); |
Also it might be helpful if examples/feature_canvas.rs made it clear that the drawing being done will be scaled after being drawn, for example by doing something such as:
let area = context.layout_node.visible_area() / ctx.scale_factor as f32;
in place of:
|
canvas(RenderCallback::new(|context| { |
|
let area = context.layout_node.visible_area(); |
|
let center_x = area.center().x; |
The canvas component does a translation of
visible_area().min()to place the drawn elements relative to the component position, however it does this after the canvas has been scaled with the scale factor, which means for scale factors != 1.0 the translation is incorrect. The translation amount should also take into account the scale factor, or happen before the scaling does.freya/crates/freya-components/src/canvas.rs
Lines 151 to 154 in cde94c1
Also it might be helpful if
examples/feature_canvas.rsmade it clear that the drawing being done will be scaled after being drawn, for example by doing something such as:let area = context.layout_node.visible_area() / ctx.scale_factor as f32;in place of:
freya/examples/feature_canvas.rs
Lines 16 to 18 in cde94c1