egui_pop_api/bus/areas.rs
1//! The interactive areas on the bus (ADR 0029): `pop.ui.areas` lists every
2//! area the last pass of each window registered
3//! (`egui_pop_core::areas`): its kind (display, navigate, edit), for an
4//! edit area the control it writes, its value and path, its panel,
5//! whether it is inert and its grips. Agents and tests read which areas
6//! edit without a screenshot.
7//!
8//! The registry's listener ([`AREA_REGISTRY`]) fills the list; a listener
9//! after it may add to it (areas egui does not draw).
10
11use std::sync::{Arc, Mutex};
12
13use bus_contract::{Bus, ListenOpts, Point, PointId, PointKind};
14use egui_pop_core::areas::{self, AreaRecord};
15use egui_pop_core::lock;
16
17use super::OWNER;
18
19/// The interactive areas are listed (`pop.ui.areas`): the value is the list,
20/// each window's last pass, the main window's first.
21#[derive(Debug)]
22pub struct UiAreas;
23impl Point for UiAreas {
24 const KIND: PointKind = PointKind::Alter;
25 const ID: PointId = PointId::new("pop.ui.areas");
26 type Input = ();
27 type Value = Vec<AreaRecord>;
28}
29
30/// The area points, in the order [`super::order_dump`] prints them.
31pub const AREA_POINTS: [&str; 1] = [UiAreas::ID.as_str()];
32
33/// The registry's listener of `pop.ui.areas`: lists the areas registered.
34pub const AREA_REGISTRY: &str = "pop.ui.area_registry";
35
36/// Registers the registry's listener of `pop.ui.areas`; it reads the context
37/// the interface draws with.
38pub(super) fn install(kernel: &dyn Bus, ctx: Arc<Mutex<Option<egui::Context>>>) {
39 let listened = kernel.listen::<UiAreas>(
40 AREA_REGISTRY,
41 ListenOpts::new().owner(OWNER),
42 move |_, value| {
43 if let Some(ctx) = lock(&ctx).clone() {
44 value.extend(areas::list(&ctx));
45 }
46 Ok(())
47 },
48 );
49 debug_assert!(listened.is_ok(), "{listened:?}");
50}