Skip to main content

armas_basic/components/
content.rs

1//! Shared content context for components that support closure-based rendering.
2//!
3//! When components accept custom content via closures (e.g. `Button::content().show_content()`),
4//! the closure receives a [`ContentContext`] with state-dependent styling information so that
5//! icons and text automatically match the component's visual state.
6
7use egui::Color32;
8
9/// Context passed to custom content closures.
10///
11/// Provides state-dependent styling information so icons and text
12/// match the component's current visual state (hover, pressed, active, disabled).
13///
14/// The `Ui` passed alongside this context also has `visuals.override_text_color`
15/// set to [`color`](Self::color), so plain `ui.label()` calls inside the closure
16/// automatically get the right color.
17///
18/// # Example
19///
20/// ```rust,no_run
21/// # use egui::Ui;
22/// # fn example(ui: &mut Ui) {
23/// use armas_basic::components::{Button, ContentContext};
24///
25/// Button::new("")
26///     .show_ui(ui, |ui, ctx| {
27///         // ctx.color is the correct text/icon color for the current state
28///         ui.label("Save");
29///     });
30/// # }
31/// ```
32pub struct ContentContext {
33    /// The text/icon color appropriate for the current state.
34    /// Changes with hover, pressed, active, and disabled states.
35    pub color: Color32,
36    /// The font size the component would use for its text label mode.
37    pub font_size: f32,
38    /// Whether the component is currently in an active/selected/pressed state.
39    pub is_active: bool,
40}