kimun_notes/components/overlay.rs
1//! The `Overlay` trait and its supporting types — the contract every editor
2//! overlay (note browser, Saved Searches modal, or dialog) implements so the
3//! `OverlayHost` can route input / app-messages / render to it uniformly.
4
5use std::sync::Arc;
6
7use kimun_core::NoteVault;
8use ratatui::Frame;
9use ratatui::layout::Rect;
10
11use crate::components::event_state::EventState;
12use crate::components::events::{AppEvent, AppTx, InputEvent};
13use crate::settings::themes::Theme;
14
15/// Identifies which overlay is active — used for toggle, focus label, and hints.
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum OverlayKind {
18 NoteBrowser,
19 SavedSearches,
20 Dialog,
21}
22
23impl OverlayKind {
24 /// Footer label for this overlay kind.
25 pub fn label(&self) -> &'static str {
26 match self {
27 OverlayKind::NoteBrowser => "NOTE BROWSER",
28 OverlayKind::SavedSearches => "SAVED SEARCHES",
29 OverlayKind::Dialog => "DIALOG",
30 }
31 }
32}
33
34/// Outcome of routing an `AppEvent` to the active overlay. Overlays never
35/// request their own dismissal here: dialogs close by emitting the
36/// `AppEvent::CloseOverlay` event, which the editor handles separately.
37#[derive(Debug)]
38pub enum OverlayMsg {
39 /// The overlay did not recognise the message.
40 NotConsumed,
41 /// The overlay handled the message and stays open.
42 Consumed,
43}
44
45// `Send`: an `OverlayHost` lives in `EditorScreen`, whose `#[async_trait]`
46// `AppScreen` methods desugar to `Send` futures — so the boxed overlay must be `Send`.
47pub trait Overlay: Send {
48 fn kind(&self) -> OverlayKind;
49 fn handle_input(&mut self, event: &InputEvent, tx: &AppTx) -> EventState;
50 fn handle_app_message(
51 &mut self,
52 _msg: &AppEvent,
53 _vault: &Arc<NoteVault>,
54 _tx: &AppTx,
55 ) -> OverlayMsg {
56 OverlayMsg::NotConsumed
57 }
58 fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme);
59 fn hint_shortcuts(&self) -> Vec<(String, String)> {
60 vec![]
61 }
62 /// The query string this overlay holds, if it is query-backed (the note
63 /// browser). Used by the editor's save-current-query action to source the
64 /// query from the active overlay. Defaults to `None` for non-query overlays.
65 fn query(&self) -> Option<&str> {
66 None
67 }
68}