Skip to content

Incorrect translation in canvas component #1893

@brads55

Description

@brads55

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;

Metadata

Metadata

Assignees

Labels

bug 😔Something isn't working

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions