Added ability to set color of spinner (#2088)

This commit is contained in:
Caleb Leinz (he/him) 2022-10-01 06:18:44 -07:00 committed by GitHub
parent 2dca01ecd5
commit 5e91a3033d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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}; use crate::{Response, Sense, Ui, Widget};
@ -10,6 +10,7 @@ use crate::{Response, Sense, Ui, Widget};
pub struct Spinner { pub struct Spinner {
/// Uses the style's `interact_size` if `None`. /// Uses the style's `interact_size` if `None`.
size: Option<f32>, size: Option<f32>,
color: Option<Color32>,
} }
impl Spinner { impl Spinner {
@ -24,6 +25,12 @@ impl Spinner {
self.size = Some(size); self.size = Some(size);
self 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 { impl Widget for Spinner {
@ -31,6 +38,9 @@ impl Widget for Spinner {
let size = self let size = self
.size .size
.unwrap_or_else(|| ui.style().spacing.interact_size.y); .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()); let (rect, response) = ui.allocate_exact_size(vec2(size, size), Sense::hover());
if ui.is_rect_visible(rect) { if ui.is_rect_visible(rect) {
@ -47,10 +57,8 @@ impl Widget for Spinner {
rect.center() + radius * vec2(cos as f32, sin as f32) rect.center() + radius * vec2(cos as f32, sin as f32)
}) })
.collect(); .collect();
ui.painter().add(Shape::line( ui.painter()
points, .add(Shape::line(points, Stroke::new(3.0, color)));
Stroke::new(3.0, ui.visuals().strong_text_color()),
));
} }
response response