mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Add Shape::hline and Shape::vline
This commit is contained in:
@@ -2,7 +2,7 @@ use std::ops::RangeInclusive;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
emath::{pos2, Align2, Pos2, Rect, Vec2},
|
emath::{Align2, Pos2, Rect, Vec2},
|
||||||
layers::{LayerId, PaintList, ShapeIdx},
|
layers::{LayerId, PaintList, ShapeIdx},
|
||||||
Color32, Context, FontId,
|
Color32, Context, FontId,
|
||||||
};
|
};
|
||||||
@@ -257,18 +257,12 @@ impl Painter {
|
|||||||
|
|
||||||
/// Paints a horizontal line.
|
/// Paints a horizontal line.
|
||||||
pub fn hline(&self, x: RangeInclusive<f32>, y: f32, stroke: impl Into<Stroke>) {
|
pub fn hline(&self, x: RangeInclusive<f32>, y: f32, stroke: impl Into<Stroke>) {
|
||||||
self.add(Shape::LineSegment {
|
self.add(Shape::hline(x, y, stroke));
|
||||||
points: [pos2(*x.start(), y), pos2(*x.end(), y)],
|
|
||||||
stroke: stroke.into(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Paints a vertical line.
|
/// Paints a vertical line.
|
||||||
pub fn vline(&self, x: f32, y: RangeInclusive<f32>, stroke: impl Into<Stroke>) {
|
pub fn vline(&self, x: f32, y: RangeInclusive<f32>, stroke: impl Into<Stroke>) {
|
||||||
self.add(Shape::LineSegment {
|
self.add(Shape::vline(x, y, stroke));
|
||||||
points: [pos2(x, *y.start()), pos2(x, *y.end())],
|
|
||||||
stroke: stroke.into(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn circle(
|
pub fn circle(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
//! The different shapes that can be painted.
|
//! The different shapes that can be painted.
|
||||||
|
|
||||||
|
use std::ops::RangeInclusive;
|
||||||
use std::{any::Any, sync::Arc};
|
use std::{any::Any, sync::Arc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@@ -72,6 +73,22 @@ impl Shape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A horizontal line.
|
||||||
|
pub fn hline(x: RangeInclusive<f32>, y: f32, stroke: impl Into<Stroke>) -> Self {
|
||||||
|
Shape::LineSegment {
|
||||||
|
points: [pos2(*x.start(), y), pos2(*x.end(), y)],
|
||||||
|
stroke: stroke.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A vertical line.
|
||||||
|
pub fn vline(x: f32, y: RangeInclusive<f32>, stroke: impl Into<Stroke>) -> Self {
|
||||||
|
Shape::LineSegment {
|
||||||
|
points: [pos2(x, *y.start()), pos2(x, *y.end())],
|
||||||
|
stroke: stroke.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A line through many points.
|
/// A line through many points.
|
||||||
///
|
///
|
||||||
/// Use [`Self::line_segment`] instead if your line only connects two points.
|
/// Use [`Self::line_segment`] instead if your line only connects two points.
|
||||||
|
|||||||
Reference in New Issue
Block a user