emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.52k stars 1.61k forks source link

Painter method for line is missing #5273

Open Resonanz opened 1 month ago

Resonanz commented 1 month ago
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):

lucasmerlin commented 1 month ago

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 👍🏻

Resonanz commented 1 month ago

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.