diff --git a/egui/src/layout.rs b/egui/src/layout.rs index ad674212..23c01797 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -506,21 +506,23 @@ impl Layout { let align; + let l = 64.0; + match self.main_dir { 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); } 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); } 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); } 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); } } diff --git a/egui/src/painter.rs b/egui/src/painter.rs index dd2372d0..f5e88783 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -152,18 +152,6 @@ impl Painter { self.galley(rect.min, galley, text_style, color::RED); 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 @@ -240,6 +228,18 @@ impl Painter { 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