f67d38b35cc5
theme_favorites.rs
//! Original theme favorite star artwork, MIT OR Apache-2.0.
/// Draw the 22×22 favorite star button: visibility flag, favorite accent, accessible label and original vector artwork.
pub(crate) fn star(ui: &mut egui::Ui, favorite: bool, visible: bool, accent: egui::Color32, label: &str) -> egui::Response {
let (rect, response) = ui.allocate_exact_size(egui::vec2(22.0, 22.0), egui::Sense::click());
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label));
if visible {
let color = if favorite { accent } else { ui.visuals().weak_text_color() };
let center = rect.center();
let points: Vec<_> = (0..10)
.map(|i| {
let angle = -std::f32::consts::FRAC_PI_2 + i as f32 * std::f32::consts::PI / 5.0;
center + egui::vec2(angle.cos(), angle.sin()) * if i % 2 == 0 { 7.0 } else { 3.0 }
})
.collect();
if favorite {
for (a, b) in points.iter().zip(points.iter().cycle().skip(1)).take(10) {
ui.painter().add(egui::Shape::convex_polygon(vec![center, *a, *b], color, egui::Stroke::NONE));
}
} else {
ui.painter().add(egui::Shape::closed_line(points, egui::Stroke::new(1.2, color)));
}
}
response.on_hover_text(label)
}
No file is open. Choose one in the tree, or press Ctrl+O (⌘O on a Mac) to find one by name.
Syntax highlighting could not load. The unmodified read-only text remains available above.