egui_charts/ui_kit/loading/mod.rs
1//! Loading indicator component: a spinner with an optional message.
2//!
3//! ```
4//! # use egui_charts::ui_kit::LoadingIndicator;
5//! # egui::__run_test_ui(|ui| {
6//! LoadingIndicator::new().message("Loading templates...").show(ui);
7//! # });
8//! ```
9
10use crate::localization as l10n;
11use egui::{RichText, Ui};
12
13/// A loading spinner with optional message text.
14///
15/// Renders a horizontal layout with spinner + label, vertically padded.
16pub struct LoadingIndicator<'a> {
17 message: Option<&'a str>,
18}
19
20impl<'a> LoadingIndicator<'a> {
21 /// Create a spinner without a message.
22 pub fn new() -> Self {
23 Self { message: None }
24 }
25
26 /// Set the loading message (default: "Loading...").
27 #[must_use]
28 pub fn message(mut self, msg: &'a str) -> Self {
29 self.message = Some(msg);
30 self
31 }
32
33 /// Show the loading indicator.
34 pub fn show(self, ui: &mut Ui) {
35 ui.horizontal(|ui| {
36 ui.spinner();
37 ui.label(
38 RichText::new(l10n::text(ui.ctx(), self.message.unwrap_or("Loading...")))
39 .color(ui.visuals().weak_text_color()),
40 );
41 });
42 }
43}
44
45impl Default for LoadingIndicator<'_> {
46 fn default() -> Self {
47 Self::new()
48 }
49}