Skip to main content

ravenrs_app/
controller.rs

1//! What gives an application its behavior: controllers bring actions and react to views.
2
3use crate::action::TargetScope;
4use crate::frame::FrameContext;
5use crate::{Action, Frame};
6
7/// Behavior tied to a view: it turns on when a view it targets is shown, and off when that goes.
8/// Its actions are off while it is off. Each frame has its own.
9pub trait ViewController {
10    /// What it is known by.
11    fn id(&self) -> &str;
12
13    /// Which views it is for. Every one by default.
14    fn scope(&self) -> TargetScope {
15        TargetScope::any()
16    }
17
18    /// The actions it brings. Asked once.
19    fn actions(&self) -> Vec<Action> {
20        Vec::new()
21    }
22
23    /// A view it targets is in place.
24    fn activated(&mut self, _frame: &Frame) {}
25
26    /// The view is going, or something turned it off.
27    fn deactivated(&mut self, _frame: &Frame) {}
28
29    /// The view's controls exist now.
30    fn view_controls_created(&mut self, _frame: &Frame) {}
31}
32
33/// Behavior tied to a window, whatever view it shows. Stays on while the frame lasts.
34pub trait WindowController {
35    /// What it is known by.
36    fn id(&self) -> &str;
37
38    /// The kinds of window it is for. Only the main one by default.
39    fn contexts(&self) -> &[FrameContext] {
40        &[FrameContext::Main]
41    }
42
43    /// The actions it brings. Asked once.
44    fn actions(&self) -> Vec<Action> {
45        Vec::new()
46    }
47
48    /// The frame is ready.
49    fn activated(&mut self, _frame: &Frame) {}
50
51    /// The frame is closing.
52    fn deactivated(&mut self, _frame: &Frame) {}
53}