Skip to main content

egui_pop_api/bus/
command_label.rs

1//! A command's live text, on the bus (ADR 0029): `pop.command.label` asks
2//! the application for a command's title and tooltip each time a menu
3//! item, a toolbar button or a shortcut tooltip naming it is drawn
4//! ([`AppHandle::command_title`], [`AppHandle::command_tooltip`]).
5//!
6//! egui-pop has no listener of its own: with nobody answering, a command
7//! shows its declared title and description, translated, as before. An
8//! application answers for the commands whose text depends on its state
9//! ("Zen: Compare" for the panel zen would show), leaving the others'
10//! [`CommandText`] as it gets it. What it answers is shown as given: it
11//! is already in the interface's language.
12//!
13//! [`AppHandle::command_title`]: crate::AppHandle::command_title
14//! [`AppHandle::command_tooltip`]: crate::AppHandle::command_tooltip
15
16use bus_contract::{Point, PointId, PointKind};
17use egui_pop_model::ids::CommandId;
18
19/// A command's text as an application says it now; `None` keeps the
20/// declared one.
21///
22/// ```
23/// use egui_pop_api::bus::CommandText;
24///
25/// let label = CommandText::default().title("Zen: Compare");
26/// assert_eq!(label.title.as_deref(), Some("Zen: Compare"));
27/// assert_eq!(label.tooltip, None);
28/// ```
29#[derive(Clone, Debug, Default, PartialEq, Eq)]
30#[non_exhaustive]
31pub struct CommandText {
32    /// The title menus, toolbars and shortcut tooltips show.
33    pub title: Option<String>,
34    /// The tooltip, in place of the command's description.
35    pub tooltip: Option<String>,
36}
37
38impl CommandText {
39    /// The title shown.
40    #[must_use]
41    pub fn title(mut self, title: impl Into<String>) -> Self {
42        self.title = Some(title.into());
43        self
44    }
45
46    /// The tooltip shown.
47    #[must_use]
48    pub fn tooltip(mut self, tooltip: impl Into<String>) -> Self {
49        self.tooltip = Some(tooltip.into());
50        self
51    }
52}
53
54/// A command's live title and tooltip (`pop.command.label`): the input is
55/// the command, the value what the application says of it, empty while no
56/// listener answers.
57#[derive(Debug)]
58pub struct CommandLabel;
59impl Point for CommandLabel {
60    const KIND: PointKind = PointKind::Alter;
61    const ID: PointId = PointId::new("pop.command.label");
62    type Input = CommandId;
63    type Value = CommandText;
64}
65
66/// The command text points, in the order [`super::order_dump`] prints
67/// them.
68pub const COMMAND_LABEL_POINTS: [&str; 1] = [CommandLabel::ID.as_str()];