Rename Painter::debug_arrow to Painter::arrow

This commit is contained in:
Emil Ernerfeldt 2020-12-25 12:27:16 +01:00
parent 36c15c4e41
commit d3eba239ed
2 changed files with 18 additions and 16 deletions

View File

@ -506,21 +506,23 @@ impl Layout {
let align; let align;
let l = 64.0;
match self.main_dir { match self.main_dir {
Direction::LeftToRight => { Direction::LeftToRight => {
painter.debug_arrow(cursor, vec2(1.0, 0.0), stroke); painter.arrow(cursor, vec2(l, 0.0), stroke);
align = (Align::Min, Align::Min); align = (Align::Min, Align::Min);
} }
Direction::RightToLeft => { Direction::RightToLeft => {
painter.debug_arrow(cursor, vec2(-1.0, 0.0), stroke); painter.arrow(cursor, vec2(-l, 0.0), stroke);
align = (Align::Max, Align::Min); align = (Align::Max, Align::Min);
} }
Direction::TopDown => { Direction::TopDown => {
painter.debug_arrow(cursor, vec2(0.0, 1.0), stroke); painter.arrow(cursor, vec2(0.0, l), stroke);
align = (Align::Min, Align::Min); align = (Align::Min, Align::Min);
} }
Direction::BottomUp => { Direction::BottomUp => {
painter.debug_arrow(cursor, vec2(0.0, -1.0), stroke); painter.arrow(cursor, vec2(0.0, -l), stroke);
align = (Align::Min, Align::Max); align = (Align::Min, Align::Max);
} }
} }

View File

@ -152,18 +152,6 @@ impl Painter {
self.galley(rect.min, galley, text_style, color::RED); self.galley(rect.min, galley, text_style, color::RED);
frame_rect frame_rect
} }
pub fn debug_arrow(&self, origin: Pos2, dir: Vec2, stroke: Stroke) {
use crate::math::*;
let full_length = dir.length().at_least(64.0);
let tip_length = full_length / 3.0;
let dir = dir.normalized();
let tip = origin + dir * full_length;
let rot = Rot2::from_angle(TAU / 10.0);
self.line_segment([origin, tip], stroke);
self.line_segment([tip, tip - tip_length * (rot * dir)], stroke);
self.line_segment([tip, tip - tip_length * (rot.inverse() * dir)], stroke);
}
} }
/// # Paint different primitives /// # Paint different primitives
@ -240,6 +228,18 @@ impl Painter {
stroke: stroke.into(), stroke: stroke.into(),
}); });
} }
/// Show an arrow starting at `origin` and going in the direction of `vec`, with the length `vec.length()`.
pub fn arrow(&self, origin: Pos2, vec: Vec2, stroke: Stroke) {
use crate::math::*;
let rot = Rot2::from_angle(TAU / 10.0);
let tip_length = vec.length() / 4.0;
let tip = origin + vec;
let dir = vec.normalized();
self.line_segment([origin, tip], stroke);
self.line_segment([tip, tip - tip_length * (rot * dir)], stroke);
self.line_segment([tip, tip - tip_length * (rot.inverse() * dir)], stroke);
}
} }
/// ## Text /// ## Text