Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Painter method for line is missing #5273

Open
Resonanz opened this issue Oct 16, 2024 · 2 comments
Open

Painter method for line is missing #5273

Resonanz opened this issue Oct 16, 2024 · 2 comments
Labels
bug Something is broken egui good first issue Good for newcomers

Comments

@Resonanz
Copy link

Error[E0599] no method named `line` found for reference `&egui::Painter` in the current scope

https://docs.rs/egui/latest/egui/enum.Shape.html#method.line

/// A line through many points.
pub fn line(points: Vec<Pos2>, stroke: impl Into<PathStroke>) -> Self

To Reproduce

let mut vec = Vec::new();
vec.push(Pos2 {x: 0., y: 0.});
vec.push(Pos2 {x: 10., y: 50.});

ui.painter().line(vec, (3., Color32::YELLOW));

There are no problem using line_segment rather than ```line'''.

Desktop (please complete the following information):

  • OS: Ubuntu
  • Version 24.04
@Resonanz Resonanz added the bug Something is broken label Oct 16, 2024
@lucasmerlin
Copy link
Collaborator

The method you linked is on the Shape struct, not the Painter. You should be able to do painter.add(Shape::line(...)). But it would make sense to add a Painter::line function as well 👍🏻

@lucasmerlin lucasmerlin added good first issue Good for newcomers egui labels Oct 16, 2024
@Resonanz
Copy link
Author

Thanks, you are right, that worked:

let mut v = Vec::new();
v.push(Pos2 {
    x: locx + 0.,
    y: locy + 0.,
});
v.push(Pos2 {
    x: locx + 70.,
    y: locy + 0.,
});
v.push(Pos2 {
    x: locx + 70.,
    y: locy + 70.,
});
v.push(Pos2 {
    x: locx + 0.,
    y: locy + 70.,
});
v.push(Pos2 {
    x: locx + 0.,
    y: locy + 0.,
});

ui.painter().add(Shape::line(v, (1., Color32::LIGHT_BLUE)));

This is also how it is done in the Spinner widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken egui good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants