Skip to main content

piki_gui/
note_ui.rs

1use crate::content::{ContentLoader, ContentProvider};
2use fltk::{enums::Color, window};
3use rutle::structured_document::BlockType;
4use rutle::tree_path::DocumentPosition;
5use std::any::Any;
6
7/// A minimal UI abstraction layer for a note editor/viewer.
8///
9/// It unifies the interactions needed by main.rs so different
10/// implementations (e.g. StructuredRichUI) can be swapped without
11/// changing app logic.
12pub trait NoteUI: ContentProvider + ContentLoader + 'static {
13    // Subscribe to content change notifications (debounced by the app).
14    fn on_change(&mut self, f: Box<dyn FnMut() + 'static>);
15
16    // Toggle/query read-only mode.
17    fn set_readonly(&mut self, readonly: bool);
18    fn is_readonly(&self) -> bool;
19
20    // Scroll position in implementation-defined units (row/pixel).
21    fn scroll_pos(&self) -> i32;
22    fn set_scroll_pos(&mut self, pos: i32);
23
24    // Caret position within the document. `cursor_pos` returns `None` for a
25    // viewer with no caret concept (the default); `set_cursor_pos` is then a
26    // no-op. Used to restore the caret when returning to a note.
27    fn cursor_pos(&self) -> Option<DocumentPosition> {
28        None
29    }
30    fn set_cursor_pos(&mut self, _pos: DocumentPosition) {}
31
32    // Set background color and make resizable with a window.
33    fn set_bg_color(&mut self, color: Color);
34    fn set_resizable(&self, wind: &mut window::Window);
35
36    // Install internal event handler to detect link clicks and cursor hints.
37    fn on_link_click(&mut self, f: Box<dyn Fn(String) + 'static>);
38
39    // Install handler for link hover; called with Some(dest) when hovering a link,
40    // and None when not hovering any link. Default no-op.
41    fn on_link_hover(&mut self, _f: Box<dyn Fn(Option<String>) + 'static>) {}
42
43    // Optional restyle hook (no-op by default).
44    fn restyle(&mut self) {}
45
46    // Optional periodic tick with ms since app start (no-op by default).
47    fn tick(&mut self, _ms_since_start: u64) {}
48
49    // Downcasting support for accessing concrete implementations.
50    fn as_any(&self) -> &dyn Any;
51    fn as_any_mut(&mut self) -> &mut dyn Any;
52
53    // Paragraph style change notification (structured editors can override).
54    fn on_paragraph_style_change(&mut self, _f: Box<dyn FnMut(BlockType) + 'static>) {}
55
56    // Hide the widget (called when switching editors).
57    fn hide(&mut self);
58
59    // Focus the widget.
60    fn take_focus(&mut self) {}
61}