Skip to content

Widgets with stroked outlines draw outside their bounds #628

@cmyr

Description

@cmyr

The stroke method on our drawing context draws the stroke centered on the path; if the path it is passed is equal to the layout bounds, half of the stroke will be outside of those bounds.

This means that any widget that draws a stroke and does not account for this will end up drawing outside of its layout bounds.

This is illustrated well by the flex example program, from which I've taken the following zoomed screenshots:
Screen Shot 2020-03-10 at 10 27 34 AM
Screen Shot 2020-03-10 at 10 28 03 AM
Screen Shot 2020-03-10 at 10 28 45 AM

The solution to this is fairly simple; we should inset our layout size before painting, increasing the layout size if necessary. When dealing with a Rect this is as easy as,

let layout_rect = Rect::ZERO.with_size(paint_ctx.size());
let paint_rect = layout_rect - Insets::uniform(my_stroke_width / 2.0);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementadds or requests a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions