Skip to content

Commit

Permalink
Added ability to set color of spinner (#2088)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmleinz committed Oct 1, 2022
1 parent 2dca01e commit 5e91a30
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/egui/src/widgets/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use epaint::{emath::lerp, vec2, Pos2, Shape, Stroke};
use epaint::{emath::lerp, vec2, Color32, Pos2, Shape, Stroke};

use crate::{Response, Sense, Ui, Widget};

Expand All @@ -10,6 +10,7 @@ use crate::{Response, Sense, Ui, Widget};
pub struct Spinner {
/// Uses the style's `interact_size` if `None`.
size: Option<f32>,
color: Option<Color32>,
}

impl Spinner {
Expand All @@ -24,13 +25,22 @@ impl Spinner {
self.size = Some(size);
self
}

/// Sets the spinner's color.
pub fn color(mut self, color: impl Into<Color32>) -> Self {
self.color = Some(color.into());
self
}
}

impl Widget for Spinner {
fn ui(self, ui: &mut Ui) -> Response {
let size = self
.size
.unwrap_or_else(|| ui.style().spacing.interact_size.y);
let color = self
.color
.unwrap_or_else(|| ui.visuals().strong_text_color());
let (rect, response) = ui.allocate_exact_size(vec2(size, size), Sense::hover());

if ui.is_rect_visible(rect) {
Expand All @@ -47,10 +57,8 @@ impl Widget for Spinner {
rect.center() + radius * vec2(cos as f32, sin as f32)
})
.collect();
ui.painter().add(Shape::line(
points,
Stroke::new(3.0, ui.visuals().strong_text_color()),
));
ui.painter()
.add(Shape::line(points, Stroke::new(3.0, color)));
}

response
Expand Down

0 comments on commit 5e91a30

Please sign in to comment.