Skip to content

Commit

Permalink
fixed selected edges drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
blitzarx1 committed Nov 7, 2023
1 parent a53c617 commit c6062e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
36 changes: 27 additions & 9 deletions src/draw/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,23 @@ fn draw_edge_basic<N: Clone, E: Clone, Ty: EdgeType, Ix: IndexType>(
tip_end - e.tip_size() * state.meta.zoom * rotate_vector(dir, -e.tip_angle());

let shape = Shape::line_segment([edge_start, edge_end], stroke_edge);
l.add(shape);
match e.selected() {
true => l.add_top(shape),
false => l.add(shape),
}

// draw tips for directed edges
if state.g.is_directed() {
let shape_tip =
Shape::convex_polygon(vec![tip_end, tip_start_1, tip_start_2], color, stroke_tip);
l.add(shape_tip);
if !state.g.is_directed() {
return;
}

// draw tips for directed edges
let shape_tip =
Shape::convex_polygon(vec![tip_end, tip_start_1, tip_start_2], color, stroke_tip);
match e.selected() {
true => l.add_top(shape_tip),
false => l.add(shape_tip),
};

return;
}

Expand Down Expand Up @@ -113,11 +121,18 @@ fn draw_edge_basic<N: Clone, E: Clone, Ty: EdgeType, Ix: IndexType>(
Color32::TRANSPARENT,
stroke_edge,
);
l.add(shape_curved);

match e.selected() {
true => l.add_top(shape_curved),
false => l.add(shape_curved),
}

let shape_tip_curved =
Shape::convex_polygon(vec![tip_end, tip_start_1, tip_start_2], color, stroke_tip);
l.add(shape_tip_curved);
match e.selected() {
true => l.add_top(shape_tip_curved),
false => l.add(shape_tip_curved),
};
}

fn draw_edge_looped<N: Clone, E: Clone, Ty: EdgeType, Ix: IndexType>(
Expand Down Expand Up @@ -149,7 +164,10 @@ fn draw_edge_looped<N: Clone, E: Clone, Ty: EdgeType, Ix: IndexType>(
stroke,
);

l.add(shape);
match e.selected() {
true => l.add_top(shape),
false => l.add(shape),
}
}

/// rotates vector by angle
Expand Down
2 changes: 1 addition & 1 deletion src/elements/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<E: Clone> Edge<E> {

pub fn color(&self, ctx: &Context) -> Color32 {
if self.selected {
return ctx.style().visuals.widgets.active.fg_stroke.color;
return ctx.style().visuals.widgets.hovered.fg_stroke.color;
}

ctx.style()
Expand Down

0 comments on commit c6062e2

Please sign in to comment.