mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 07:23:13 -04:00
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use crate::{Color32, Pos2, Rect, Shape, Stroke, Vec2};
|
|
|
|
/// How to paint a circle.
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
|
pub struct CircleShape {
|
|
pub center: Pos2,
|
|
pub radius: f32,
|
|
pub fill: Color32,
|
|
pub stroke: Stroke,
|
|
}
|
|
|
|
impl CircleShape {
|
|
#[inline]
|
|
pub fn filled(center: Pos2, radius: f32, fill_color: impl Into<Color32>) -> Self {
|
|
Self {
|
|
center,
|
|
radius,
|
|
fill: fill_color.into(),
|
|
stroke: Default::default(),
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn stroke(center: Pos2, radius: f32, stroke: impl Into<Stroke>) -> Self {
|
|
Self {
|
|
center,
|
|
radius,
|
|
fill: Default::default(),
|
|
stroke: stroke.into(),
|
|
}
|
|
}
|
|
|
|
/// The visual bounding rectangle (includes stroke width)
|
|
pub fn visual_bounding_rect(&self) -> Rect {
|
|
if self.fill == Color32::TRANSPARENT && self.stroke.is_empty() {
|
|
Rect::NOTHING
|
|
} else {
|
|
Rect::from_center_size(
|
|
self.center,
|
|
Vec2::splat(self.radius * 2.0 + self.stroke.width),
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<CircleShape> for Shape {
|
|
#[inline(always)]
|
|
fn from(shape: CircleShape) -> Self {
|
|
Self::Circle(shape)
|
|
}
|
|
}
|